Search in sources :

Example 11 with ProductPackage

use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testSimpleAddMoveToShelfRemovePakage.

@Test
public void testSimpleAddMoveToShelfRemovePakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        fail();
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    } catch (ProductPackageNotExist e) {
    }
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.close();
    } catch (CriticalError 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 12 with ProductPackage

use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testMovePakageToShelfAndRemoveTwice.

@Test
public void testMovePakageToShelfAndRemoveTwice() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    }
    try {
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        fail();
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    } catch (ProductPackageNotExist e) {
    }
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist 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 13 with ProductPackage

use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testRemoveCatalogProductStillForSell.

@Test
public void testRemoveCatalogProductStillForSell() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    CatalogProduct newProduct = createDummyProduct(456L, "testRemoveCatalogProductStillForSell", 1, "תנובה", 3.0);
    ProductPackage newPackage = new ProductPackage(new SmartCode(newProduct.getBarcode(), date232015), 5, locationWarehouse);
    // add catalog-product and add it to warehouse
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.addProductPackageToWarehouse(null, newPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.placeProductPackageOnShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
    } catch (SQLDatabaseException e) {
        fail();
    }
    // try to remove
    try {
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
        fail();
    } catch (ProductStillForSale e1) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    // move to shelf
    try {
        sqlConnection.removeProductPackageFromShelves(null, newPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) SQLDatabaseException(SQLDatabase.SQLDatabaseException) Test(org.junit.Test)

Example 14 with ProductPackage

use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testMovePakageToCartAndRemoveTwice.

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

use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testSimpleAddRemovePakage.

@Test
public void testSimpleAddRemovePakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist 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)

Aggregations

ProductPackage (BasicCommonClasses.ProductPackage)68 SmartCode (BasicCommonClasses.SmartCode)58 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)55 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)55 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)55 Test (org.junit.Test)55 CommandWrapper (ClientServerApi.CommandWrapper)45 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 Location (BasicCommonClasses.Location)40 Gson (com.google.gson.Gson)38 CommandExecuter (CommandHandler.CommandExecuter)37 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)18 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 CartProduct (BasicCommonClasses.CartProduct)2 CatalogProduct (BasicCommonClasses.CatalogProduct)2 AuthenticationError (CustomerContracts.ACustomerExceptions.AuthenticationError)2 ForgotPasswordWrongAnswer (CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer)2