Search in sources :

Example 6 with IngredientStillUsed

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

the class RemoveIngredientTest method removeIngredientClientNotConnectedTest.

@Test
public void removeIngredientClientNotConnectedTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
    } catch (CriticalError | IngredientNotExist | IngredientStillUsed e1) {
        fail();
    } catch (ClientNotConnected e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 7 with IngredientStillUsed

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

the class SQLDatabaseConnectionTest method testAddRemoveIngredient.

@Test
public void testAddRemoveIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    String result = null;
    Ingredient ingredient = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addIngredient(null, ingredientName);
        ingredient = Serialization.deserialize(tempID, Ingredient.class);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //test remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
    assert result != null;
    set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert !set.contains(ingredient);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 8 with IngredientStillUsed

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

the class SQLDatabaseConnectionTest method testCantRemoveNotExistedIngredient.

@Test
public void testCantRemoveNotExistedIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    Ingredient ingredient = new Ingredient(999, ingredientName);
    try {
        sqlConnection.removeIngredient(null, ingredient);
        fail();
    } catch (CriticalError | ClientNotConnected | IngredientStillUsed e) {
        fail();
    } catch (IngredientNotExist e) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 9 with IngredientStillUsed

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

the class SQLDatabaseConnectionTest method testEditIngredient.

@Test
public void testEditIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    String result = null;
    Ingredient ingredient = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addIngredient(null, ingredientName);
        ingredient = Serialization.deserialize(tempID, Ingredient.class);
        ingredient.setName("newIngredient");
        sqlConnection.editIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 10 with IngredientStillUsed

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

the class RemoveIngredientTest method removeIngredientIngredientNotExistTest.

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

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)10 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)10 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)10 IngredientStillUsed (SQLDatabase.SQLDatabaseException.IngredientStillUsed)10 Test (org.junit.Test)8 CommandWrapper (ClientServerApi.CommandWrapper)7 Ingredient (BasicCommonClasses.Ingredient)5 CommandExecuter (CommandHandler.CommandExecuter)5 Gson (com.google.gson.Gson)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3