Search in sources :

Example 91 with CommandExecuter

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

the class RegisterNewWorkerTest method registerNewWorkerClientNotConnectedTest.

@Test
public void registerNewWorkerClientNotConnectedTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    } catch (ClientNotConnected __) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 92 with CommandExecuter

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

the class RegisterNewWorkerTest method registerNewWorkerClientAlreadyExistTest.

@Test
public void registerNewWorkerClientAlreadyExistTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientAlreadyExist()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ClientAlreadyExist __) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 93 with CommandExecuter

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

the class RegisterNewWorkerTest method registerNewWorkerSuccessfulTest.

@Test
public void registerNewWorkerSuccessfulTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 94 with CommandExecuter

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

the class RemoveManufacturerTest method removeManufacturerSuccessfulTest.

@Test
public void removeManufacturerSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ClientNotConnected | ManufacturerNotExist | ManufacturerStillUsed 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) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 95 with CommandExecuter

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

the class RemoveManufacturerTest method removeManufacturerClientNotConnectedTest.

@Test
public void removeManufacturerClientNotConnectedTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeManufacturer(senderID, manufacturer);
    } catch (CriticalError | ManufacturerNotExist | ManufacturerStillUsed 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) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) Gson(com.google.gson.Gson) 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