Search in sources :

Example 26 with ClientNotExist

use of SQLDatabase.SQLDatabaseException.ClientNotExist in project SmartCity-Market by TechnionYP5777.

the class RemoveWorkerTest method removeWorkerSuccessfulTest.

@Test
public void removeWorkerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_WORKER, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeWorker(senderID, username);
    } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 27 with ClientNotExist

use of SQLDatabase.SQLDatabaseException.ClientNotExist 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 28 with ClientNotExist

use of SQLDatabase.SQLDatabaseException.ClientNotExist in project SmartCity-Market by TechnionYP5777.

the class RemoveWorkerTest method removeWorkerClientNotConnectedTest.

@Test
public void removeWorkerClientNotConnectedTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_WORKER, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeWorker(senderID, username);
    } catch (CriticalError | ClientNotExist e) {
        fail();
    } catch (ClientNotConnected e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 29 with ClientNotExist

use of SQLDatabase.SQLDatabaseException.ClientNotExist in project SmartCity-Market by TechnionYP5777.

the class UpdateCustomerProfileTest method updateCustomerProfileClientNotExistTest.

@Test
public void updateCustomerProfileClientNotExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | IngredientNotExist e1) {
        fail();
    } catch (ClientNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 30 with ClientNotExist

use of SQLDatabase.SQLDatabaseException.ClientNotExist in project SmartCity-Market by TechnionYP5777.

the class UpdateCustomerProfileTest method updateCustomerProfileIngredientNotExistTest.

@Test
public void updateCustomerProfileIngredientNotExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } catch (IngredientNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Aggregations

ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)40 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)40 Test (org.junit.Test)33 CommandWrapper (ClientServerApi.CommandWrapper)23 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)17 CommandExecuter (CommandHandler.CommandExecuter)16 Gson (com.google.gson.Gson)16 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)14 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)13 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)12 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)9 Login (BasicCommonClasses.Login)6 CustomerProfile (BasicCommonClasses.CustomerProfile)4 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)4 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)4 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)4