Search in sources :

Example 11 with ManufacturerNotExist

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

the class AddProductToCatalogTest method addCatalogProductClientNotConnectedTest.

@Test
public void addCatalogProductClientNotConnectedTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
    } catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError e) {
        fail();
    } catch (ClientNotConnected __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ProductAlreadyExistInCatalog(SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog) Test(org.junit.Test)

Example 12 with ManufacturerNotExist

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

the class AddProductToCatalogTest method addCatalogProductProductAlreadyExistInCatalogTest.

@Test
public void addCatalogProductProductAlreadyExistInCatalogTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductAlreadyExistInCatalog()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
    } catch (IngredientNotExist | ManufacturerNotExist | CriticalError | ClientNotConnected e) {
        fail();
    } catch (ProductAlreadyExistInCatalog __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_ALREADY_EXISTS, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ProductAlreadyExistInCatalog(SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog) Test(org.junit.Test)

Example 13 with ManufacturerNotExist

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

the class AddProductToCatalogTest method addCatalogProductSuccessfulTest.

@Test
public void addCatalogProductSuccessfulTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 1.5, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
    } catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError | ClientNotConnected e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ProductAlreadyExistInCatalog(SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog) Test(org.junit.Test)

Example 14 with ManufacturerNotExist

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

the class CommandExecuter method editProductFromCatalogCommand.

private void editProductFromCatalogCommand(SQLDatabaseConnection c) {
    CatalogProduct catalogProduct = null;
    log.info("Edit Product From Catalog command called");
    try {
        catalogProduct = Serialization.deserialize(inCommandWrapper.getData(), CatalogProduct.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Edit Product From Catalog command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!catalogProduct.isValid()) {
        log.info("Edit Product From Catalog command failed, barcode can't be negative");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        try {
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
            c.editProductInCatalog(inCommandWrapper.getSenderID(), catalogProduct);
        } catch (CriticalError e) {
            log.fatal("Edit Product From Catalog command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Edit 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("Edit Product From Catalog command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        } catch (IngredientNotExist e) {
            log.info("Edit Product From Catalog command failed, ingredient in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        } catch (ManufacturerNotExist e) {
            log.info("Edit Product From Catalog command failed, manufacturer in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        }
        log.info("Edit Product From Catalog with product " + catalogProduct + " finished");
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist)

Example 15 with ManufacturerNotExist

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

the class CommandExecuter method addProductToCatalogCommand.

private void addProductToCatalogCommand(SQLDatabaseConnection c) {
    CatalogProduct catalogProduct = null;
    log.info("Add Product To Catalog command called");
    try {
        catalogProduct = Serialization.deserialize(inCommandWrapper.getData(), CatalogProduct.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Add Product To Catalog command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!catalogProduct.isValid()) {
        log.info("Add Product To Catalog command failed, product is invalid");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        try {
            c.addProductToCatalog(inCommandWrapper.getSenderID(), catalogProduct);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
        } catch (CriticalError e) {
            log.fatal("Add Product To Catalog command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Add Product To Catalog command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductAlreadyExistInCatalog e) {
            log.info("Add Product To Catalog command failed, product already exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_ALREADY_EXISTS);
        } catch (IngredientNotExist e) {
            log.info("Add Product To Catalog command failed, ingredient in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        } catch (ManufacturerNotExist e) {
            log.info("Add Product To Catalog command failed, manufacturer in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        }
        log.info("Add Product To Catalog with product " + catalogProduct + " finished");
    }
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ProductAlreadyExistInCatalog(SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)31 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)31 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)31 CommandWrapper (ClientServerApi.CommandWrapper)27 Test (org.junit.Test)27 CommandExecuter (CommandHandler.CommandExecuter)23 Gson (com.google.gson.Gson)23 CatalogProduct (BasicCommonClasses.CatalogProduct)16 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)16 ManufacturerStillUsed (SQLDatabase.SQLDatabaseException.ManufacturerStillUsed)9 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)8 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)8 Manufacturer (BasicCommonClasses.Manufacturer)6 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)4