use of SQLDatabase.SQLDatabaseConnection 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();
}
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromWarehouse.
@Test
public void testRemoveMoreThanHaveFromWarehouse() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
fail();
}
productPackage.setAmount(11);
try {
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
fail();
} catch (ProductPackageAmountNotMatch e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(10);
try {
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testGetManufacturers.
@Test
public void testGetManufacturers() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
try {
HashSet<Manufacturer> list = new HashSet<>();
list = Serialization.deserializeManufacturersHashSet(sqlConnection.getManufacturersList(null));
assert list.contains(new Manufacturer(1, "תנובה"));
assert list.contains(new Manufacturer(2, "מאפיות ברמן"));
} catch (CriticalError | ClientNotConnected e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanSetSecurityQA.
@Test
public void testCustomerCanSetSecurityQA() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ForgotPasswordData p = new ForgotPasswordData("question", "answer");
String result = null;
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
sqlConnection.setSecurityQACustomer(customerName, p);
result = sqlConnection.getSecurityQuestionCustomer(customerName);
assertTrue(sqlConnection.verifySecurityAnswerCustomer(customerName, "answer"));
assertEquals("question", result);
} catch (CriticalError | ClientNotExist e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
}
use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartClientType.
@Test
public void testCartClientType() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assert sqlConnection.isClientLoggedIn(session);
assertEquals(new Gson().toJson(CLIENT_TYPE.CART), sqlConnection.getClientType(session));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
} catch (CriticalError | ClientNotConnected e) {
fail();
}
try {
sqlConnection.getClientType(session);
fail();
} catch (ClientNotConnected e) {
} catch (CriticalError e) {
fail();
}
}
Aggregations