Search in sources :

Example 1 with CatalogProduct

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

the class EditProductFromCatalogTest method editCatalogProductManufacturerNotExistTest.

@Test
public void editCatalogProductManufacturerNotExistTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ManufacturerNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | IngredientNotExist e1) {
        fail();
    } catch (ManufacturerNotExist __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 2 with CatalogProduct

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

the class EditProductFromCatalogTest method editCatalogProductIngredientNotExistTest.

@Test
public void editCatalogProductIngredientNotExistTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ManufacturerNotExist e1) {
        fail();
    } catch (IngredientNotExist __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 3 with CatalogProduct

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

the class SQLDatabaseConnectionTest method testRemoveCatalogProductStillForSell.

@Test
public void testRemoveCatalogProductStillForSell() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CatalogProduct newProduct = createDummyProduct(456L, "testRemoveCatalogProductStillForSell", 1, "תנובה", 3.0);
    ProductPackage newPackage = new ProductPackage(new SmartCode(newProduct.getBarcode(), date232015), 5, locationWarehouse);
    // add catalog-product and add it to warehouse
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.addProductPackageToWarehouse(null, newPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.placeProductPackageOnShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.removeProductPackageFromShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) SQLDatabaseException(SQLDatabase.SQLDatabaseException) Test(org.junit.Test)

Example 4 with CatalogProduct

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

the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog2.

@Test
public void testSimpleGetProductFromCatalog2() {
    final long barcodeNum = 7290004685195L;
    final int manufaturerID = 2;
    final String manufaturerName = "מאפיות ברמן";
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CatalogProduct product = null;
    try {
        product = new Gson().fromJson(sqlConnection.getProductFromCatalog(null, barcodeNum), CatalogProduct.class);
    } catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
        fail();
    }
    assertEquals(product.getBarcode(), barcodeNum);
    assertEquals(product.getManufacturer().getId(), manufaturerID);
    assertEquals(product.getManufacturer().getName(), manufaturerName);
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 5 with CatalogProduct

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

the class SQLDatabaseConnectionTest method testSimpleAddRemoveProductFromCatalog.

@Test
public void testSimpleAddRemoveProductFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    HashSet<Location> locations = new HashSet<Location>();
    CatalogProduct newProduct = new CatalogProduct(123L, "name", ingredients, new Manufacturer(1, "תנובה"), "", 20, "", locations);
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
    try {
        sqlConnection.getProductFromCatalog(null, newProduct.getBarcode());
        fail();
    } catch (ProductNotExistInCatalog e) {
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) SQLDatabaseException(SQLDatabase.SQLDatabaseException) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Aggregations

CatalogProduct (BasicCommonClasses.CatalogProduct)26 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)22 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)21 Test (org.junit.Test)21 Gson (com.google.gson.Gson)19 CommandWrapper (ClientServerApi.CommandWrapper)18 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)16 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)16 CommandExecuter (CommandHandler.CommandExecuter)14 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)13 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)8 Manufacturer (BasicCommonClasses.Manufacturer)6 Ingredient (BasicCommonClasses.Ingredient)5 Location (BasicCommonClasses.Location)5 SmartCode (BasicCommonClasses.SmartCode)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)5 HashSet (java.util.HashSet)4 SQLDatabaseException (SQLDatabase.SQLDatabaseException)3 ProductPackage (BasicCommonClasses.ProductPackage)2 CriticalError (SMExceptions.CommonExceptions.CriticalError)2