use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantEditNotExistedIngredient.
@Test
public void testCantEditNotExistedIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
Ingredient ingredient = new Ingredient(999, ingredientName);
try {
sqlConnection.editIngredient(null, ingredient);
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (IngredientNotExist e) {
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartCheckoutDoLogout.
/**
* [[SuppressWarningsSpartan]]
*/
@Test
public void testCartCheckoutDoLogout() {
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assertTrue(sqlConnection.isClientLoggedIn(session));
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
sqlConnection.addProductToGroceryList(session, productPackage);
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.cartCheckout(session);
assertFalse(sqlConnection.isClientLoggedIn(session));
} catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
fail();
} catch (ClientNotConnected e) {
} catch (CriticalError e) {
fail();
}
try {
sqlConnection.clearGroceryListsHistory();
} catch (CriticalError e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantAddWorkerAlreadyExisted.
@Test
public void testCantAddWorkerAlreadyExisted() {
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 add again the same worker
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (ClientAlreadyExist e) {
}
//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.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartLogoutReturnsProductsToShelves.
@Test
public void testCartLogoutReturnsProductsToShelves() {
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(session, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveNotExistedPakageFromCart.
@Test
public void testRemoveNotExistedPakageFromCart() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
int sessionCart = 0;
try {
sessionCart = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
} catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.addProductToGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
} catch (ClientNotConnected | CriticalError e) {
fail();
}
}
Aggregations