use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method editManufacturer.
private void editManufacturer(SQLDatabaseConnection c) {
Manufacturer manufacturer = null;
log.info("Edit 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 Edit Manufacturer command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to edit manufacturer " + manufacturer);
try {
c.editManufacturer(inCommandWrapper.getSenderID(), manufacturer);
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Edit manufacturer command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Edit manufacturer command failed, client is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (ManufacturerNotExist e) {
log.info("Edit manufacturer customer command failed, manufacturer does not exist");
outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
}
log.info("Edit manufacturer " + manufacturer + " to system finished");
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class RemoveManufacturerTest method removeManufacturerSuccessfulTest.
@Test
public void removeManufacturerSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed 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 RemoveManufacturerTest method removeManufacturerClientNotConnectedTest.
@Test
public void removeManufacturerClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
} catch (CriticalError | ManufacturerNotExist | ManufacturerStillUsed 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 RemoveManufacturerTest method removeManufacturerManufacturerNotExistTest.
@Test
public void removeManufacturerManufacturerNotExistTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ManufacturerNotExist()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
} catch (CriticalError | ClientNotConnected | ManufacturerStillUsed e1) {
fail();
} catch (ManufacturerNotExist e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.PARAM_ID_IS_NOT_EXIST, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ManufacturerNotExist in project SmartCity-Market by TechnionYP5777.
the class RemoveManufacturerTest method removeManufacturerManufacturerStillUsedTest.
@Test
public void removeManufacturerManufacturerStillUsedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ManufacturerStillUsed()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist e1) {
fail();
} catch (ManufacturerStillUsed e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE, out.getResultDescriptor());
}
Aggregations