Search in sources :

Example 21 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class GetAllManufacturerTest method getAllManufacturersCriticalErrorTest.

@Test
public void getAllManufacturersCriticalErrorTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.GET_ALL_MANUFACTURERS).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getManufacturersList(senderID)).thenThrow(new CriticalError());
    } catch (ClientNotConnected e) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 22 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest2.

@Test
public void registerNewCustomerProfileCriticalErrorTest2() {
    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 ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | IngredientNotExist e1) {
        fail();
    } catch (ClientNotExist e) {
    /* success */
    }
    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 23 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RegisterNewCustomerTest method registerNewCustomerProfileClientAlreadyExistTest.

@Test
public void registerNewCustomerProfileClientAlreadyExistTest() {
    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 ClientAlreadyExist()).when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
    } catch (CriticalError e) {
        fail();
    } catch (ClientAlreadyExist 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_USERNAME_ALREADY_EXISTS, 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 24 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RegisterNewWorkerTest method registerNewWorkerIllegalInputTest.

@Test
public void registerNewWorkerIllegalInputTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson("", String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 25 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class IsFreeCustomerNameTest method isFreeCustomerNameSuccessfulTest1.

@Test
public void isFreeCustomerNameSuccessfulTest1() {
    String command = new CommandWrapper(senderID, CommandDescriptor.IS_FREE_CUSTOMER_NAME, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.isCustomerUsernameAvailable(username)).thenReturn(true);
    } catch (CriticalError 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) Test(org.junit.Test)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)135 CommandExecuter (CommandHandler.CommandExecuter)135 Test (org.junit.Test)135 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)128 Gson (com.google.gson.Gson)119 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)100 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)48 SmartCode (BasicCommonClasses.SmartCode)47 Location (BasicCommonClasses.Location)37 ProductPackage (BasicCommonClasses.ProductPackage)37 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)32 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)23 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)23 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)23 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)16 CatalogProduct (BasicCommonClasses.CatalogProduct)14 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)9 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)7 Login (BasicCommonClasses.Login)6 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)6