Search in sources :

Example 6 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection 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 7 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection 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)

Example 8 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCartLogoutReturnsProductsToShelves.

@Test
public void testCartLogoutReturnsProductsToShelves() {
    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);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.addProductToGroceryList(session, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
        assert !sqlConnection.isClientLoggedIn(session);
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist 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) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 9 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCantVerifySecurityAnswerOfNotExistedCustomer.

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

Example 10 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testAddRemoveIngredient.

@Test
public void testAddRemoveIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    String result = null;
    Ingredient ingredient = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addIngredient(null, ingredientName);
        ingredient = Serialization.deserialize(tempID, Ingredient.class);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //test remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
    assert result != null;
    set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert !set.contains(ingredient);
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Aggregations

SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)62 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)61 Test (org.junit.Test)58 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)48 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)24 SmartCode (BasicCommonClasses.SmartCode)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)19 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)19 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)19 ProductPackage (BasicCommonClasses.ProductPackage)18 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)17 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)16 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)16 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)9 Manufacturer (BasicCommonClasses.Manufacturer)9 Ingredient (BasicCommonClasses.Ingredient)8 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)8 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)6 Gson (com.google.gson.Gson)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5