Search in sources :

Example 11 with NumberOfConnectionsExceeded

use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded 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();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 12 with NumberOfConnectionsExceeded

use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded 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();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 13 with NumberOfConnectionsExceeded

use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.

the class LoginTest method loginCustomerCriticalErrorTest.

@Test
public void loginCustomerCriticalErrorTest() {
    Login login = new Login("unknown", "unknown");
    String command = new CommandWrapper(0, CommandDescriptor.LOGIN_CUSTOMER, new Gson().toJson(login, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.loginCustomer(login.getUserName(), login.getPassword())).thenThrow(new CriticalError());
    } catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 14 with NumberOfConnectionsExceeded

use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.

the class LoginTest method loginCustomerUsernameDoesNotExistWrongPasswordTest.

@Test
public void loginCustomerUsernameDoesNotExistWrongPasswordTest() {
    Login login = new Login("unknown", "unknown");
    String command = new CommandWrapper(0, CommandDescriptor.LOGIN_CUSTOMER, new Gson().toJson(login, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.loginCustomer(login.getUserName(), login.getPassword())).thenThrow(new AuthenticationError());
    } catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD, out.getResultDescriptor());
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 15 with NumberOfConnectionsExceeded

use of SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded in project SmartCity-Market by TechnionYP5777.

the class LoginTest method loginEmployeeUsernameDoesNotExistWrongPasswordTest.

@Test
public void loginEmployeeUsernameDoesNotExistWrongPasswordTest() {
    Login login = new Login("unknown", "unknown");
    String command = new CommandWrapper(0, CommandDescriptor.LOGIN_EMPLOYEE, new Gson().toJson(login, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.loginWorker(login.getUserName(), login.getPassword())).thenThrow(new AuthenticationError());
    } catch (NumberOfConnectionsExceeded | ClientAlreadyConnected | CriticalError | AuthenticationError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD, out.getResultDescriptor());
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)27 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)27 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)27 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)27 Test (org.junit.Test)25 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)19 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)19 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)10 Login (BasicCommonClasses.Login)9 ProductPackage (BasicCommonClasses.ProductPackage)8 SmartCode (BasicCommonClasses.SmartCode)8 CommandWrapper (ClientServerApi.CommandWrapper)8 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)8 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)8 Gson (com.google.gson.Gson)7 CommandExecuter (CommandHandler.CommandExecuter)6 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)4 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)3 GroceryListIsEmpty (SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)3 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)1