Search in sources :

Example 6 with Location

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

the class GetProductPackageAmountTest method getProductPackageAmountClientNotConnectedTest.

@Test
public void getProductPackageAmountClientNotConnectedTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getProductPackageAmonutOnShelves(senderID, productPackage)).thenThrow(new ClientNotConnected());
        Mockito.when(sqlDatabaseConnection.getProductPackageAmonutInWarehouse(senderID, productPackage)).thenThrow(new ClientNotConnected());
    } catch (CriticalError | ProductNotExistInCatalog e1) {
        fail();
    } catch (ClientNotConnected __) {
    /* Success */
    }
    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) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 7 with Location

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

the class CatalogProductTest method CatalogProductTestMethod.

@Test
public void CatalogProductTestMethod() {
    Manufacturer man = new Manufacturer(11, "Osem");
    String bambaIm = "https://www.osem.co.il/tm-content/uploads/2015/01/Bamba_classic_80g3.png3-308x308.png";
    //just an example of use:
    try {
        ImageIO.read(new URL(bambaIm));
    } catch (IOException e) {
    }
    CatalogProduct cp = new CatalogProduct(11, "Bamba", null, man, "", 12, bambaIm, null);
    if (cp.getBarcode() != 11 || !"Bamba".equals(cp.getName()) || cp.getIngredients() != null || !cp.getManufacturer().equals(man) || !"".equals(cp.getDescription()) || cp.getPrice() != 12 || cp.getLocations() != null)
        fail();
    cp.setBarcode(111);
    cp.setName("Bisli");
    Ingredient gluten = new Ingredient(5, "gluten");
    cp.addIngredient(gluten);
    String description = "A popular snack with different flavours";
    cp.setDescription(description);
    Location lo = new Location(1, 1, PlaceInMarket.WAREHOUSE);
    cp.addLocation(lo);
    cp.setPrice(7.35);
    if (cp.getBarcode() != 111 || !"Bisli".equals(cp.getName()) || cp.getIngredients().size() != 1 || !cp.getIngredients().contains(gluten) || !cp.getManufacturer().equals(man) || !description.equals(cp.getDescription()) || cp.getPrice() != 7.35 || cp.getLocations().size() != 1 || !cp.getLocations().contains(lo))
        fail();
    CatalogProduct cp2 = new CatalogProduct(111, "Bamba", null, man, "", 12, bambaIm, null);
    if (!cp2.equals(cp))
        fail();
    cp2.setBarcode(11);
    if (cp2.equals(cp))
        fail();
}
Also used : Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) CatalogProduct(BasicCommonClasses.CatalogProduct) IOException(java.io.IOException) URL(java.net.URL) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 8 with Location

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

the class LocationTest method LocationTestMethod.

@Test
public void LocationTestMethod() {
    Location lo = new Location(1, 1, PlaceInMarket.WAREHOUSE);
    if (lo.getX() != 1 || lo.getY() != 1 || lo.getPlaceInMarket() != PlaceInMarket.WAREHOUSE)
        fail();
    lo.setX(2);
    lo.setY(2);
    lo.setPlaceInMarket(PlaceInMarket.STORE);
    //TODO: add null check?
    if (lo.getX() != 2 || lo.getY() != 2 || lo.getPlaceInMarket() != PlaceInMarket.STORE)
        fail();
    Location lo2 = new Location(1, 2, PlaceInMarket.STORE);
    if (lo2.equals(lo))
        fail();
    lo2.setX(2);
    if (!lo2.equals(lo))
        fail();
}
Also used : Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 9 with Location

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

the class ProductPackageTest method ProductPackageTestMethod.

@Test
public void ProductPackageTestMethod() {
    LocalDate ld = LocalDate.of(2016, 12, 11);
    SmartCode sc = new SmartCode(123, ld);
    Location lo = new Location(1, 1, PlaceInMarket.WAREHOUSE);
    ProductPackage pp = new ProductPackage(sc, 2, lo);
    if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 2 || !lo.equals(pp.getLocation()))
        fail();
    sc.setBarcode(111);
    lo.setX(2);
    pp.setSmartCode(sc);
    pp.setAmount(1);
    pp.setLocation(lo);
    if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 1 || !lo.equals(pp.getLocation()))
        fail();
    LocalDate ld2 = LocalDate.of(2015, 12, 12);
    SmartCode sc2 = new SmartCode(111, ld2);
    ProductPackage pp2 = new ProductPackage(sc2, 1, lo);
    if (pp2.equals(pp))
        fail();
    sc2.setExpirationDate(sc.getExpirationDate());
    pp.setSmartCode(sc2);
    if (!pp2.equals(pp))
        fail();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) LocalDate(java.time.LocalDate) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 10 with Location

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

the class RemoveProductPackageFromGroceryListTest method removeProductPackageFromGroceryListCriticalErrorTest.

@Test
public void removeProductPackageFromGroceryListCriticalErrorTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeProductFromGroceryList(cartID, productPackage);
    } catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (CriticalError __) {
    /* Successful */
    }
    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)

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