QuantityRules { @SuppressWarnings("checkstyle:indentation") public Map<String, SuggestedQuantityDTO> getSuggestedQuantities(List<Pool> pools, Consumer c, Date date) { JsonJsContext args = new JsonJsContext(mapper); Stream<PoolDTO> poolStream = pools == null ? Stream.empty() : pools.stream().map(this.translator.getStreamMapper(Pool.class, PoolDTO.class)); Stream<EntitlementDTO> entStream = c.getEntitlements() == null ? Stream.empty() : c.getEntitlements().stream() .filter(ent -> ent.isValidOnDate(date)) .map(this.translator.getStreamMapper(Entitlement.class, EntitlementDTO.class)); Stream<GuestIdDTO> guestIdStream = c.getGuestIds() == null ? Stream.empty() : c.getGuestIds().stream() .map(this.translator.getStreamMapper(GuestId.class, GuestIdDTO.class)); args.put("pools", poolStream); args.put("consumer", this.translator.translate(c, ConsumerDTO.class)); args.put("validEntitlements", entStream); args.put("log", log, false); args.put("guestIds", guestIdStream); String json = jsRules.runJsFunction(String.class, "get_suggested_quantities", args); Map<String, SuggestedQuantityDTO> resultMap; TypeReference<Map<String, SuggestedQuantityDTO>> typeref = new TypeReference<Map<String, SuggestedQuantityDTO>>() {}; try { resultMap = mapper.toObject(json, typeref); } catch (Exception e) { throw new RuleExecutionException(e); } return resultMap; } @Inject  QuantityRules(JsRunner jsRules, RulesObjectMapper mapper, ModelTranslator translator); @SuppressWarnings("checkstyle:indentation") SuggestedQuantityDTO getSuggestedQuantity(Pool p, Consumer c, Date date); @SuppressWarnings("checkstyle:indentation") Map<String, SuggestedQuantityDTO> getSuggestedQuantities(List<Pool> pools, Consumer c, Date date);  }
@Test public void testNonMultiEntitlementPoolMultiPool() { pool.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "no"); List<Pool> pools = new LinkedList<>(); pools.add(pool); Map<String, SuggestedQuantityDTO> results = quantityRules.getSuggestedQuantities( pools, TestUtil.createConsumer(), new Date()); assertTrue(results.containsKey(pool.getId())); SuggestedQuantityDTO suggested = results.get(pool.getId()); assertEquals(new Long(1), suggested.getSuggested()); }