use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanLoginWithNewPassword.
@Test
public void testCustomerCanLoginWithNewPassword() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
sqlConnection.setPasswordCustomer(customerName, "newPass");
//try to login with new password
int sessionID = sqlConnection.loginCustomer(customerName, "newPass");
sqlConnection.logout(sessionID, customerName);
} catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartClientType.
@Test
public void testCartClientType() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assert sqlConnection.isClientLoggedIn(session);
assertEquals(new Gson().toJson(CLIENT_TYPE.CART), sqlConnection.getClientType(session));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
} catch (CriticalError | ClientNotConnected e) {
fail();
}
try {
sqlConnection.getClientType(session);
fail();
} catch (ClientNotConnected e) {
} catch (CriticalError e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartConnection.
@Test
public void testCartConnection() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assert sqlConnection.isClientLoggedIn(session);
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
} catch (CriticalError | ClientNotConnected e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.AuthenticationError in project SmartCity-Market by TechnionYP5777.
the class LoginTest method loginCustomerCriticalErrorTest.
@Test
public void loginCustomerCriticalErrorTest() {
Login login = new Login("unknown", "unknown");
String command = new CommandWrapper(0, CommandDescriptor.LOGIN_CUSTOMER, new Gson().toJson(login, Login.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.loginCustomer(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 loginCustomerUsernameDoesNotExistWrongPasswordTest.
@Test
public void loginCustomerUsernameDoesNotExistWrongPasswordTest() {
Login login = new Login("unknown", "unknown");
String command = new CommandWrapper(0, CommandDescriptor.LOGIN_CUSTOMER, new Gson().toJson(login, Login.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.loginCustomer(login.getUserName(), login.getPassword())).thenThrow(new AuthenticationError());
} catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD, out.getResultDescriptor());
}
Aggregations