Search in sources :

Example 16 with ProductPackageAmountNotMatch

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

the class SQLDatabaseConnectionTest method testSimpleAddRemovePakage.

@Test
public void testSimpleAddRemovePakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist 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 17 with ProductPackageAmountNotMatch

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

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductNotExistInCatalogTest.

@Test
public void removeProductPackageFromStoreProductNotExistInCatalogTest() {
    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 ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (ProductNotExistInCatalog __) {
    /* Success */
    }
    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 18 with ProductPackageAmountNotMatch

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

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreCriticalErrorTest.

@Test
public void removeProductPackageFromStoreCriticalErrorTest() {
    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 CriticalError()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (CriticalError __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, 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 19 with ProductPackageAmountNotMatch

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

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductPackageNotExistTest.

@Test
public void removeProductPackageFromStoreProductPackageNotExistTest() {
    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 ProductPackageNotExist()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    } catch (ProductPackageNotExist __) {
    /* Success */
    }
    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 20 with ProductPackageAmountNotMatch

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

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