Search in sources :

Example 6 with ManufacturerStillUsed

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

use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed 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 8 with ManufacturerStillUsed

use of SQLDatabase.SQLDatabaseException.ManufacturerStillUsed 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 9 with ManufacturerStillUsed

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