Search in sources :

Example 1 with ManufacturerStillUsed

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

the class CommandExecuter method removeManufacturer.

private void removeManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Remove 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 Remove Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to remove manufacturer " + manufacturer + " from system");
    try {
        c.removeManufacturer(inCommandWrapper.getSenderID(), manufacturer);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Remove manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (ManufacturerNotExist e) {
        log.info("Remove manufacturer customer command failed, manufacturer does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    } catch (ManufacturerStillUsed e) {
        log.info("Remove manufacturer customer command failed, manufacturer still in use");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE);
    }
    log.info("Remove manufacturer " + manufacturer + " from system finished");
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) CommandWrapper(ClientServerApi.CommandWrapper)

Example 2 with ManufacturerStillUsed

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

the class RemoveManufacturerTest method removeManufacturerCriticalErrorTest.

@Test
public void removeManufacturerCriticalErrorTest() {
    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 CriticalError()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e1) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, 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 3 with ManufacturerStillUsed

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

the class SQLDatabaseConnectionTest method testCantRemoveNotExistedManufacturer.

@Test
public void testCantRemoveNotExistedManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    Manufacturer manufacturer = new Manufacturer(999, manufacturerName);
    try {
        sqlConnection.removeManufacturer(null, manufacturer);
        fail();
    } catch (CriticalError | ClientNotConnected | ManufacturerStillUsed e) {
        fail();
    } catch (ManufacturerNotExist e) {
    }
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Test(org.junit.Test)

Example 4 with ManufacturerStillUsed

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

the class SQLDatabaseConnectionTest method testAddRemoveManufacturer.

@Test
public void testAddRemoveManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    String result = null;
    Manufacturer manufacturer = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addManufacturer(null, manufacturerName);
        manufacturer = Serialization.deserialize(tempID, Manufacturer.class);
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
    assert set.contains(manufacturer);
    //test remove ingredient
    try {
        sqlConnection.removeManufacturer(null, manufacturer);
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e) {
        fail();
    }
    assert result != null;
    set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
    assert !set.contains(manufacturer);
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Test(org.junit.Test)

Example 5 with ManufacturerStillUsed

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

the class SQLDatabaseConnectionTest method testEditManufacturer.

@Test
public void testEditManufacturer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String manufacturerName = "manydebug";
    String result = null;
    Manufacturer manufacturer = null;
    try {
        String tempID = sqlConnection.addManufacturer(null, manufacturerName);
        manufacturer = Serialization.deserialize(tempID, Manufacturer.class);
        manufacturer.setName("newManufacturer");
        sqlConnection.editManufacturer(null, manufacturer);
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist e) {
        fail();
    }
    assert result != null;
    HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
    assert set.contains(manufacturer);
    try {
        sqlConnection.removeManufacturer(null, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed e) {
        fail();
    }
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Test(org.junit.Test)

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)9 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)9 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)9 ManufacturerStillUsed (SQLDatabase.SQLDatabaseException.ManufacturerStillUsed)9 Test (org.junit.Test)8 CommandWrapper (ClientServerApi.CommandWrapper)6 CommandExecuter (CommandHandler.CommandExecuter)5 Gson (com.google.gson.Gson)5 Manufacturer (BasicCommonClasses.Manufacturer)4 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3