Skip to content
Snippets Groups Projects
Commit 7da5a3c2 authored by eyan_'s avatar eyan_
Browse files
parents 345e5528 f341f6bc
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,8 @@ public class Positions {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("insert into Positions (position, wage) " +
"values ('" + position.toLowerCase(Locale.ROOT) +"', "+ wage + ")");
ResultSet myRs = myStatement.executeQuery("select * from Positions where position=" + position);
ResultSet myRs = myStatement.executeQuery("select * from Positions where position = '" + position + "'");
myRs.next();
newPosition = myRs.getString("position") + "/" + myRs.getString("wage");
} catch (SQLException exception) {
exception.printStackTrace();
......@@ -65,7 +66,8 @@ public class Positions {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
myStatement.executeUpdate("update Positions set wage=" + newWage +
"where position='" + position.toLowerCase(Locale.ROOT) +"'");
ResultSet myRs = myStatement.executeQuery("select * from Positions where position=" + position);
ResultSet myRs = myStatement.executeQuery("select * from Positions where position = '" + position + "'");
myRs.next();
editedPosition = myRs.getString("position") + "/" + myRs.getString("wage");
} catch (SQLException exception) {
exception.printStackTrace();
......
......@@ -39,7 +39,6 @@ public class Staff {
*/
protected String addEmployee(String firstName, String lastName, String isManager, String email, String phoneNumber,
float wage){
System.out.println(firstName + " " + lastName + " " + isManager + " " + email + " " + phoneNumber + " " + wage);
String newEmployee = "";
try {
Statement myStatement = dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
......@@ -58,7 +57,6 @@ public class Staff {
exception.printStackTrace();
return newEmployee;
}
System.out.println("Employee Added");
return newEmployee;
}
......@@ -96,7 +94,6 @@ public class Staff {
exception.printStackTrace();
return editedEmployee;
}
System.out.println("Employee Added");
return editedEmployee;
}
......@@ -117,7 +114,6 @@ public class Staff {
exception.printStackTrace();
return -1;
}
System.out.println("Employee Removed");
return ID;
}
......@@ -133,7 +129,6 @@ public class Staff {
*/
protected String addPosition(int employeeID, String position) {
try {
System.out.println(employeeID + " " + position);
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("select exists(select *from Positions where position='" + position + "')");
myRs.next();
......@@ -173,7 +168,10 @@ public class Staff {
Statement myStatement = dbConnection.createStatement();
ResultSet myRs = myStatement.executeQuery("select positions from Employees where employee_ID=" + ID);
myRs.next();
for (String s : myRs.getString("positions").split("\\.")) {
if (myRs.getString("positions") == null) {
return removedPosition;
}
for (String s : myRs.getString("positions").split(",")) {
if (!s.equalsIgnoreCase(position)) {
if (newPositions.isEmpty()) {
newPositions.append(s);
......@@ -204,7 +202,7 @@ public class Staff {
Description: To remove a position from all employees.
Return: void
*/
protected void removePositionAllEmployees(String position) {
protected String removePositionAllEmployees(String position) {
try {
String positionLowerCase = position.toLowerCase(Locale.ROOT);
Statement myStatement = dbConnection.createStatement();
......@@ -214,7 +212,9 @@ public class Staff {
}
} catch (Exception exception) {
exception.printStackTrace();
return "";
}
return position;
}
/*
......@@ -246,16 +246,129 @@ public class Staff {
return response.toString();
}
// Staff testing suite
// This test suite must be started while the staff table is empty.
public static void main(String[] args) {
/* This is for running test on the staff class although the cass for the DriverManager can be used for testing
other classed.
try {
Staff staff = new Staff(DriverManager.getConnection("jdbc:mysql://localhost:3306/ScheduleApp", "root", "password"));
staff.removePosition(1, "dishwasher");
Connection dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ScheduleApp", "root", "password");
Staff staff = new Staff(dbConnection);
Positions positions = new Positions(dbConnection);
positions.addPosition("dishwasher", 10.00f); // Required to test position methods.
positions.addPosition("cashier", 10.00f); // Required to test position methods.
String queryString;
int queryInt;
int success = 0;
System.out.println("Staff Test 1: ");
System.out.println("Test Scenario: " + "Testing allEmployees()");
System.out.println("Test Data: " + "none");
System.out.println("Expected Results: " + "allEmployees");
queryString = staff.allEmployees();
System.out.println("Actual Results: " + queryString);
if (queryString.equals("allEmployees")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Test 2: ");
System.out.println("Test Scenario: " + "Testing addEmployee()");
System.out.println("Test Data: " + "firstName='John', lastName='Doe', isManager='true', " +
"email='john.doe@email.com', phoneNumber='1234567890', wage=11.81f");
System.out.println("Expected Results: " + "1,John,Doe,1,john.doe@email.com,1234567890,11.81, ");
queryString = staff.addEmployee("John", "Doe", "true", "john.doe@email.com",
"1234567890", 11.81f);
System.out.println("Actual Results: " + queryString);
if (queryString.equals("1,John,Doe,1,john.doe@email.com,1234567890,11.81, ")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Test 3: ");
System.out.println("Test Scenario: " + "Testing editEmployee()");
System.out.println("Test Data: " + "firstName='Jonathan', lastName='Deer', isManager='false', " +
"email='jonathan.deer@email.com', phoneNumber='0987654321', wage=15.00f");
System.out.println("Expected Results: " + "1,Jonathan,Deer,0,jonathan.deer@email.com,0987654321,15.0,null");
queryString = staff.editEmployee(1,"Jonathan", "Deer", "false", "jonathan.deer@email.com",
"0987654321", 15.00f);
System.out.println("Actual Results: " + queryString);
if (queryString.equals("1,Jonathan,Deer,0,jonathan.deer@email.com,0987654321,15.0,null")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Test 4: ");
System.out.println("Test Scenario: " + "Testing addPosition()");
System.out.println("Test Data: " + "employeeID='1', position='dishwasher'");
System.out.println("Expected Results: " + "1/dishwasher");
queryString = staff.addPosition(1, "dishwasher");
System.out.println("Actual Results: " + queryString);
if (queryString.equals("1/dishwasher")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Test 5: ");
System.out.println("Test Scenario: " + "Testing removePosition()");
System.out.println("Test Data: " + "employeeID='1', position='dishwasher'");
System.out.println("Expected Results: " + "1/dishwasher");
queryString = staff.removePosition(1, "dishwasher");
System.out.println("Actual Results: " + queryString);
if (queryString.equals("1/dishwasher")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
//Setup to test removePositionAllEmployees() properly
staff.addEmployee("Jane", "Doe", "false", "jane.doe@email.com",
"1234567890", 10.0f);
staff.addPosition(2, "cashier");
staff.addPosition(1, "cashier");
System.out.println("\nStaff Test 6: ");
System.out.println("Test Scenario: " + "Testing removePositionAllEmployees() removes the the position from" +
"all employees.");
System.out.println("Test Data: " + "position='cashier'");
System.out.println("Expected Results: " + "allEmployees/1,Jonathan,Deer,0,jonathan.deer@email.com,0987654321," +
"15.0,null/2,Jane,Doe,0,jane.doe@email.com,1234567890,10.0,null");
staff.removePositionAllEmployees("cashier");
queryString = staff.allEmployees();
System.out.println("Actual Results: " + queryString);
if (queryString.equals("allEmployees/1,Jonathan,Deer,0,jonathan.deer@email.com,0987654321,15.0,null/2,Jane," +
"Doe,0,jane.doe@email.com,1234567890,10.0,null")){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Test 7: ");
System.out.println("Test Scenario: " + "Testing removeEmployee()");
System.out.println("Test Data: " + "employeeID='1'");
System.out.println("Expected Results: " + "1");
queryInt = staff.removeEmployee(1);
System.out.println("Actual Results: " + queryInt);
if (queryInt == 1){
success += 1;
System.out.println("Pass/Fail: Pass");
} else {
System.out.println("Pass/Fail: Fail");
}
System.out.println("\nStaff Unit Testing: Passed " + success + "/7.");
} catch (Exception exception) {
exception.printStackTrace();
System.out.println("Exception: Tests failed");
}
*/
}
}
......@@ -227,10 +227,12 @@ public class UserThread extends Thread {
break;
case "removePosition":
try {
dbQuery.staff.removePositionAllEmployees(args[1]);
String removedPositionAllEmployee = dbQuery.staff.removePositionAllEmployees(args[1]);
String removedPosition = dbQuery.positions.removePosition(args[1]);
if (removedPosition.equalsIgnoreCase(args[1])) {
if (removedPositionAllEmployee.equalsIgnoreCase(args[1])) {
server.broadcast("removePositionAllEmployees/" + args[1].toLowerCase(Locale.ROOT));
}
if (removedPosition.equalsIgnoreCase(args[1])) {
server.broadcast("removePosition/" + args[1].toLowerCase(Locale.ROOT));
}
} catch (NumberFormatException exception) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment