SystemPurposeComplianceRules { public SystemPurposeComplianceStatus getStatus(Consumer consumer, Collection<Entitlement> existingEntitlements, Collection<Entitlement> newEntitlements, boolean updateConsumer) { return getStatus(consumer, existingEntitlements, newEntitlements, null, updateConsumer); } @Inject  SystemPurposeComplianceRules(EventSink eventSink, ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator, I18n i18n); SystemPurposeComplianceStatus getStatus(Consumer consumer,
        Collection<Entitlement> existingEntitlements, Collection<Entitlement> newEntitlements,
        boolean updateConsumer); @SuppressWarnings({"checkstyle:indentation", "checkstyle:methodlength"}) SystemPurposeComplianceStatus getStatus(Consumer consumer,
        Collection<Entitlement> existingEntitlements, Collection<Entitlement> newEntitlements,
        Date date, boolean updateConsumer); void applyStatus(Consumer c, SystemPurposeComplianceStatus status, boolean updateConsumer);  }
@Test public void testConsumerRoleIsCompliantCaseInsensitively() { Consumer consumer = mockConsumer(); consumer.setRole("mY_rOlE"); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ROLES, "my_role"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertNull(status.getNonCompliantRole()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerAddonIsCompliantCaseInsensitively() { Consumer consumer = mockConsumer(); Set<String> addons = new HashSet<>(); addons.add("mY_aDDoN"); consumer.setAddOns(addons); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ADDONS, "my_addon"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertEquals(0, status.getNonCompliantAddOns().size()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerUsageIsCompliantCaseInsensitively() { Consumer consumer = mockConsumer(); consumer.setUsage("mY_uSaGe"); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.USAGE, "my_usage"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertNull(status.getNonCompliantUsage()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerSLAIsCompliantCaseInsensitively() { Consumer consumer = mockConsumer(); consumer.setServiceLevel("mY_sLA"); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "my_sla"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertNull(status.getNonCompliantSLA()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerRoleIsCompliantAgainstPoolRoleWithTrailingSpaces() { Consumer consumer = mockConsumer(); consumer.setRole("mY_rOlE"); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ROLES, " my_role "); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertNull(status.getNonCompliantRole()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerAddonIsCompliantAgainstPoolAddonWithTrailingSpaces() { Consumer consumer = mockConsumer(); Set<String> addons = new HashSet<>(); addons.add("mY_aDDoN"); consumer.setAddOns(addons); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ADDONS, " random_addon , my_addon , another_addon "); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertEquals(0, status.getNonCompliantAddOns().size()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerRoleWithTrailingWhitespaceIsCompliant() { Consumer consumer = mockConsumer(); consumer.setRole(" mY_rOlE "); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ROLES, "my_role"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertNull(status.getNonCompliantRole()); assertEquals(0, status.getReasons().size()); }
@Test public void testConsumerAddonWithTrailingWhitespaceIsCompliant() { Consumer consumer = mockConsumer(); Set<String> addons = new HashSet<>(); addons.add(" mY_aDDoN "); consumer.setAddOns(addons); Product prod1 = new Product(); prod1.setAttribute(Product.Attributes.ADDONS, "random_addon,my_addon,another_addon"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(consumer, TestUtil.createProduct("Awesome Product"), prod1)); SystemPurposeComplianceStatus status = complianceRules.getStatus(consumer, ents, null, false); assertTrue(status.isCompliant()); assertEquals(0, status.getNonCompliantAddOns().size()); assertEquals(0, status.getReasons().size()); }