Search in sources :

Example 36 with ProductPackageNotExist

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

the class SQLDatabaseConnectionTest method testSplitPackageToCartPakage.

@Test
public void testSplitPackageToCartPakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackageCart = new ProductPackage(new SmartCode(barcodeDebug, date112000), 2, 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, productPackageCart));
        sqlConnection.addProductToGroceryList(cartSession, productPackageCart);
        assertEquals(productPackage.getAmount() - productPackageCart.getAmount() + "", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
        fail();
    }
    productPackage.setAmount(3);
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        sqlConnection.removeProductFromGroceryList(cartSession, productPackageCart);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("2", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
        sqlConnection.removeProductPackageFromShelves(null, productPackageCart);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
        sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
    } catch (ProductPackageNotExist | CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch 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 37 with ProductPackageNotExist

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

the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromCart.

// TODO: test manufacturers methods
@Test
public void testRemoveMoreThanHaveFromCart() {
    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);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.addProductToGroceryList(sessionCart, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(11);
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageAmountNotMatch e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(10);
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
    } 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 38 with ProductPackageNotExist

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

the class SQLDatabaseConnectionTest method testSplitPackageToShelfPakage.

@Test
public void testSplitPackageToShelfPakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackageShelf = new ProductPackage(new SmartCode(barcodeDebug, date112000), 2, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
        sqlConnection.placeProductPackageOnShelves(null, productPackageShelf);
        assertEquals(productPackage.getAmount() - productPackageShelf.getAmount() + "", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals(productPackageShelf.getAmount() + "", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(3);
    try {
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        sqlConnection.removeProductPackageFromShelves(null, productPackageShelf);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
    } catch (ProductPackageNotExist | CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
}
Also used : 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) Test(org.junit.Test)

Example 39 with ProductPackageNotExist

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

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductPackageAmountNotMatchTest.

@Test
public void removeProductPackageFromStoreProductPackageAmountNotMatchTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        if (productPackage.getLocation().equals(PlaceInMarket.STORE))
            Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
        fail();
    } catch (ProductPackageAmountNotMatch __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) 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 40 with ProductPackageNotExist

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

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreClientNotConnectedTest.

@Test
public void removeProductPackageFromStoreClientNotConnectedTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        if (productPackage.getLocation().equals(PlaceInMarket.STORE))
            Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (ClientNotConnected __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, 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)

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