Search in sources :

Example 11 with ClientAlreadyExist

use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist 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 12 with ClientAlreadyExist

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

the class RegisterNewWorkerTest method registerNewWorkerCriticalErrorTest.

@Test
public void registerNewWorkerCriticalErrorTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (ClientAlreadyExist | ClientNotConnected e) {
        fail();
    } catch (CriticalError __) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 13 with ClientAlreadyExist

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

the class RegisterNewWorkerTest method registerNewWorkerClientNotConnectedTest.

@Test
public void registerNewWorkerClientNotConnectedTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    } catch (ClientNotConnected __) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 14 with ClientAlreadyExist

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

the class RegisterNewWorkerTest method registerNewWorkerClientAlreadyExistTest.

@Test
public void registerNewWorkerClientAlreadyExistTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientAlreadyExist()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ClientAlreadyExist __) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 15 with ClientAlreadyExist

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

the class RegisterNewWorkerTest method registerNewWorkerSuccessfulTest.

@Test
public void registerNewWorkerSuccessfulTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)19 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)19 Test (org.junit.Test)17 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)14 CommandWrapper (ClientServerApi.CommandWrapper)11 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)11 CommandExecuter (CommandHandler.CommandExecuter)9 Gson (com.google.gson.Gson)9 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)8 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)7 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)6 Login (BasicCommonClasses.Login)5 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)3 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)3 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)3 CustomerProfile (BasicCommonClasses.CustomerProfile)2