PromotionServiceImpl extends BaseGenericServiceImpl<Promotion> implements PromotionService { @Override public List<Promotion> getPromotionsByShopCode(final String shopCode, final String currency, final boolean active) { if (active) { final LocalDateTime now = now(); return getGenericDao().findByNamedQuery("PROMOTION.BY.SHOPCODE.CURRENCY.ACTIVE", shopCode, currency, active, now, now); } return getGenericDao().findByNamedQuery("PROMOTION.BY.SHOPCODE.CURRENCY", shopCode, currency); } PromotionServiceImpl(final GenericDAO<Promotion, Long> genericDao); @Override List<Promotion> getPromotionsByShopCode(final String shopCode, final String currency, final boolean active); @Override Promotion findPromotionByCode(final String code, final boolean active); @Override Long findPromotionIdByCode(final String code); @Override List<Promotion> findPromotions(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findPromotionCount(final Map<String, List> filter);  }
@Test public void testCrud() throws Exception { int startAll, startActive; final PromotionService promotionService = ctx().getBean("promotionService", PromotionService.class); List<Promotion> allPromotions, activePromotions; allPromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", false); assertNotNull(allPromotions); startAll = allPromotions.size(); activePromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", true); assertNotNull(activePromotions); startActive = activePromotions.size(); Promotion sku10PercentOff = promotionService.getGenericDao().getEntityFactory().getByIface(Promotion.class); sku10PercentOff.setCode("SKU10%OFF"); sku10PercentOff.setCanBeCombined(false); sku10PercentOff.setCurrency("EUR"); sku10PercentOff.setShopCode("SHOP10"); sku10PercentOff.setName("10% off SKU-001, SKU-002"); sku10PercentOff.setDescription("10% discount to purchases of SKU-001, SKU-002"); sku10PercentOff.setEligibilityCondition("['SKU-001','SKU-002'].contains(product.code)"); sku10PercentOff.setPromoType(Promotion.TYPE_ITEM); sku10PercentOff.setPromoAction(Promotion.ACTION_PERCENT_DISCOUNT); sku10PercentOff.setPromoActionContext("10"); promotionService.create(sku10PercentOff); allPromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", false); assertNotNull(allPromotions); assertEquals(startAll + 1, allPromotions.size()); activePromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", true); assertNotNull(activePromotions); assertEquals(startActive, activePromotions.size()); sku10PercentOff.setEnabled(true); sku10PercentOff = promotionService.update(sku10PercentOff); allPromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", false); assertNotNull(allPromotions); assertEquals(startAll + 1, allPromotions.size()); activePromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", true); assertNotNull(activePromotions); assertEquals(startActive + 1, activePromotions.size()); promotionService.delete(sku10PercentOff); allPromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", false); assertNotNull(allPromotions); assertEquals(startAll, allPromotions.size()); activePromotions = promotionService.getPromotionsByShopCode("SHOP10", "EUR", true); assertNotNull(activePromotions); assertEquals(startActive, activePromotions.size()); }