Search in sources :

Example 21 with ProductPackageAmountNotMatch

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

the class AddProductToGroceryListTest method addProductToGroceryListSuccessfulTest.

@Test
public void addProductToGroceryListSuccessfulTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 22 with ProductPackageAmountNotMatch

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

the class AddProductToGroceryListTest method addProductToGroceryListProductNotExistInCatalogTest.

@Test
public void addProductToGroceryListProductNotExistInCatalogTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
    } catch (ClientNotConnected | CriticalError | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (ProductNotExistInCatalog __) {
    /* Successful */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 23 with ProductPackageAmountNotMatch

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

the class AddProductToGroceryListTest method addProductToGroceryListProductPackageNotExistTest.

@Test
public void addProductToGroceryListProductPackageNotExistTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
    } catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    } catch (ProductPackageNotExist __) {
    /* Successful */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 24 with ProductPackageAmountNotMatch

use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch 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 25 with ProductPackageAmountNotMatch

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

ProductPackage (BasicCommonClasses.ProductPackage)43 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)43 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)43 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)43 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 SmartCode (BasicCommonClasses.SmartCode)39 Test (org.junit.Test)39 CommandWrapper (ClientServerApi.CommandWrapper)27 Location (BasicCommonClasses.Location)23 CommandExecuter (CommandHandler.CommandExecuter)23 Gson (com.google.gson.Gson)23 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)16 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 GroceryListIsEmpty (SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)2