use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartLogoutReturnsProductsToShelves.
@Test
public void testCartLogoutReturnsProductsToShelves() {
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(session, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientClientNotConnectedTest.
@Test
public void addNewIngredientClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenThrow(new ClientNotConnected());
} catch (CriticalError e) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientSuccessfulTest.
@Test
public void addNewIngredientSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenReturn("0");
} catch (CriticalError | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientCriticalErrorTest.
@Test
public void addNewIngredientCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenThrow(new CriticalError());
} catch (ClientNotConnected e) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientNotConnected in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductCriticalErrorTest.
@Test
public void addCatalogProductCriticalErrorTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | ClientNotConnected e) {
fail();
} catch (CriticalError __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Aggregations