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());
}
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();
}
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();
}
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();
}
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());
}
Aggregations