use of CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable in project SmartCity-Market by TechnionYP5777.
the class RemoveProductFromCartTest method setup.
@Before
public void setup() {
PropertyConfigurator.configure("../log4j.properties");
customer = new Customer(clientRequestHandler);
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, Serialization.serialize(pp)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK).serialize());
} catch (IOException ¢) {
fail();
}
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(sc)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct)).serialize());
} catch (IOException ¢) {
fail();
}
try {
customer.addProductToCart(sc, amount);
} catch (CriticalError | CustomerNotConnected | AmountBiggerThanAvailable | ProductPackageDoesNotExist | InvalidParameter e1) {
fail();
}
}
use of CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable in project SmartCity-Market by TechnionYP5777.
the class Customer method checkOutGroceryList.
@Override
public Double checkOutGroceryList() throws CriticalError, CustomerNotConnected, GroceryListIsEmpty {
String serverResponse;
Double $ = totalSum;
log.info("Creating CHECKOUT_GROCERY_LIST command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.CHECKOUT_GROCERY_LIST)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | AmountBiggerThanAvailable | ProductPackageDoesNotExist | AuthenticationError | ProductCatalogDoesNotExist | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* update customer data: groceryList, cartProductCache, totalSum */
groceryList = new GroceryList();
cartProductCache = new HashMap<Long, CartProduct>();
totalSum = Double.valueOf(0);
totalProductsAmount = 0;
log.info("CHECKOUT_GROCERY_LIST command succeed.");
return $;
}
use of CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable in project SmartCity-Market by TechnionYP5777.
the class Customer method login.
@Override
public void login(String username, String password, boolean updateProductPictures) throws CriticalError, AuthenticationError {
CommandWrapper cmdwrppr = null;
String serverResponse = null;
log.info("Creating login command wrapper for customer");
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(CustomerDefs.loginCommandSenderId, CommandDescriptor.LOGIN_CUSTOMER, Serialization.serialize(new Login(username, password)))).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
cmdwrppr = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(cmdwrppr.getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | CustomerNotConnected | ProductCatalogDoesNotExist | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
id = cmdwrppr.getSenderID();
if (this instanceof RegisteredCustomer)
customerProfile = Serialization.deserialize(cmdwrppr.getData(), CustomerProfile.class);
//check for new product pictures asynchronous
if (updateProductPictures)
new UpdateProductPictures().start();
log.info("Customer Login to server as succeed. Client id is: " + id);
}
use of CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable in project SmartCity-Market by TechnionYP5777.
the class Customer method viewCatalogProduct.
@Override
public CatalogProduct viewCatalogProduct(SmartCode c) throws CriticalError, CustomerNotConnected, ProductCatalogDoesNotExist {
String serverResponse;
log.info("Creating viewProductFromCatalog (in order to addPtoductToCart) command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
/* first: getting the product from the server */
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(c)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
CommandWrapper $ = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler($.getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | CriticalError | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("viewProductFromCatalog command succeed.");
return Serialization.deserialize($.getData(), CatalogProduct.class);
}
use of CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable in project SmartCity-Market by TechnionYP5777.
the class Customer method logout.
@Override
public void logout() throws CustomerNotConnected, CriticalError {
String serverResponse;
log.info("Creating customer logout command wrapper with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.LOGOUT)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
customerProfile = null;
log.info("logout from server succeed.");
}
Aggregations