ProductCartService extends WebService { @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (propagation=Propagation.REQUIRED) public void addProductToCart(String uuid, Long p_id) throws UserNotExistingException, ProductNotExistingException { Product product = productDao.read (p_id); if (product == null) { throw new ProductNotExistingException(); } String key = "{" + uuid.toString () + "-" + p_id.toString () + "}"; synchronized (BlockingObject.getBlockingObject (key)) { ProductCart cart = getCartOfUser (uuid); if (cart == null) cart = createCartOfUser (uuid); if (cart.getProducts () == null) { cart.setProducts (new HashSet<Product> ()); } cart.getProducts ().add (product); productCartDao.update (cart); } }  @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=false, propagation=Propagation.REQUIRED) ProductCart createCartOfUser(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=false, propagation=Propagation.REQUIRED) void deleteCartOfUser(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=true, propagation=Propagation.REQUIRED) ProductCart getCartOfUser(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (propagation=Propagation.REQUIRED) void addProductToCart(String uuid, Long p_id); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (propagation=Propagation.REQUIRED) void removeProductFromCart(String uuid, Long p_id); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (propagation=Propagation.REQUIRED) List<Long> getProductsIdOfCart(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=true, propagation=Propagation.REQUIRED) List<Product> getProductsOfCart(String uuid, int skip, int top); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=true, propagation=Propagation.REQUIRED) int countProductsInCart(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (readOnly=true, propagation=Propagation.REQUIRED) boolean hasProducts(String uuid); @PreAuthorize ("hasRole('ROLE_DOWNLOAD')") @Transactional (propagation=Propagation.REQUIRED) void clearCart(String uuid);  }
@Test (priority=10) public void addProductToCart() throws MalformedURLException { User u = new User(); u.setUsername ("TMPUSER##1"); u.setPassword ("TMPPASS##1"); u = userDao.create(u); Product p = new Product(); p.setPath(new URL("file: p = productDao.create(p); try { pcs.addProductToCart(u.getUUID (), p.getId()); } catch (Exception e) { Assert.fail("Error while adding a product into a product cart.", e); } }