Search in sources :

Example 6 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RemoveCustomerTest method removeCustomerCriticalErrorTest.

@Test
public void removeCustomerCriticalErrorTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_CUSTOMER, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeCustomer(username);
    } catch (ClientNotExist e) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 7 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RemoveIngredientTest method removeIngredientSuccessfulTest.

@Test
public void removeIngredientSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e1) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, 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 8 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RemoveIngredientTest method removeIngredientIngredientStillUsedTest.

@Test
public void removeIngredientIngredientStillUsedTest() {
    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 IngredientStillUsed()).when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist e1) {
        fail();
    } catch (IngredientStillUsed e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INGREDIENT_STILL_IN_USE, 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 9 with CommandExecuter

use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.

the class RemoveIngredientTest method removeIngredientCriticalErrorTest.

@Test
public void removeIngredientCriticalErrorTest() {
    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 CriticalError()).when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
    } catch (ClientNotConnected | IngredientNotExist | IngredientStillUsed e1) {
        fail();
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, 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 10 with CommandExecuter

use of CommandHandler.CommandExecuter 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)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)135 CommandExecuter (CommandHandler.CommandExecuter)135 Test (org.junit.Test)135 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)128 Gson (com.google.gson.Gson)119 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)100 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)48 SmartCode (BasicCommonClasses.SmartCode)47 Location (BasicCommonClasses.Location)37 ProductPackage (BasicCommonClasses.ProductPackage)37 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)32 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)23 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)23 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)23 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)16 CatalogProduct (BasicCommonClasses.CatalogProduct)14 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)9 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)7 Login (BasicCommonClasses.Login)6 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)6