Search in sources :

Example 51 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method removeProductFromCatalogCommand.

private void removeProductFromCatalogCommand(SQLDatabaseConnection c) {
    SmartCode smartCode = null;
    log.info("Remove Product From Catalog command called");
    try {
        smartCode = Serialization.deserialize(inCommandWrapper.getData(), SmartCode.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Product From Catalog command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!smartCode.isValid()) {
        log.info("Remove Product From Catalog command failed, barcode can't be negative");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        try {
            c.removeProductFromCatalog(inCommandWrapper.getSenderID(), smartCode);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
        } catch (CriticalError e) {
            log.fatal("Remove Product From Catalog command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Remove Product From Catalog command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductNotExistInCatalog e) {
            log.info("Remove Product From Catalog command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        } catch (ProductStillForSale e) {
            log.info("Remove Product From Catalog command failed, product still for sale");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_STILL_FOR_SALE);
        }
        log.info("Remove Product From Catalog with product barcode " + smartCode.getBarcode() + " finished");
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper)

Example 52 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class RemoveProductFromCatalogTest method removeCatalogProductSuccessfulTest.

@Test
public void removeCatalogProductSuccessfulTest() {
    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_OK, 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 53 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class RemoveProductFromCatalogTest method removeCatalogProductCriticalErrorTest.

@Test
public void removeCatalogProductCriticalErrorTest() {
    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 CriticalError()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (ClientNotConnected | ProductNotExistInCatalog | ProductStillForSale e) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, 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 54 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class GetProductPackageAmountTest method getProductPackageAmountIllegalCatalogProductTest.

@Test
public void getProductPackageAmountIllegalCatalogProductTest() {
    assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson(new ProductPackage(new SmartCode(1, null), -1, new Location(0, 0, PlaceInMarket.WAREHOUSE)), ProductPackage.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 55 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class GetProductPackageAmountTest method getProductPackageAmountCriticalErrorTest.

@Test
public void getProductPackageAmountCriticalErrorTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getProductPackageAmonutOnShelves(senderID, productPackage)).thenThrow(new CriticalError());
        Mockito.when(sqlDatabaseConnection.getProductPackageAmonutInWarehouse(senderID, productPackage)).thenThrow(new CriticalError());
    } catch (ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    } catch (CriticalError __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Aggregations

SmartCode (BasicCommonClasses.SmartCode)82 Test (org.junit.Test)71 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)63 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)63 ProductPackage (BasicCommonClasses.ProductPackage)58 CommandWrapper (ClientServerApi.CommandWrapper)51 Gson (com.google.gson.Gson)50 CommandExecuter (CommandHandler.CommandExecuter)47 Location (BasicCommonClasses.Location)41 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)39 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)39 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 ProductStillForSale (SQLDatabase.SQLDatabaseException.ProductStillForSale)8 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)3 SMException (SMExceptions.SMException)3