@Test public void testParseGroovyConditionFalse() throws Exception { final ShoppingCart cart = mockery.mock(ShoppingCart.class, "cart"); final ShoppingContext cartCtx = mockery.mock(ShoppingContext.class, "cartCtx"); mockery.checking(new Expectations() {{ allowing(cart).getShoppingContext(); will(returnValue(cartCtx)); allowing(cartCtx).getShopId(); will(returnValue(10L)); allowing(cartCtx).getCustomerShopId(); will(returnValue(1010L)); }}); final GroovyPromotionConditionParser parser = new GroovyPromotionConditionParser(); final Class cl = parser.parseGroovyCondition(1L, "ABC#", "shoppingCart != null; return false"); assertEquals("PromotionABC_", cl.getSimpleName()); final PromotionCondition condition = ((PromotionCondition) cl.newInstance()); assertEquals(1L, condition.getPromotionId()); assertEquals("ABC#", condition.getPromotionCode()); final boolean result = condition.isEligible(new HashMap<String, Object>() {{ put("shoppingCart", cart); }}); assertFalse(result); }
Class parseGroovyCondition(final long promoId, final String promoCode, final String condition) { final StringBuilder script = new StringBuilder(); appendImports(script); appendStartClass(script, promoId, promoCode); appendBody(script, condition); appendEndClass(script); LOG.debug("Creating promotion condition class {}\n{}", promoCode, script); return gcl.parseClass(script.toString()); }
GroovyPromotionConditionParser implements PromotionConditionParser { Class parseGroovyCondition(final long promoId, final String promoCode, final String condition) { final StringBuilder script = new StringBuilder(); appendImports(script); appendStartClass(script, promoId, promoCode); appendBody(script, condition); appendEndClass(script); LOG.debug("Creating promotion condition class {}\n{}", promoCode, script); return gcl.parseClass(script.toString()); } }
GroovyPromotionConditionParser implements PromotionConditionParser { Class parseGroovyCondition(final long promoId, final String promoCode, final String condition) { final StringBuilder script = new StringBuilder(); appendImports(script); appendStartClass(script, promoId, promoCode); appendBody(script, condition); appendEndClass(script); LOG.debug("Creating promotion condition class {}\n{}", promoCode, script); return gcl.parseClass(script.toString()); }  }
GroovyPromotionConditionParser implements PromotionConditionParser { Class parseGroovyCondition(final long promoId, final String promoCode, final String condition) { final StringBuilder script = new StringBuilder(); appendImports(script); appendStartClass(script, promoId, promoCode); appendBody(script, condition); appendEndClass(script); LOG.debug("Creating promotion condition class {}\n{}", promoCode, script); return gcl.parseClass(script.toString()); }  @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") PromotionCondition parse(final Promotion promotion); }
GroovyPromotionConditionParser implements PromotionConditionParser { Class parseGroovyCondition(final long promoId, final String promoCode, final String condition) { final StringBuilder script = new StringBuilder(); appendImports(script); appendStartClass(script, promoId, promoCode); appendBody(script, condition); appendEndClass(script); LOG.debug("Creating promotion condition class {}\n{}", promoCode, script); return gcl.parseClass(script.toString()); }  @Override @Cacheable(value = "promotionService-groovyCache", key = "#promotion.promotionId") PromotionCondition parse(final Promotion promotion);  }