ComplianceRules { @SuppressWarnings("checkstyle:indentation") public boolean isStackCompliant(Consumer consumer, String stackId, List<Entitlement> entsToConsider) { Stream<EntitlementDTO> entStream = entsToConsider == null ? Stream.empty() : entsToConsider.stream() .map(this.translator.getStreamMapper(Entitlement.class, EntitlementDTO.class)); Stream<GuestIdDTO> guestIdStream = consumer.getGuestIds() == null ? Stream.empty() : consumer.getGuestIds().stream() .map(this.translator.getStreamMapper(GuestId.class, GuestIdDTO.class)); JsonJsContext args = new JsonJsContext(mapper); args.put("stack_id", stackId); args.put("consumer", this.translator.translate(consumer, ConsumerDTO.class)); args.put("entitlements", entStream); args.put("log", log, false); args.put("guestIds", guestIdStream); return jsRules.runJsFunction(Boolean.class, "is_stack_compliant", args); } @Inject  ComplianceRules(JsRunner jsRules, EntitlementCurator entCurator,
        StatusReasonMessageGenerator generator, EventSink eventSink, ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator, RulesObjectMapper mapper, ModelTranslator translator); ComplianceStatus getStatus(Consumer c); ComplianceStatus getStatus(Consumer c, Date date); ComplianceStatus getStatus(Consumer c, Date date, boolean calculateCompliantUntil); ComplianceStatus getStatus(Consumer c, Date date, boolean calculateCompliantUntil,
        boolean updateConsumer); @SuppressWarnings("checkstyle:indentation") ComplianceStatus getStatus(Consumer consumer, Collection<Entitlement> newEntitlements, Date date,
        boolean calculateCompliantUntil, boolean updateConsumer, boolean calculateProductComplianceDateRanges,
        boolean currentCompliance); void updateEntsOnStart(Consumer c); void applyStatus(Consumer c, ComplianceStatus status, boolean updateConsumer); @SuppressWarnings("checkstyle:indentation") boolean isStackCompliant(Consumer consumer, String stackId, List<Entitlement> entsToConsider); @SuppressWarnings("checkstyle:indentation") boolean isEntitlementCompliant(Consumer consumer, Entitlement ent, Date onDate);  }
@Test public void stackIsCompliant() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.cpu_socket(s)", "2"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); assertTrue(compliance.isStackCompliant(c, STACK_ID_1, ents)); }
@Test public void stackIsNotCompliant() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.cpu_socket(s)", "4"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockEntitlement(c, TestUtil.createProduct("Another Product"), PRODUCT_3)); assertFalse(compliance.isStackCompliant(c, STACK_ID_1, ents)); }
@Test public void isStackFullyCompliantOverriddenVirtLimit() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); for (int i = 0; i < 5; i++) { c.addGuestId(new GuestId("" + i, c, activeGuestAttrs)); } List<Entitlement> ents = new LinkedList<>(); Entitlement mockServerEntitlement = mockStackedEntitlement(c, "mockServerStack", PRODUCT_1, PRODUCT_2); mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4"); mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "2"); mockServerEntitlement.setQuantity(4); ents.add(mockServerEntitlement); Entitlement mockHypervisorEntitlement = mockEntitlement( c, TestUtil.createProduct("Awesome Enterprise Hypervisor"), PRODUCT_1, PRODUCT_2 ); mockHypervisorEntitlement.getPool() .getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1"); ents.add(mockHypervisorEntitlement); assertTrue(compliance.isStackCompliant(c, "mockServerStack", ents)); }