use of SQLDatabase.SQLDatabaseException.CriticalError in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveWorker.
@Test
public void testAddRemoveWorker() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
String result = null;
//test add worker
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
result = sqlConnection.getWorkersList(null);
} catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
fail();
}
assert result != null;
HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
assert map != null;
assert map.containsKey(workerName);
assertEquals(false, map.get(workerName));
//test remove worker
try {
sqlConnection.removeWorker(null, workerName);
result = sqlConnection.getWorkersList(null);
} catch (CriticalError | ClientNotConnected | ClientNotExist e) {
fail();
}
assert result != null;
map = Serialization.deserializeWorkersHashMap(result);
assert map != null;
assert !map.containsKey(workerName);
}
use of SQLDatabase.SQLDatabaseException.CriticalError 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();
}
}
use of SQLDatabase.SQLDatabaseException.CriticalError in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductNotExistInCatalogTest.
@Test
public void removeProductPackageFromStoreProductNotExistInCatalogTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
if (productPackage.getLocation().equals(PlaceInMarket.STORE))
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.CriticalError in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreCriticalErrorTest.
@Test
public void removeProductPackageFromStoreCriticalErrorTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
if (productPackage.getLocation().equals(PlaceInMarket.STORE))
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (CriticalError __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.CriticalError in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductPackageNotExistTest.
@Test
public void removeProductPackageFromStoreProductPackageNotExistTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
if (productPackage.getLocation().equals(PlaceInMarket.STORE))
Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
Aggregations