use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method loginEmployeeCommand.
private void loginEmployeeCommand(SQLDatabaseConnection c) {
Login login = null;
log.info("Login employee command called");
try {
login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for login command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
if (!login.isValid()) {
log.info("Login command failed, username and password can't be empty");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
return;
}
try {
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
outCommandWrapper.setSenderID(c.loginWorker(login.getUserName(), login.getPassword()));
try {
outCommandWrapper.setData(c.getClientType(outCommandWrapper.getSenderID()));
} catch (ClientNotConnected e) {
log.fatal("Client is not connected for sender ID " + outCommandWrapper.getSenderID());
}
log.info("Login command succeded with sender ID " + outCommandWrapper.getSenderID() + " with client type " + outCommandWrapper.getData());
} catch (AuthenticationError e) {
log.info("Login command failed, username dosen't exist or wrong password received");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD);
} catch (CriticalError e) {
log.fatal("Login command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientAlreadyConnected e) {
log.info("Login command failed, user already connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_ALREADY_CONNECTED);
} catch (NumberOfConnectionsExceeded e) {
log.fatal("Login command failed, too much connections (try to increase TRYS_NUMBER)");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
}
log.info("Login employee with User " + login.getUserName() + " finished");
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method loginClientCommand.
private void loginClientCommand(SQLDatabaseConnection c) {
Login login = null;
log.info("Login client command called");
try {
login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for login command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
if (!login.isValid()) {
log.info("Login command failed, username and password can't be empty");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
return;
}
try {
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
int senderID = c.loginCustomer(login.getUserName(), login.getPassword());
outCommandWrapper.setSenderID(senderID);
try {
outCommandWrapper.setData(c.getCustomerProfile(login.getUserName()));
} catch (ClientNotExist e) {
log.fatal("Client is not exist with username: " + outCommandWrapper.getSenderID());
}
log.info("Login command succeded with sender ID " + outCommandWrapper.getSenderID() + " with client type " + outCommandWrapper.getData());
} catch (AuthenticationError e) {
log.info("Login command failed, username dosen't exist or wrong password received");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD);
} catch (CriticalError e) {
log.fatal("Login command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientAlreadyConnected e) {
log.info("Login command failed, user already connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_ALREADY_CONNECTED);
} catch (NumberOfConnectionsExceeded e) {
log.fatal("Login command failed, too much connections (try to increase TRYS_NUMBER)");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
}
log.info("Login client with User " + login.getUserName() + " finished");
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class LoginTest method loginEmployeeCriticalErrorTest.
@Test
public void loginEmployeeCriticalErrorTest() {
Login login = new Login("unknown", "unknown");
String command = new CommandWrapper(0, CommandDescriptor.LOGIN_EMPLOYEE, new Gson().toJson(login, Login.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.loginWorker(login.getUserName(), login.getPassword())).thenThrow(new CriticalError());
} catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class LoginTest method loginEmployeeSuccessfulTest.
@Test
public void loginEmployeeSuccessfulTest() {
Login login = new Login("admin", "admin");
String command = new CommandWrapper(0, CommandDescriptor.LOGIN_EMPLOYEE, new Gson().toJson(login, Login.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.loginWorker(login.getUserName(), login.getPassword())).thenReturn(EMPLOYEE_SENDER_ID);
} catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testMovePakageToCartAndRemoveTwice.
@Test
public void testMovePakageToCartAndRemoveTwice() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
int cartSession = 0;
try {
cartSession = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(cartSession, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(cartSession, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
try {
sqlConnection.removeProductPackageFromShelves(null, productPackage);
fail();
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist e) {
}
try {
sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
Aggregations