Search in sources :

Example 41 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class EditProductFromCatalogTest method editCatalogProductIngredientNotExistTest.

@Test
public void editCatalogProductIngredientNotExistTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ManufacturerNotExist e1) {
        fail();
    } catch (IngredientNotExist __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 42 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class GetAllIngredientsTest method getAllManufacturersCriticalErrorTest.

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

Example 43 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class GetAllIngredientsTest method getAllManufacturersSuccessfulTest.

@Test
public void getAllManufacturersSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.GET_ALL_INGREDIENTS).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getIngredientsList()).thenReturn("");
    } catch (CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 44 with CommandWrapper

use of ClientServerApi.CommandWrapper 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 45 with CommandWrapper

use of ClientServerApi.CommandWrapper 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)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)218 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)162 Test (org.junit.Test)144 CommandExecuter (CommandHandler.CommandExecuter)135 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)124 Gson (com.google.gson.Gson)123 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)57 SmartCode (BasicCommonClasses.SmartCode)51 ProductPackage (BasicCommonClasses.ProductPackage)45 CriticalError (SMExceptions.CommonExceptions.CriticalError)39 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)39 Location (BasicCommonClasses.Location)37 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)27 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)27 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)27 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)23 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)22 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)21 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)21 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)21