Search in sources :

Example 71 with ClientNotConnected

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

the class AddProductToGroceryListTest method addProductToGroceryListProductPackageNotExistTest.

@Test
public void addProductToGroceryListProductPackageNotExistTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
    } catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    } catch (ProductPackageNotExist __) {
    /* Successful */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 72 with ClientNotConnected

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

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

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

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

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)172 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)172 Test (org.junit.Test)147 CommandWrapper (ClientServerApi.CommandWrapper)124 CommandExecuter (CommandHandler.CommandExecuter)100 Gson (com.google.gson.Gson)96 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)81 SmartCode (BasicCommonClasses.SmartCode)63 ProductPackage (BasicCommonClasses.ProductPackage)55 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)48 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 Location (BasicCommonClasses.Location)34 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)32 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)31 CatalogProduct (BasicCommonClasses.CatalogProduct)21 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)19 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)19 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)19 Manufacturer (BasicCommonClasses.Manufacturer)12