@Test public void testBrokenCondition() throws Exception { 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("#?/*")); }}); GroovyPromotionConditionParser parser = new GroovyPromotionConditionParser(); final PromotionCondition condition = parser.parse(promotion); assertTrue(condition instanceof NullPromotionCondition); assertEquals(1L, condition.getPromotionId()); assertEquals("ABC#", condition.getPromotionCode()); final boolean result = condition.isEligible(null); assertFalse(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);  }