Search in sources :

Example 21 with ClientAlreadyConnected

use of SQLDatabase.SQLDatabaseException.ClientAlreadyConnected 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();
        }
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 22 with ClientAlreadyConnected

use of SQLDatabase.SQLDatabaseException.ClientAlreadyConnected 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();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 23 with ClientAlreadyConnected

use of SQLDatabase.SQLDatabaseException.ClientAlreadyConnected 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();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 24 with ClientAlreadyConnected

use of SQLDatabase.SQLDatabaseException.ClientAlreadyConnected 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());
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 25 with ClientAlreadyConnected

use of SQLDatabase.SQLDatabaseException.ClientAlreadyConnected 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());
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)27 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)27 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)27 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)27 Test (org.junit.Test)25 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)19 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)19 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)10 Login (BasicCommonClasses.Login)9 ProductPackage (BasicCommonClasses.ProductPackage)8 SmartCode (BasicCommonClasses.SmartCode)8 CommandWrapper (ClientServerApi.CommandWrapper)8 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)8 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)8 Gson (com.google.gson.Gson)7 CommandExecuter (CommandHandler.CommandExecuter)6 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)4 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)3 GroceryListIsEmpty (SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)3 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)1