Search in sources :

Example 6 with Ingredient

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

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();
}
Also used : Ingredient(BasicCommonClasses.Ingredient) Test(org.junit.Test)

Example 8 with Ingredient

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) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 9 with Ingredient

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);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 10 with 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();
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Ingredient(BasicCommonClasses.Ingredient)

Aggregations

Ingredient (BasicCommonClasses.Ingredient)27 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)14 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)11 Test (org.junit.Test)9 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)8 Location (BasicCommonClasses.Location)6 Manufacturer (BasicCommonClasses.Manufacturer)6 CommandWrapper (ClientServerApi.CommandWrapper)6 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)6 Gson (com.google.gson.Gson)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5 CriticalError (SMExceptions.CommonExceptions.CriticalError)5 HashSet (java.util.HashSet)5 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)4 IngredientStillUsed (SQLDatabase.SQLDatabaseException.IngredientStillUsed)4 SQLException (java.sql.SQLException)4 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)3 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)3 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)3 ParamIDDoesNotExist (EmployeeDefs.AEmployeeException.ParamIDDoesNotExist)3