Search in sources :

Example 76 with CommandWrapper

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 77 with CommandWrapper

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 78 with CommandWrapper

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 79 with CommandWrapper

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 80 with CommandWrapper

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);
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) EmployeeAlreadyConnected(EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) ProductAlreadyExistInCatalog(EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog) ProductStillForSale(EmployeeDefs.AEmployeeException.ProductStillForSale) AmountBiggerThanAvailable(EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable) InvalidCommandDescriptor(EmployeeDefs.AEmployeeException.InvalidCommandDescriptor) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)218 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)162 Test (org.junit.Test)144 CommandExecuter (CommandHandler.CommandExecuter)135 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)124 Gson (com.google.gson.Gson)123 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)57 SmartCode (BasicCommonClasses.SmartCode)51 ProductPackage (BasicCommonClasses.ProductPackage)45 CriticalError (SMExceptions.CommonExceptions.CriticalError)39 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)39 Location (BasicCommonClasses.Location)37 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)27 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)27 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)27 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)23 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)22 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)21 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)21 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)21