Search in sources :

Example 46 with SQLDatabaseConnection

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

the class SQLDatabaseConnectionTest method testAddRemoveProductRealBarcodeFromCatalog.

@Test
public void testAddRemoveProductRealBarcodeFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    HashSet<Location> locations = new HashSet<Location>();
    CatalogProduct newProduct = new CatalogProduct(7290010328246L, "thini", ingredients, new Manufacturer(1, "תנובה"), "", 20, "", locations);
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
    try {
        sqlConnection.getProductFromCatalog(null, newProduct.getBarcode());
        fail();
    } catch (ProductNotExistInCatalog e) {
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) SQLDatabaseException(SQLDatabase.SQLDatabaseException) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 47 with SQLDatabaseConnection

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

the class SQLDatabaseConnectionTest method testSplitPackageToShelfPakage.

@Test
public void testSplitPackageToShelfPakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackageShelf = new ProductPackage(new SmartCode(barcodeDebug, date112000), 2, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
        sqlConnection.placeProductPackageOnShelves(null, productPackageShelf);
        assertEquals(productPackage.getAmount() - productPackageShelf.getAmount() + "", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals(productPackageShelf.getAmount() + "", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    productPackage.setAmount(3);
    try {
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        sqlConnection.removeProductPackageFromShelves(null, productPackageShelf);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageShelf));
    } catch (ProductPackageNotExist | CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
}
Also used : 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) Test(org.junit.Test)

Example 48 with SQLDatabaseConnection

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

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

the class SQLDatabaseConnectionTest method teardown.

@After
public void teardown() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackage2 = new ProductPackage(new SmartCode(barcodeDebug, date232015), 5, locationWarehouse);
    try {
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage2));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage2));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) After(org.junit.After)

Example 50 with SQLDatabaseConnection

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

the class SQLDatabaseConnectionTest method testLogoutAll.

@Test
public void testLogoutAll() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    int session = 0;
    try {
        session = sqlConnection.loginWorker("admin", "admin");
        sqlConnection.logoutAllUsers();
        session = sqlConnection.loginWorker("admin", "admin");
    } catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
        fail();
    }
    try {
        sqlConnection.logout(session, "admin");
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) 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