Search in sources :

Example 26 with IngredientNotExist

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

the class UpdateCustomerProfileTest method updateCustomerProfileClientNotExistTest.

@Test
public void updateCustomerProfileClientNotExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | IngredientNotExist e1) {
        fail();
    } catch (ClientNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 27 with IngredientNotExist

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

the class UpdateCustomerProfileTest method updateCustomerProfileIngredientNotExistTest.

@Test
public void updateCustomerProfileIngredientNotExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } catch (IngredientNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 28 with IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist 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 29 with IngredientNotExist

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

Example 30 with IngredientNotExist

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

the class CommandExecuter method updateCustomerProfile.

private void updateCustomerProfile(SQLDatabaseConnection c) {
    CustomerProfile profile = null;
    log.info("Update customer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        profile = Serialization.deserialize(inCommandWrapper.getData(), CustomerProfile.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Update Customer Data command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to update customer " + profile + " to system");
    try {
        c.setCustomerProfile(profile.getUserName(), profile);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Update customer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Update customer command failed, client is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    } catch (IngredientNotExist e) {
        log.info("Update customer command failed, client try to use not existed ingredient");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    }
    log.info("Update customer " + profile + " to system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Aggregations

CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)45 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)45 CommandWrapper (ClientServerApi.CommandWrapper)39 Test (org.junit.Test)38 CommandExecuter (CommandHandler.CommandExecuter)32 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)32 Gson (com.google.gson.Gson)32 CatalogProduct (BasicCommonClasses.CatalogProduct)16 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)16 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)13 IngredientStillUsed (SQLDatabase.SQLDatabaseException.IngredientStillUsed)10 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)8 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)8 Ingredient (BasicCommonClasses.Ingredient)7 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)7 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)6 CustomerProfile (BasicCommonClasses.CustomerProfile)4 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)2