@Test public void testACreateGift() { User consignor = _dbInjecter.injectUser("Adam"); _dbInjecter.injectTreeType("wood", "this is a wood", 0.5); _dbInjecter.injectProject("Project A", "Adam", "this is a project", true, 0, 0); _dbInjecter.injectProjectArticle("wood", "Project A", 10, 1.0, 0.5); PlantBag plantBag = plantBagBuilder.initializeProjectDataAndAddToPlantBag("Project A").createPlantItemAndAddToPlantBag(5, 5, "wood", "Project A").build(); try { _giftService.generateGift(consignor, plantBag); } catch (IpatException e) { fail("No Exception expected, when generating a gift"); } assertEquals(1, _giftRepository.count()); assertEquals(1, _codeRepository.count()); assertEquals(1, _cartRepository.count()); }
@Transactional public Long[] generateGift(User consignor, PlantBag plantBag) throws IpatException { Long[] ids = new Long[2]; _plantBagValidator.validatePlantBag(plantBag); Cart cart = plantBagToCartConverter.convertPlantPageDataToCart(plantBag, consignor, CartState.INITIAL); Gift gift = new Gift(); gift.setConsignor(consignor); gift.setStatus(Status.NEW); Code code = _codeGenerator.generate(gift); gift.setCode(code); _giftRepository.save(gift); cart.setCode(code); cart.setGift(true); cart = _cartRepository.save(cart); code.setCart(cart); _codeRepository.save(code); ids[0] = cart.getId(); ids[1] = gift.getId(); return ids; }
GiftService { @Transactional public Long[] generateGift(User consignor, PlantBag plantBag) throws IpatException { Long[] ids = new Long[2]; _plantBagValidator.validatePlantBag(plantBag); Cart cart = plantBagToCartConverter.convertPlantPageDataToCart(plantBag, consignor, CartState.INITIAL); Gift gift = new Gift(); gift.setConsignor(consignor); gift.setStatus(Status.NEW); Code code = _codeGenerator.generate(gift); gift.setCode(code); _giftRepository.save(gift); cart.setCode(code); cart.setGift(true); cart = _cartRepository.save(cart); code.setCart(cart); _codeRepository.save(code); ids[0] = cart.getId(); ids[1] = gift.getId(); return ids; } }
GiftService { @Transactional public Long[] generateGift(User consignor, PlantBag plantBag) throws IpatException { Long[] ids = new Long[2]; _plantBagValidator.validatePlantBag(plantBag); Cart cart = plantBagToCartConverter.convertPlantPageDataToCart(plantBag, consignor, CartState.INITIAL); Gift gift = new Gift(); gift.setConsignor(consignor); gift.setStatus(Status.NEW); Code code = _codeGenerator.generate(gift); gift.setCode(code); _giftRepository.save(gift); cart.setCode(code); cart.setGift(true); cart = _cartRepository.save(cart); code.setCart(cart); _codeRepository.save(code); ids[0] = cart.getId(); ids[1] = gift.getId(); return ids; }  }
GiftService { @Transactional public Long[] generateGift(User consignor, PlantBag plantBag) throws IpatException { Long[] ids = new Long[2]; _plantBagValidator.validatePlantBag(plantBag); Cart cart = plantBagToCartConverter.convertPlantPageDataToCart(plantBag, consignor, CartState.INITIAL); Gift gift = new Gift(); gift.setConsignor(consignor); gift.setStatus(Status.NEW); Code code = _codeGenerator.generate(gift); gift.setCode(code); _giftRepository.save(gift); cart.setCode(code); cart.setGift(true); cart = _cartRepository.save(cart); code.setCart(cart); _codeRepository.save(code); ids[0] = cart.getId(); ids[1] = gift.getId(); return ids; }  @Transactional Long[] generateGift(User consignor, PlantBag plantBag); @Transactional void redeemGiftCode(User recipient, String giftCode); void createGiftPdf(long giftId, HttpServletResponse response); }
GiftService { @Transactional public Long[] generateGift(User consignor, PlantBag plantBag) throws IpatException { Long[] ids = new Long[2]; _plantBagValidator.validatePlantBag(plantBag); Cart cart = plantBagToCartConverter.convertPlantPageDataToCart(plantBag, consignor, CartState.INITIAL); Gift gift = new Gift(); gift.setConsignor(consignor); gift.setStatus(Status.NEW); Code code = _codeGenerator.generate(gift); gift.setCode(code); _giftRepository.save(gift); cart.setCode(code); cart.setGift(true); cart = _cartRepository.save(cart); code.setCart(cart); _codeRepository.save(code); ids[0] = cart.getId(); ids[1] = gift.getId(); return ids; }  @Transactional Long[] generateGift(User consignor, PlantBag plantBag); @Transactional void redeemGiftCode(User recipient, String giftCode); void createGiftPdf(long giftId, HttpServletResponse response);  }