Search in sources :

Example 41 with CriticalError

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

the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest2.

@Test
public void registerNewCustomerProfileCriticalErrorTest2() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        Mockito.doThrow(new ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | IngredientNotExist e1) {
        fail();
    } catch (ClientNotExist e) {
    /* success */
    }
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
    } catch (CriticalError | ClientNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 42 with CriticalError

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

the class RegisterNewCustomerTest method registerNewCustomerProfileClientAlreadyExistTest.

@Test
public void registerNewCustomerProfileClientAlreadyExistTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ClientAlreadyExist()).when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
    } catch (CriticalError e) {
        fail();
    } catch (ClientAlreadyExist e) {
    /* success */
    }
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
    } catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
        fail();
    }
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
    } catch (CriticalError | ClientNotExist e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 43 with CriticalError

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

the class IsFreeCustomerNameTest method isFreeCustomerNameSuccessfulTest1.

@Test
public void isFreeCustomerNameSuccessfulTest1() {
    String command = new CommandWrapper(senderID, CommandDescriptor.IS_FREE_CUSTOMER_NAME, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.isCustomerUsernameAvailable(username)).thenReturn(true);
    } catch (CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 44 with CriticalError

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

the class IsFreeCustomerNameTest method isFreeCustomerNameCriticalErrorTest.

@Test
public void isFreeCustomerNameCriticalErrorTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.IS_FREE_CUSTOMER_NAME, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.isCustomerUsernameAvailable(username)).thenThrow(new CriticalError());
    } catch (CriticalError e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 45 with CriticalError

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

the class IsLoggedInTest method isLoggedInSuccessfulTest.

@Test
public void isLoggedInSuccessfulTest() {
    int senderID = 0;
    String command = new CommandWrapper(senderID, CommandDescriptor.IS_LOGGED_IN).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.isClientLoggedIn(senderID)).thenReturn(true);
    } catch (CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(true, new Gson().fromJson(out.getData(), Boolean.class));
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)225 Test (org.junit.Test)186 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)172 CommandWrapper (ClientServerApi.CommandWrapper)162 CommandExecuter (CommandHandler.CommandExecuter)128 Gson (com.google.gson.Gson)118 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)81 SmartCode (BasicCommonClasses.SmartCode)63 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)61 ProductPackage (BasicCommonClasses.ProductPackage)55 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)45 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)40 Location (BasicCommonClasses.Location)35 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)31 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)27 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)27 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)27 CatalogProduct (BasicCommonClasses.CatalogProduct)22