Search in sources :

Example 16 with ManufacturerNotExist

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

the class CommandExecuter method editManufacturer.

private void editManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Edit manufacturer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        manufacturer = Serialization.deserialize(inCommandWrapper.getData(), Manufacturer.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Edit Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to edit manufacturer " + manufacturer);
    try {
        c.editManufacturer(inCommandWrapper.getSenderID(), manufacturer);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Edit manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Edit manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (ManufacturerNotExist e) {
        log.info("Edit manufacturer customer command failed, manufacturer does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    }
    log.info("Edit manufacturer " + manufacturer + " to system finished");
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) CommandWrapper(ClientServerApi.CommandWrapper)

Example 17 with ManufacturerNotExist

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

the class RemoveManufacturerTest method removeManufacturerSuccessfulTest.

@Test
public void removeManufacturerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e1) {
        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) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 18 with ManufacturerNotExist

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

the class RemoveManufacturerTest method removeManufacturerClientNotConnectedTest.

@Test
public void removeManufacturerClientNotConnectedTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ManufacturerNotExist | ManufacturerStillUsed e1) {
        fail();
    } catch (ClientNotConnected e) {
    /* 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) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 19 with ManufacturerNotExist

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

the class RemoveManufacturerTest method removeManufacturerManufacturerNotExistTest.

@Test
public void removeManufacturerManufacturerNotExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ManufacturerNotExist()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerStillUsed e1) {
        fail();
    } catch (ManufacturerNotExist e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.PARAM_ID_IS_NOT_EXIST, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 20 with ManufacturerNotExist

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

the class RemoveManufacturerTest method removeManufacturerManufacturerStillUsedTest.

@Test
public void removeManufacturerManufacturerStillUsedTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ManufacturerStillUsed()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist e1) {
        fail();
    } catch (ManufacturerStillUsed e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

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