use of SQLDatabase.SQLDatabaseException.ProductStillForSale in project SmartCity-Market by TechnionYP5777.
the class RemoveProductFromCatalogTest method removeCatalogProductInvalidParamTest.
@Test
public void removeCatalogProductInvalidParamTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(-1, null);
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductStillForSale e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductStillForSale in project SmartCity-Market by TechnionYP5777.
the class RemoveProductFromCatalogTest method removeCatalogProductStillForSaleTest.
@Test
public void removeCatalogProductStillForSaleTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(1, null);
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductStillForSale()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
fail();
} catch (ProductStillForSale e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_STILL_FOR_SALE, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductStillForSale in project SmartCity-Market by TechnionYP5777.
the class RemoveProductFromCatalogTest method removeCatalogProductClientNotConnectedTest.
@Test
public void removeCatalogProductClientNotConnectedTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(1, null);
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
} catch (CriticalError | ProductNotExistInCatalog | ProductStillForSale e) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductStillForSale 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.ProductStillForSale in project SmartCity-Market by TechnionYP5777.
the class RemoveProductFromCatalogTest method removeCatalogProductNotExistInCatalogTest.
@Test
public void removeCatalogProductNotExistInCatalogTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(1, null);
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
} catch (CriticalError | ClientNotConnected | ProductStillForSale e) {
fail();
} catch (ProductNotExistInCatalog e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Aggregations