Search in sources :

Example 21 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testCustomerCanSetProfile.

@Test
public void testCustomerCanSetProfile() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
    CustomerProfile result = null;
    try {
        sqlConnection.registerCustomer(customerName, customerName);
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        sqlConnection.setCustomerProfile(customerName, p);
        result = Serialization.deserialize(sqlConnection.getCustomerProfile(customerName), CustomerProfile.class);
    } catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeCustomer(customerName);
        } catch (CriticalError | ClientNotExist e) {
            e.printStackTrace();
        }
    }
    assertEquals(p.getBirthdate(), result.getBirthdate());
    assertEquals(p.getCity(), result.getCity());
    assertEquals(p.getEmailAddress(), result.getEmailAddress());
    assertEquals(p.getFirstName(), result.getFirstName());
    assertEquals(p.getLastName(), result.getLastName());
    assertEquals(p.getPhoneNumber(), result.getPhoneNumber());
    assertEquals(p.getStreet(), result.getStreet());
    assertEquals(p.getUserName(), result.getUserName());
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 22 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testCantSetSecurityQAToNotExistedCustomer.

@Test
public void testCantSetSecurityQAToNotExistedCustomer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ForgotPasswordData p = new ForgotPasswordData("question", "answer");
    try {
        sqlConnection.setSecurityQACustomer(customerName, p);
        fail();
    } catch (CriticalError e1) {
        fail();
    } catch (ClientNotExist e2) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 23 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testCustomerCanLoginLogout.

@Test
public void testCustomerCanLoginLogout() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.registerCustomer(customerName, customerName);
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        int sessionID = sqlConnection.loginCustomer(customerName, customerName);
        sqlConnection.logout(sessionID, customerName);
    } catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded | ClientNotConnected e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeCustomer(customerName);
        } catch (CriticalError | ClientNotExist e) {
            e.printStackTrace();
        }
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 24 with ClientNotExist

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

the class SQLDatabaseConnectionTest method testCantSetProfileToNotExistedCustomer.

@Test
public void testCantSetProfileToNotExistedCustomer() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
    try {
        sqlConnection.setCustomerProfile(customerName, p);
        fail();
    } catch (CriticalError | IngredientNotExist e1) {
        fail();
    } catch (ClientNotExist e2) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 25 with ClientNotExist

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

the class RemoveWorkerTest method removeWorkerCriticalErrorTest.

@Test
public void removeWorkerCriticalErrorTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_WORKER, new Gson().toJson(username, String.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeWorker(senderID, username);
    } catch (ClientNotExist | 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) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Aggregations

ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)40 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)40 Test (org.junit.Test)33 CommandWrapper (ClientServerApi.CommandWrapper)23 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)17 CommandExecuter (CommandHandler.CommandExecuter)16 Gson (com.google.gson.Gson)16 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)14 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)13 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)12 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)9 Login (BasicCommonClasses.Login)6 CustomerProfile (BasicCommonClasses.CustomerProfile)4 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)4 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)4 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)4