Search in sources :

Example 66 with CommandWrapper

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

the class ViewCatalogProductTest method viewCatalogProductWorkerNotConnectedTest.

@Test
public void viewCatalogProductWorkerNotConnectedTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(0, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenThrow(new ClientNotConnected());
    } catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 67 with CommandWrapper

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

the class AddNewManufacturerTest method addNewManufacturerClientNotConnectedrTest.

@Test
public void addNewManufacturerClientNotConnectedrTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.getName())).thenThrow(new ClientNotConnected());
    } catch (CriticalError e) {
        fail();
    } catch (ClientNotConnected e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 68 with CommandWrapper

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

the class AddNewManufacturerTest method addNewManufacturerSuccessfulTest.

@Test
public void addNewManufacturerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.getName())).thenReturn("0");
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 69 with CommandWrapper

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

the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseCriticalErrorTest.

@Test
public void addProductPackageToWarehouseCriticalErrorTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addProductPackageToWarehouse(senderID, productPackage);
    } catch (ClientNotConnected | ProductNotExistInCatalog e) {
        fail();
    } catch (CriticalError __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 70 with CommandWrapper

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

the class AddProductToCatalogTest method addCatalogProductClientNotConnectedTest.

@Test
public void addCatalogProductClientNotConnectedTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
    } catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError e) {
        fail();
    } catch (ClientNotConnected __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : 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) ProductAlreadyExistInCatalog(SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog) 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