use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListSuccessfulTest.
@Test
public void checkoutGroceryListSuccessfulTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListCriticalErrorTest.
@Test
public void checkoutGroceryListCriticalErrorTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (ClientNotConnected | GroceryListIsEmpty e) {
fail();
} catch (CriticalError __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class EditIngredientTest method editIngredientSuccessfulTest.
@Test
public void editIngredientSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).editIngredient(senderID, ingredient);
} catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class EditIngredientTest method editIngredientCriticalErrorTest.
@Test
public void editIngredientCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).editIngredient(senderID, ingredient);
} catch (ClientNotConnected | IngredientNotExist e1) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class Manager method addIngredient.
@Override
public Ingredient addIngredient(Ingredient w) throws InvalidParameter, CriticalError, EmployeeNotConnected, ConnectionFailure, ParamIDAlreadyExists {
log.info("Creating addIngredient command wrapper with Ingredient: " + w);
String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.ADD_INGREDIENT, Serialization.serialize(w))).serialize());
CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandDescriptor.getResultDescriptor());
} catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | ParamIDDoesNotExist | WorkerAlreadyExists | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ยข) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("addIngredient command succeed.");
return Serialization.deserialize(commandDescriptor.getData(), Ingredient.class);
}
Aggregations