@Test public void testParseCache() throws Exception { final ShoppingCart cart = mockery.mock(ShoppingCart.class, "cart"); final ShoppingContext cartCtx = mockery.mock(ShoppingContext.class, "cartCtx"); final Promotion promotion = mockery.mock(Promotion.class, "promotion"); mockery.checking(new Expectations() {{ allowing(promotion).getPromotionId(); will(returnValue(1L)); allowing(promotion).getCode(); will(returnValue("ABC#")); allowing(promotion).getEligibilityCondition(); will(returnValue("shoppingCart != null")); allowing(cart).getShoppingContext(); will(returnValue(cartCtx)); allowing(cartCtx).getShopId(); will(returnValue(10L)); allowing(cartCtx).getCustomerShopId(); will(returnValue(1010L)); }}); final GroovyPromotionConditionParser parser = new GroovyPromotionConditionParser(); final PromotionCondition condition = parser.parse(promotion); assertFalse(condition instanceof NullPromotionCondition); assertEquals("PromotionABC_", condition.getClass().getSimpleName()); assertEquals(1L, condition.getPromotionId()); assertEquals("ABC#", condition.getPromotionCode()); final boolean result = condition.isEligible(new HashMap<String, Object>() {{ put("shoppingCart", cart); }}); assertTrue(result); }
@Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") public PromotionCondition parse(final Promotion promotion) { PromotionCondition condition; try { final Class cl = parseGroovyCondition(promotion.getPromotionId(), promotion.getCode(), promotion.getEligibilityCondition()); condition = (PromotionCondition) cl.newInstance(); } catch (Exception exp) { LOG.error(Markers.alert(), "Unable to create groovy class for promo: " + promotion.getCode() + ", cause: " + exp.getMessage(), exp); condition = new NullPromotionCondition(promotion.getPromotionId(), promotion.getCode()); } return condition; }
GroovyPromotionConditionParser implements PromotionConditionParser { @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") public PromotionCondition parse(final Promotion promotion) { PromotionCondition condition; try { final Class cl = parseGroovyCondition(promotion.getPromotionId(), promotion.getCode(), promotion.getEligibilityCondition()); condition = (PromotionCondition) cl.newInstance(); } catch (Exception exp) { LOG.error(Markers.alert(), "Unable to create groovy class for promo: " + promotion.getCode() + ", cause: " + exp.getMessage(), exp); condition = new NullPromotionCondition(promotion.getPromotionId(), promotion.getCode()); } return condition; } }
GroovyPromotionConditionParser implements PromotionConditionParser { @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") public PromotionCondition parse(final Promotion promotion) { PromotionCondition condition; try { final Class cl = parseGroovyCondition(promotion.getPromotionId(), promotion.getCode(), promotion.getEligibilityCondition()); condition = (PromotionCondition) cl.newInstance(); } catch (Exception exp) { LOG.error(Markers.alert(), "Unable to create groovy class for promo: " + promotion.getCode() + ", cause: " + exp.getMessage(), exp); condition = new NullPromotionCondition(promotion.getPromotionId(), promotion.getCode()); } return condition; }  }
GroovyPromotionConditionParser implements PromotionConditionParser { @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") public PromotionCondition parse(final Promotion promotion) { PromotionCondition condition; try { final Class cl = parseGroovyCondition(promotion.getPromotionId(), promotion.getCode(), promotion.getEligibilityCondition()); condition = (PromotionCondition) cl.newInstance(); } catch (Exception exp) { LOG.error(Markers.alert(), "Unable to create groovy class for promo: " + promotion.getCode() + ", cause: " + exp.getMessage(), exp); condition = new NullPromotionCondition(promotion.getPromotionId(), promotion.getCode()); } return condition; }  @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") PromotionCondition parse(final Promotion promotion); }
GroovyPromotionConditionParser implements PromotionConditionParser { @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") public PromotionCondition parse(final Promotion promotion) { PromotionCondition condition; try { final Class cl = parseGroovyCondition(promotion.getPromotionId(), promotion.getCode(), promotion.getEligibilityCondition()); condition = (PromotionCondition) cl.newInstance(); } catch (Exception exp) { LOG.error(Markers.alert(), "Unable to create groovy class for promo: " + promotion.getCode() + ", cause: " + exp.getMessage(), exp); condition = new NullPromotionCondition(promotion.getPromotionId(), promotion.getCode()); } return condition; }  @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") PromotionCondition parse(final Promotion promotion);  }