Search in sources :

Example 81 with ClientNotConnected

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

the class SQLDatabaseConnectionTest method testWorkerCanSetSecurityQA.

@Test
public void testWorkerCanSetSecurityQA() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ForgotPasswordData p = new ForgotPasswordData("question", "answer");
    String result = null;
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setSecurityQAWorker(workerName, p);
        result = sqlConnection.getSecurityQuestionWorker(workerName);
        assertTrue(sqlConnection.verifySecurityAnswerWorker(workerName, "answer"));
        assertEquals("question", result);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 82 with ClientNotConnected

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

the class SQLDatabaseConnectionTest method testWorkerCanLoginWithNewPassword.

@Test
public void testWorkerCanLoginWithNewPassword() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setPasswordWorker(workerName, "newPass");
        //try to login with new password
        int sessionID = sqlConnection.loginWorker(workerName, "newPass");
        sqlConnection.logout(sessionID, workerName);
    } catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 83 with ClientNotConnected

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

the class SQLDatabaseConnectionTest method testCantEditNotExistedIngredient.

@Test
public void testCantEditNotExistedIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    Ingredient ingredient = new Ingredient(999, ingredientName);
    try {
        sqlConnection.editIngredient(null, ingredient);
        fail();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (IngredientNotExist e) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 84 with ClientNotConnected

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

the class SQLDatabaseConnectionTest method testCartCheckoutDoLogout.

/**
	 * [[SuppressWarningsSpartan]]
	 */
@Test
public void testCartCheckoutDoLogout() {
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    int session = 0;
    try {
        session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
        assertTrue(sqlConnection.isClientLoggedIn(session));
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        sqlConnection.addProductToGroceryList(session, productPackage);
    } catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.cartCheckout(session);
        assertFalse(sqlConnection.isClientLoggedIn(session));
    } catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
        fail();
    }
    try {
        sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
        fail();
    } catch (ClientNotConnected e) {
    } catch (CriticalError e) {
        fail();
    }
    try {
        sqlConnection.clearGroceryListsHistory();
    } catch (CriticalError e) {
        fail();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 85 with ClientNotConnected

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

the class SQLDatabaseConnectionTest method testCantAddWorkerAlreadyExisted.

@Test
public void testCantAddWorkerAlreadyExisted() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    //test add worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
        fail();
    }
    assert result != null;
    HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert map.containsKey(workerName);
    assertEquals(false, map.get(workerName));
    //test add again the same worker
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
        fail();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    } catch (ClientAlreadyExist e) {
    }
    //remove worker
    try {
        sqlConnection.removeWorker(null, workerName);
        result = sqlConnection.getWorkersList(null);
    } catch (CriticalError | ClientNotConnected | ClientNotExist e) {
        fail();
    }
    assert result != null;
    map = Serialization.deserializeWorkersHashMap(result);
    assert map != null;
    assert !map.containsKey(workerName);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) Test(org.junit.Test)

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)172 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)172 Test (org.junit.Test)147 CommandWrapper (ClientServerApi.CommandWrapper)124 CommandExecuter (CommandHandler.CommandExecuter)100 Gson (com.google.gson.Gson)96 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)81 SmartCode (BasicCommonClasses.SmartCode)63 ProductPackage (BasicCommonClasses.ProductPackage)55 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)48 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 Location (BasicCommonClasses.Location)34 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)32 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)31 CatalogProduct (BasicCommonClasses.CatalogProduct)21 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)19 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)19 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)19 Manufacturer (BasicCommonClasses.Manufacturer)12