Search in sources :

Example 1 with GroceryListIsEmpty

use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty 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 2 with GroceryListIsEmpty

use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty 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 3 with GroceryListIsEmpty

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

the class CheckoutGroceryListTest method checkoutGroceryListSuccessfulTest.

@Test
public void checkoutGroceryListSuccessfulTest() {
    int cartID = 1;
    String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).cartCheckout(cartID);
    } catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 4 with GroceryListIsEmpty

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

the class CheckoutGroceryListTest method checkoutGroceryListCriticalErrorTest.

@Test
public void checkoutGroceryListCriticalErrorTest() {
    int cartID = 1;
    String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).cartCheckout(cartID);
    } catch (ClientNotConnected | GroceryListIsEmpty e) {
        fail();
    } catch (CriticalError __) {
    /* Successful */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 5 with GroceryListIsEmpty

use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty 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

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)8 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)8 GroceryListIsEmpty (SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)8 Test (org.junit.Test)7 CommandWrapper (ClientServerApi.CommandWrapper)5 CommandExecuter (CommandHandler.CommandExecuter)4 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)3 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)3 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)3 ProductPackage (BasicCommonClasses.ProductPackage)2 SmartCode (BasicCommonClasses.SmartCode)2 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)2 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)2 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)2