use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog 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();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog2.
@Test
public void testSimpleGetProductFromCatalog2() {
final long barcodeNum = 7290004685195L;
final int manufaturerID = 2;
final String manufaturerName = "מאפיות ברמן";
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
CatalogProduct product = null;
try {
product = new Gson().fromJson(sqlConnection.getProductFromCatalog(null, barcodeNum), CatalogProduct.class);
} catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
fail();
}
assertEquals(product.getBarcode(), barcodeNum);
assertEquals(product.getManufacturer().getId(), manufaturerID);
assertEquals(product.getManufacturer().getName(), manufaturerName);
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog 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();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSimpleAddRemoveProductFromCatalog.
@Test
public void testSimpleAddRemoveProductFromCatalog() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
HashSet<Location> locations = new HashSet<Location>();
CatalogProduct newProduct = new CatalogProduct(123L, "name", 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();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog 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();
}
}
Aggregations