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);
}
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();
}
}
use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductClientNotConnectedTest.
@Test
public void addCatalogProductClientNotConnectedTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError e) {
fail();
} catch (ClientNotConnected __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductProductAlreadyExistInCatalogTest.
@Test
public void addCatalogProductProductAlreadyExistInCatalogTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductAlreadyExistInCatalog()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (IngredientNotExist | ManufacturerNotExist | CriticalError | ClientNotConnected e) {
fail();
} catch (ProductAlreadyExistInCatalog __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_ALREADY_EXISTS, out.getResultDescriptor());
}
use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductSuccessfulTest.
@Test
public void addCatalogProductSuccessfulTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 1.5, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Aggregations