use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method removeManufacturer.
private void removeManufacturer(SQLDatabaseConnection c) {
Manufacturer manufacturer = null;
log.info("Remove 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 Remove Manufacturer command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to remove manufacturer " + manufacturer + " from system");
try {
c.removeManufacturer(inCommandWrapper.getSenderID(), manufacturer);
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Remove manufacturer command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Remove manufacturer command failed, client is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (ManufacturerNotExist e) {
log.info("Remove manufacturer customer command failed, manufacturer does not exist");
outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
} catch (ManufacturerStillUsed e) {
log.info("Remove manufacturer customer command failed, manufacturer still in use");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE);
}
log.info("Remove manufacturer " + manufacturer + " from system finished");
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class EditManufacturerTest method editManufacturerSuccessfulTest.
@Test
public void editManufacturerSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).editManufacturer(senderID, manufacturer);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist e1) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class EditManufacturerTest method editManufacturerClientNotConnectedTest.
@Test
public void editManufacturerClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).editManufacturer(senderID, manufacturer);
} catch (CriticalError | ManufacturerNotExist e1) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class EditProductFromCatalogTest method editCatalogProductManufacturerNotExistTest.
@Test
public void editCatalogProductManufacturerNotExistTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ManufacturerNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | IngredientNotExist e1) {
fail();
} catch (ManufacturerNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class EditProductFromCatalogTest method editCatalogProductIngredientNotExistTest.
@Test
public void editCatalogProductIngredientNotExistTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ManufacturerNotExist e1) {
fail();
} catch (IngredientNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Aggregations