Search in sources :

Example 16 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreCriticalErrorTest.

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

Example 17 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductPackageNotExistTest.

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

Example 18 with Location

use of BasicCommonClasses.Location 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 19 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class AddProductToGroceryListTest method addProductToGroceryListSuccessfulTest.

@Test
public void addProductToGroceryListSuccessfulTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 20 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class AddProductToGroceryListTest method addProductToGroceryListProductNotExistInCatalogTest.

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

Aggregations

Location (BasicCommonClasses.Location)47 Test (org.junit.Test)43 SmartCode (BasicCommonClasses.SmartCode)41 ProductPackage (BasicCommonClasses.ProductPackage)40 Gson (com.google.gson.Gson)40 CommandWrapper (ClientServerApi.CommandWrapper)37 CommandExecuter (CommandHandler.CommandExecuter)37 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)35 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)34 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)34 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)23 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)23 Ingredient (BasicCommonClasses.Ingredient)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3 HashSet (java.util.HashSet)3 SQLDatabaseException (SQLDatabase.SQLDatabaseException)2 SmartcodePrint (SmartcodeParser.SmartcodePrint)2 SMException (SMExceptions.SMException)1