use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed 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.ManufacturerStillUsed in project SmartCity-Market by TechnionYP5777.
the class RemoveManufacturerTest method removeManufacturerCriticalErrorTest.
@Test
public void removeManufacturerCriticalErrorTest() {
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 CriticalError()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
} catch (ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e1) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantRemoveNotExistedManufacturer.
@Test
public void testCantRemoveNotExistedManufacturer() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String manufacturerName = "manydebug";
Manufacturer manufacturer = new Manufacturer(999, manufacturerName);
try {
sqlConnection.removeManufacturer(null, manufacturer);
fail();
} catch (CriticalError | ClientNotConnected | ManufacturerStillUsed e) {
fail();
} catch (ManufacturerNotExist e) {
}
}
use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveManufacturer.
@Test
public void testAddRemoveManufacturer() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String manufacturerName = "manydebug";
String result = null;
Manufacturer manufacturer = null;
//test add ingredient
try {
String tempID = sqlConnection.addManufacturer(null, manufacturerName);
manufacturer = Serialization.deserialize(tempID, Manufacturer.class);
result = sqlConnection.getManufacturersList(null);
} catch (CriticalError | ClientNotConnected e) {
fail();
}
assert result != null;
HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
assert set != null;
assert set.contains(manufacturer);
//test remove ingredient
try {
sqlConnection.removeManufacturer(null, manufacturer);
result = sqlConnection.getManufacturersList(null);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e) {
fail();
}
assert result != null;
set = Serialization.deserializeManufacturersHashSet(result);
assert set != null;
assert !set.contains(manufacturer);
}
use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testEditManufacturer.
@Test
public void testEditManufacturer() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String manufacturerName = "manydebug";
String result = null;
Manufacturer manufacturer = null;
try {
String tempID = sqlConnection.addManufacturer(null, manufacturerName);
manufacturer = Serialization.deserialize(tempID, Manufacturer.class);
manufacturer.setName("newManufacturer");
sqlConnection.editManufacturer(null, manufacturer);
result = sqlConnection.getManufacturersList(null);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist e) {
fail();
}
assert result != null;
HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
assert set != null;
assert set.contains(manufacturer);
try {
sqlConnection.removeManufacturer(null, manufacturer);
} catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e) {
fail();
}
}
Aggregations