Search in sources :

Example 1 with ProductStillForSale

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

the class RemoveProductFromCatalogTest method removeCatalogProductInvalidParamTest.

@Test
public void removeCatalogProductInvalidParamTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(-1, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductStillForSale e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 2 with ProductStillForSale

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

the class RemoveProductFromCatalogTest method removeCatalogProductStillForSaleTest.

@Test
public void removeCatalogProductStillForSaleTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(1, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductStillForSale()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
        fail();
    } catch (ProductStillForSale e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_STILL_FOR_SALE, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 3 with ProductStillForSale

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

the class RemoveProductFromCatalogTest method removeCatalogProductClientNotConnectedTest.

@Test
public void removeCatalogProductClientNotConnectedTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(1, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (CriticalError | ProductNotExistInCatalog | ProductStillForSale e) {
        fail();
    } catch (ClientNotConnected e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 4 with ProductStillForSale

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

the class SQLDatabaseConnectionTest method testRemoveCatalogProductStillForSell.

@Test
public void testRemoveCatalogProductStillForSell() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CatalogProduct newProduct = createDummyProduct(456L, "testRemoveCatalogProductStillForSell", 1, "תנובה", 3.0);
    ProductPackage newPackage = new ProductPackage(new SmartCode(newProduct.getBarcode(), date232015), 5, locationWarehouse);
    // add catalog-product and add it to warehouse
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.addProductPackageToWarehouse(null, newPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.placeProductPackageOnShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.removeProductPackageFromShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) SQLDatabaseException(SQLDatabase.SQLDatabaseException) Test(org.junit.Test)

Example 5 with ProductStillForSale

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

the class RemoveProductFromCatalogTest method removeCatalogProductNotExistInCatalogTest.

@Test
public void removeCatalogProductNotExistInCatalogTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(1, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (CriticalError | ClientNotConnected | ProductStillForSale e) {
        fail();
    } catch (ProductNotExistInCatalog e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

SmartCode (BasicCommonClasses.SmartCode)8 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)8 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)8 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)8 ProductStillForSale (SQLDatabase.SQLDatabaseException.ProductStillForSale)8 CommandWrapper (ClientServerApi.CommandWrapper)7 Gson (com.google.gson.Gson)7 Test (org.junit.Test)7 CommandExecuter (CommandHandler.CommandExecuter)6 CatalogProduct (BasicCommonClasses.CatalogProduct)1 ProductPackage (BasicCommonClasses.ProductPackage)1 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)1 SQLDatabaseException (SQLDatabase.SQLDatabaseException)1