Search in sources :

Example 41 with SQLDatabaseConnection

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

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

the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromCart.

// TODO: test manufacturers methods
@Test
public void testRemoveMoreThanHaveFromCart() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
    int sessionCart = 0;
    try {
        sessionCart = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.addProductToGroceryList(sessionCart, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(11);
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageAmountNotMatch e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(10);
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
    } 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 43 with SQLDatabaseConnection

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

the class SQLDatabaseConnectionTest method testGetManufacturersList.

@Test
public void testGetManufacturersList() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    try {
        result = sqlConnection.getManufacturersList(null);
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Manufacturer> set = Serialization.deserializeManufacturersHashSet(result);
    assert set != null;
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) Test(org.junit.Test)

Example 44 with SQLDatabaseConnection

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

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

the class SQLDatabaseConnectionTest method testEditIngredient.

@Test
public void testEditIngredient() {
    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);
        ingredient.setName("newIngredient");
        sqlConnection.editIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
}
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