Search in sources :

Example 11 with AuthenticationError

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

the class SQLDatabaseConnectionTest method testCartCantCheckoutWithEmptyList.

@Test
public void testCartCantCheckoutWithEmptyList() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    int session = 0;
    try {
        session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
        assert sqlConnection.isClientLoggedIn(session);
    } catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
        fail();
    }
    try {
        sqlConnection.cartCheckout(session);
        fail();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (GroceryListIsEmpty e) {
    }
    try {
        sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 12 with AuthenticationError

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

the class SQLDatabaseConnectionTest method testSimpleAddMoveToCartRemovePakage.

@Test
public void testSimpleAddMoveToCartRemovePakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, 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, productPackage));
        sqlConnection.addProductToGroceryList(cartSession, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
    } catch (ClientNotConnected | 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) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 13 with AuthenticationError

use of SQLDatabase.SQLDatabaseException.AuthenticationError 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();
    }
}
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 14 with AuthenticationError

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

the class SQLDatabaseConnectionTest method testGetProductFromCatalogAfterLogoutWorker.

@Test
public void testGetProductFromCatalogAfterLogoutWorker() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    int session = 0;
    try {
        session = sqlConnection.loginWorker("admin", "admin");
    } catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded e1) {
        fail();
    }
    try {
        sqlConnection.getProductFromCatalog(session, 1234567890);
    } catch (ClientNotConnected | ProductNotExistInCatalog | CriticalError e) {
        fail();
    }
    try {
        sqlConnection.logout(session, "admin");
    } catch (ClientNotConnected | CriticalError e1) {
        fail();
    }
    try {
        sqlConnection.getProductFromCatalog(session, 1234567890);
        fail();
    } catch (ProductNotExistInCatalog | CriticalError e) {
        fail();
    } catch (ClientNotConnected e) {
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 15 with AuthenticationError

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

the class SQLDatabaseConnectionTest method testWhenCartCheckoutItProductsNotReturnToStore.

@Test
public void testWhenCartCheckoutItProductsNotReturnToStore() {
    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);
        assert sqlConnection.isClientLoggedIn(session);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.addProductToGroceryList(session, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.cartCheckout(session);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        assert !sqlConnection.isClientLoggedIn(session);
    } catch (CriticalError | ClientNotConnected | GroceryListIsEmpty | ProductNotExistInCatalog 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)

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