Search in sources :

Example 16 with ClientAlreadyExist

use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist 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 17 with ClientAlreadyExist

use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist 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 18 with ClientAlreadyExist

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

the class SQLDatabaseConnectionTest method testCustomerCanLoginWithNewPassword.

@Test
public void testCustomerCanLoginWithNewPassword() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.registerCustomer(customerName, customerName);
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        sqlConnection.setPasswordCustomer(customerName, "newPass");
        //try to login with new password
        int sessionID = sqlConnection.loginCustomer(customerName, "newPass");
        sqlConnection.logout(sessionID, customerName);
    } catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | 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 19 with ClientAlreadyExist

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

the class SQLDatabaseConnectionTest method testCustomerCanSetSecurityQA.

@Test
public void testCustomerCanSetSecurityQA() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ForgotPasswordData p = new ForgotPasswordData("question", "answer");
    String result = null;
    try {
        sqlConnection.registerCustomer(customerName, customerName);
    } catch (CriticalError | ClientAlreadyExist e) {
        fail();
    }
    try {
        sqlConnection.setSecurityQACustomer(customerName, p);
        result = sqlConnection.getSecurityQuestionCustomer(customerName);
        assertTrue(sqlConnection.verifySecurityAnswerCustomer(customerName, "answer"));
        assertEquals("question", result);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeCustomer(customerName);
        } catch (CriticalError | ClientNotExist e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Aggregations

ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)19 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)19 Test (org.junit.Test)17 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)14 CommandWrapper (ClientServerApi.CommandWrapper)11 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)11 CommandExecuter (CommandHandler.CommandExecuter)9 Gson (com.google.gson.Gson)9 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)8 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)7 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)6 Login (BasicCommonClasses.Login)5 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)3 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)3 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)3 CustomerProfile (BasicCommonClasses.CustomerProfile)2