Search in sources :

Example 11 with CommandExecuter

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

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

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

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

Example 15 with CommandExecuter

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

the class GetAllWorkersTest method getAllManufacturersSuccessfulTest.

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