Search in sources :

Example 16 with Manufacturer

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

the class SQLDatabaseConnectionTest method testAddRemoveProductRealBarcodeFromCatalog.

@Test
public void testAddRemoveProductRealBarcodeFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    HashSet<Location> locations = new HashSet<Location>();
    CatalogProduct newProduct = new CatalogProduct(7290010328246L, "thini", 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)

Example 17 with Manufacturer

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

the class SQLDatabaseConnectionTest method testGetManufacturers.

@Test
public void testGetManufacturers() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        HashSet<Manufacturer> list = new HashSet<>();
        list = Serialization.deserializeManufacturersHashSet(sqlConnection.getManufacturersList(null));
        assert list.contains(new Manufacturer(1, "תנובה"));
        assert list.contains(new Manufacturer(2, "מאפיות ברמן"));
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with Manufacturer

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

the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog.

@Test
public void testSimpleGetProductFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    ingredients.add(new Ingredient(1, "חלב"));
    HashSet<Location> locations = new HashSet<Location>();
    // locations.add(new Location(1, 1, PlaceInMarket.STORE));
    String milkImage = "";
    try {
        assertEquals(sqlConnection.getProductFromCatalog(null, 1234567890), new Gson().toJson(new CatalogProduct(1234567890L, "חלב", ingredients, new Manufacturer(1, "תנובה"), "", 10.5, milkImage, locations)));
    } catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
        fail();
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CatalogProduct(BasicCommonClasses.CatalogProduct) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 19 with Manufacturer

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

the class ViewProductFromCatalogTest method ViewProductFromCatalogSuccessfulTest.

@Test
public void ViewProductFromCatalogSuccessfulTest() {
    CatalogProduct testCatalogProduct = null, catalogProduct = new CatalogProduct(1234567890, "name", null, new Manufacturer(1, "Manufacturer"), "description", 22.0, null, null);
    CommandWrapper commandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct));
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(1234567890, null))).serialize())).thenReturn(commandWrapper.serialize());
    } catch (IOException ¢) {
        fail();
    }
    try {
        testCatalogProduct = worker.viewProductFromCatalog(1234567890);
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ProductNotExistInCatalog | ConnectionFailure ¢) {
        fail();
    }
    assertEquals(testCatalogProduct.getBarcode(), 1234567890);
    assertEquals(testCatalogProduct.getManufacturer().getId(), 1);
    assertEquals(testCatalogProduct.getManufacturer().getName(), "Manufacturer");
    assertEquals(testCatalogProduct.getName(), "name");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Manufacturer(BasicCommonClasses.Manufacturer) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) Test(org.junit.Test)

Example 20 with Manufacturer

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

the class CommandExecuter method editManufacturer.

private void editManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Edit manufacturer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        manufacturer = Serialization.deserialize(inCommandWrapper.getData(), Manufacturer.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Edit Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to edit manufacturer " + manufacturer);
    try {
        c.editManufacturer(inCommandWrapper.getSenderID(), manufacturer);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Edit manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Edit manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (ManufacturerNotExist e) {
        log.info("Edit manufacturer customer command failed, manufacturer does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    }
    log.info("Edit manufacturer " + manufacturer + " to system finished");
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) CommandWrapper(ClientServerApi.CommandWrapper)

Aggregations

Manufacturer (BasicCommonClasses.Manufacturer)22 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)13 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)12 Test (org.junit.Test)12 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)9 CatalogProduct (BasicCommonClasses.CatalogProduct)6 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)6 Ingredient (BasicCommonClasses.Ingredient)5 Location (BasicCommonClasses.Location)5 CommandWrapper (ClientServerApi.CommandWrapper)5 Gson (com.google.gson.Gson)5 HashSet (java.util.HashSet)5 CriticalError (SMExceptions.CommonExceptions.CriticalError)4 ManufacturerStillUsed (SQLDatabase.SQLDatabaseException.ManufacturerStillUsed)4 SmartCode (BasicCommonClasses.SmartCode)3 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)3 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)3 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)3 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)3 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)2