use of BasicCommonClasses.Ingredient 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.Ingredient in project SmartCity-Market by TechnionYP5777.
the class IngredientTest method IngredientTestMethod.
@Test
public void IngredientTestMethod() {
Ingredient man = new Ingredient(1, "Telma");
if (man.getId() != 1 || !"Telma".equals(man.getName()))
fail();
man.setId(2);
man.setName("Osem");
if (man.getId() != 2 || !"Osem".equals(man.getName()))
fail();
//the equals consider only the id field
Ingredient man2 = new Ingredient(2, "Elite");
if (!man2.equals(man))
fail();
man2.setId(3);
if (man2.equals(man))
fail();
}
use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantEditNotExistedIngredient.
@Test
public void testCantEditNotExistedIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
Ingredient ingredient = new Ingredient(999, ingredientName);
try {
sqlConnection.editIngredient(null, ingredient);
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (IngredientNotExist e) {
}
}
use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveIngredient.
@Test
public void testAddRemoveIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
String result = null;
Ingredient ingredient = null;
//test add ingredient
try {
String tempID = sqlConnection.addIngredient(null, ingredientName);
ingredient = Serialization.deserialize(tempID, Ingredient.class);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected e) {
fail();
}
assert result != null;
HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert set.contains(ingredient);
//test remove ingredient
try {
sqlConnection.removeIngredient(null, ingredient);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
fail();
}
assert result != null;
set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert !set.contains(ingredient);
}
use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testGetEmptyIngredientsList.
public void testGetEmptyIngredientsList() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
String result = null;
try {
result = sqlConnection.getIngredientsList();
} catch (CriticalError e) {
fail();
}
assert result != null;
HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert set.isEmpty();
}
Aggregations