use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromGroceryListTest method removeProductPackageFromGroceryListProductNotExistInCatalogTest.
@Test
public void removeProductPackageFromGroceryListProductNotExistInCatalogTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductFromGroceryList(cartID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreSuccessfulTest.
@Test
public void removeProductPackageFromStoreSuccessfulTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.STORE));
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
if (productPackage.getLocation().equals(PlaceInMarket.STORE))
Mockito.doNothing().when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doNothing().when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesProductPackageAmountNotMatchTest.
@Test
public void placeProductPackageOnShelvesProductPackageAmountNotMatchTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
} catch (ProductPackageAmountNotMatch __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesProductPackageNotExistTest.
@Test
public void placeProductPackageOnShelvesProductPackageNotExistTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class ViewCatalogProductTest method viewCatalogProductSuccessfulTest.
@Test
public void viewCatalogProductSuccessfulTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(0, null);
String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenReturn("");
} catch (ClientNotConnected | ProductNotExistInCatalog | CriticalError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Aggregations