use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class CommandProcess method process.
@Override
public void process(Socket clientSocket) {
CommandWrapper outCommandWrapper;
BufferedReader in = null;
PrintWriter out = null;
String command = null;
try {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
for (long startTime = System.currentTimeMillis(); command == null && System.currentTimeMillis() - startTime < 1000; ) command = in.readLine();
} catch (IOException e1) {
log.fatal("Failed to get string command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
out.println(outCommandWrapper.serialize());
return;
}
if (command == null) {
/* Timeout failure */
log.fatal("Failed to get string command due to timeout");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} else {
log.info("New command received: " + command);
outCommandWrapper = new CommandExecuter(command).execute(new SQLDatabaseConnection());
}
out.println(outCommandWrapper.serialize());
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantGetSecurityQusetionOfNotExistedWorker.
@Test
public void testCantGetSecurityQusetionOfNotExistedWorker() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
sqlConnection.getSecurityQuestionWorker(workerName);
fail();
} catch (CriticalError e1) {
fail();
} catch (ClientNotExist e2) {
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testWorkerCanSetSecurityQA.
@Test
public void testWorkerCanSetSecurityQA() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ForgotPasswordData p = new ForgotPasswordData("question", "answer");
String result = null;
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
} catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
fail();
}
try {
sqlConnection.setSecurityQAWorker(workerName, p);
result = sqlConnection.getSecurityQuestionWorker(workerName);
assertTrue(sqlConnection.verifySecurityAnswerWorker(workerName, "answer"));
assertEquals("question", result);
} catch (CriticalError | ClientNotExist e1) {
fail();
} finally {
try {
sqlConnection.removeWorker(null, workerName);
} catch (CriticalError | ClientNotExist | ClientNotConnected e) {
e.printStackTrace();
}
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testWorkerCanLoginWithNewPassword.
@Test
public void testWorkerCanLoginWithNewPassword() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
} catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
fail();
}
try {
sqlConnection.setPasswordWorker(workerName, "newPass");
//try to login with new password
int sessionID = sqlConnection.loginWorker(workerName, "newPass");
sqlConnection.logout(sessionID, workerName);
} catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
fail();
} finally {
try {
sqlConnection.removeWorker(null, workerName);
} catch (CriticalError | ClientNotExist | ClientNotConnected e) {
e.printStackTrace();
}
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantEditNotExistedIngredient.
@Test
public void testCantEditNotExistedIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
Ingredient ingredient = new Ingredient(999, ingredientName);
try {
sqlConnection.editIngredient(null, ingredient);
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (IngredientNotExist e) {
}
}
Aggregations