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