use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSplitPackageToCartPakage.
@Test
public void testSplitPackageToCartPakage() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackageCart = new ProductPackage(new SmartCode(barcodeDebug, date112000), 2, locationWarehouse);
int cartSession = 0;
try {
cartSession = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.addProductToGroceryList(cartSession, productPackageCart);
assertEquals(productPackage.getAmount() - productPackageCart.getAmount() + "", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
productPackage.setAmount(3);
try {
sqlConnection.removeProductPackageFromShelves(null, productPackage);
sqlConnection.removeProductFromGroceryList(cartSession, productPackageCart);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("2", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.removeProductPackageFromShelves(null, productPackageCart);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
} catch (ProductPackageNotExist | CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromCart.
// TODO: test manufacturers methods
@Test
public void testRemoveMoreThanHaveFromCart() {
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);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(11);
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageAmountNotMatch e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(10);
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanLoginLogout.
@Test
public void testCustomerCanLoginLogout() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
int sessionID = sqlConnection.loginCustomer(customerName, customerName);
sqlConnection.logout(sessionID, customerName);
} catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded | ClientNotConnected e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
}
use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testLogoutAll.
@Test
public void testLogoutAll() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginWorker("admin", "admin");
sqlConnection.logoutAllUsers();
session = sqlConnection.loginWorker("admin", "admin");
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
try {
sqlConnection.logout(session, "admin");
} catch (CriticalError | ClientNotConnected e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanLoginWithNewPassword.
@Test
public void testCustomerCanLoginWithNewPassword() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
sqlConnection.setPasswordCustomer(customerName, "newPass");
//try to login with new password
int sessionID = sqlConnection.loginCustomer(customerName, "newPass");
sqlConnection.logout(sessionID, customerName);
} catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
}
Aggregations