Search in sources :

Example 36 with ClientNotExist

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

the class CommandExecuter method removeWorker.

private void removeWorker(SQLDatabaseConnection c) {
    String username = null;
    log.info("Remove worker from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        username = Serialization.deserialize(inCommandWrapper.getData(), String.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Worker command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to remove worker " + username + " from system");
    try {
        c.removeWorker(inCommandWrapper.getSenderID(), username);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove worker command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Remove worker command failed, worker is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    } catch (ClientNotConnected e) {
        log.info("Remove worker command failed, manager is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    }
    log.info("Remove worker " + username + " from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Example 37 with ClientNotExist

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

the class RegisterNewCustomerTest method registerNewCustomerProfileIngredientNotExistTest.

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

Example 38 with ClientNotExist

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

the class RegisterNewCustomerTest method registerNewCustomerProfileSuccessfulTest.

@Test
public void registerNewCustomerProfileSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
        fail();
    }
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
    } catch (CriticalError | ClientNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 39 with ClientNotExist

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

the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest1.

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

Example 40 with ClientNotExist

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

the class RemoveCustomerTest method removeCustomerSuccessfulTest.

@Test
public void removeCustomerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_CUSTOMER, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeCustomer(username);
    } catch (CriticalError | ClientNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) 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