Search in sources :

Example 16 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testCantGetProfileToNotExistedCustomer.

@Test
public void testCantGetProfileToNotExistedCustomer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        Serialization.deserialize(sqlConnection.getCustomerProfile(customerName), CustomerProfile.class);
        fail();
    } catch (CriticalError e1) {
        fail();
    } catch (ClientNotExist e2) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 17 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testAddRemoveWorker.

@Test
public void testAddRemoveWorker() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    //test add worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
        fail();
    }
    assert result != null;
    HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert map.containsKey(workerName);
    assertEquals(false, map.get(workerName));
    //test remove worker
    try {
        sqlConnection.removeWorker(null, workerName);
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientNotExist e) {
        fail();
    }
    assert result != null;
    map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert !map.containsKey(workerName);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 18 with ClientNotExist

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

the class RemoveWorkerTest method removeWorkerClientNotExistTest.

@Test
public void removeWorkerClientNotExistTest() {
    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 ClientNotExist()).when(sqlDatabaseConnection).removeWorker(senderID, username);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ClientNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST, 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 19 with ClientNotExist

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

the class UpdateCustomerProfileTest method updateCustomerProfileCriticalErrorTest.

@Test
public void updateCustomerProfileCriticalErrorTest() {
    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 CriticalError()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (ClientNotExist | IngredientNotExist e1) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, 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 20 with ClientNotExist

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

the class UpdateCustomerProfileTest method updateCustomerProfileSuccessfulTest.

@Test
public void updateCustomerProfileSuccessfulTest() {
    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.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
        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) 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