use of ClientServerApi.CommandWrapper 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 ClientServerApi.CommandWrapper 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());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListSuccessfulTest.
@Test
public void addProductToGroceryListSuccessfulTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListProductNotExistInCatalogTest.
@Test
public void addProductToGroceryListProductNotExistInCatalogTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | CriticalError | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListProductPackageNotExistTest.
@Test
public void addProductToGroceryListProductPackageNotExistTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
Aggregations