Search in sources :

Example 21 with ClientNotConnected

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

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

the class EditManufacturerTest method editManufacturerSuccessfulTest.

@Test
public void editManufacturerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).editManufacturer(senderID, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist e1) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 23 with ClientNotConnected

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

the class EditManufacturerTest method editManufacturerClientNotConnectedTest.

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

Example 24 with ClientNotConnected

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

the class EditProductFromCatalogTest method editCatalogProductManufacturerNotExistTest.

@Test
public void editCatalogProductManufacturerNotExistTest() {
    int senderID = 1;
    CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ManufacturerNotExist()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | IngredientNotExist e1) {
        fail();
    } catch (ManufacturerNotExist __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 25 with ClientNotConnected

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

the class GetAllWorkersTest method getAllManufacturersCriticalErrorTest.

@Test
public void getAllManufacturersCriticalErrorTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.GET_ALL_WORKERS).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getWorkersList(senderID)).thenThrow(new CriticalError());
    } catch (ClientNotConnected e) {
        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) CommandWrapper(ClientServerApi.CommandWrapper) 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