use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductIngredientNotExistTest.
@Test
public void addCatalogProductIngredientNotExistTest() {
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 IngredientNotExist()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | ManufacturerNotExist | CriticalError | ClientNotConnected e) {
fail();
} catch (IngredientNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductInvalidParamTest.
@Test
public void addCatalogProductInvalidParamTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, -1, 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_INVALID_PARAMETER, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListCriticalErrorTest.
@Test
public void addProductToGroceryListCriticalErrorTest() {
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 CriticalError()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (CriticalError __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListProductPackageAmountNotMatchTest.
@Test
public void addProductToGroceryListProductPackageAmountNotMatchTest() {
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 ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
} catch (ProductPackageAmountNotMatch __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerCriticalErrorTest.
@Test
public void addNewManufacturerCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.getName())).thenThrow(new CriticalError());
} catch (ClientNotConnected e) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Aggregations