ComplianceRules { public ComplianceStatus getStatus(Consumer c) { return getStatus(c, null, false); } @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 additivePropertiesCanStillDeserialize() { JsRunner mockRunner = mock(JsRunner.class); compliance = new ComplianceRules(mockRunner, entCurator, new StatusReasonMessageGenerator(i18n), eventSink, consumerCurator, consumerTypeCurator, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator); when(mockRunner.runJsFunction(any(Class.class), eq("get_status"), any(JsContext.class))).thenReturn("{\"unknown\": \"thing\"}"); Consumer c = mockConsumerWithTwoProductsAndNoEntitlements(); compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); }
@Test public void noEntitlements() { Consumer c = mockConsumerWithTwoProductsAndNoEntitlements(); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(2, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); }
@Test public void entitledProducts() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getNonCompliantProducts().size()); assertTrue(status.getNonCompliantProducts().contains(PRODUCT_2.getId())); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(0, status.getPartiallyCompliantProducts().size()); }
@Test public void fullyEntitled() { Consumer c = mockFullyEntitledConsumer(); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(0, status.getPartiallyCompliantProducts().size()); }
@Test public void testArchitectureMismatch() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("uname.machine", "x86_64"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_2)); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getCompliantProducts().size()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals("partial", status.getStatus()); }
@Test public void testMultiArchitectureMatch() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("uname.machine", "x86_64"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64,x86_64"); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_2)); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals("valid", status.getStatus()); }
@Test public void regularEntButLackingSocketCoverage() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); ents.get(0).setQuantity(1000); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(0, status.getPartialStacks().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void regularEntsOneLackingSocketCoverage() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "10"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(0, status.getPartialStacks().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void regularEntsBothLackingSocketCoverage() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "6"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(0, status.getPartialStacks().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void regularEntPlusPartialStack() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(1, status.getPartialStacks().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartialStacks().keySet().contains(STACK_ID_1)); }
@Test public void regularEntPlusArchMismatchStack() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("uname.machine", "x86_64"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); ents.get(2).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(3).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); ents.get(4).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(1, status.getPartialStacks().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals("partial", status.getStatus()); }
@Test public void testComplianceCountsZeroPoolSocketsAsNotSet() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "0"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(0, status.getPartialStacks().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void testComplianceCountsUndefinedPoolSocketsAsInfinite() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(0, status.getPartialStacks().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void compliantStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void testArchMismatchStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("uname.machine", "x86_64"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); ents.get(2).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(3).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getCompliantProducts().size()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getPartiallyCompliantProducts().size()); assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_2.getId()).size()); assertEquals(1, status.getPartialStacks().size()); assertTrue(status.getPartialStacks().keySet().contains(STACK_ID_1)); assertEquals("partial", status.getStatus()); }
@Test public void partiallyCompliantStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(2, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(3, status.getPartiallyCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(3, status.getPartiallyCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void overCompliantStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(8, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(8, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void notInstalledButPartiallyStacked() { Consumer c = mockConsumer(); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getPartialStacks().size()); assertTrue(status.getPartialStacks().keySet().contains(STACK_ID_1)); assertEquals("partial", status.getStatus()); }
@Test public void partialStackProvidingDiffProducts() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2, PRODUCT_3); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_3)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(3, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(2, status.getPartiallyCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(1, status.getPartiallyCompliantProducts().get(PRODUCT_2.getId()).size()); assertEquals(1, status.getPartiallyCompliantProducts().get(PRODUCT_3.getId()).size()); assertEquals(1, status.getPartialStacks().size()); }
@Test public void fullStackProvidingDiffProducts() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2, PRODUCT_3); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_3)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_2)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(3, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(2, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(3, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(1, status.getCompliantProducts().get(PRODUCT_3.getId()).size()); assertEquals(0, status.getPartialStacks().size()); }
@Test public void partialStackAndFullStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement( c, STACK_ID_2, TestUtil.createProduct("Awesome Product 2"), PRODUCT_1 )); ents.add(mockStackedEntitlement( c, STACK_ID_2, TestUtil.createProduct("Awesome Product 2"), PRODUCT_1 )); ents.add(mockStackedEntitlement( c, STACK_ID_2, TestUtil.createProduct("Awesome Product 2"), PRODUCT_1 )); ents.add(mockStackedEntitlement( c, STACK_ID_2, TestUtil.createProduct("Awesome Product 2"), PRODUCT_1 )); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(1, status.getPartialStacks().size()); }
@Test public void compliantUntilDateIsNullWhenNoInstalledProductsAndNoEntitlements() { Consumer consumer = mockConsumer(); ComplianceStatus status = compliance.getStatus(consumer, new Date()); assertNull(status.getCompliantUntil()); }
@Test public void compliantUntilDateIsOnDateWhenInstalledProductsButNoEntitlements() { Consumer consumer = mockConsumer(TestUtil.createProduct("Only One Installed Prod")); Date expectedOnDate = TestUtil.createDate(9999, 4, 12); ComplianceStatus status = compliance.getStatus(consumer, expectedOnDate); assertNull(status.getCompliantUntil()); }
@Test public void compliantUntilDateIsDateOfFirstEntitlementToExpireCausingNonCompliant() { Consumer consumer = mockConsumer(PRODUCT_1, PRODUCT_2); Date start = TestUtil.createDate(2005, 6, 12); Entitlement ent1 = mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 For Short Period"), start, TestUtil.createDate(2005, 6, 22), PRODUCT_1 ); Entitlement ent2 = mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 past Ent3"), TestUtil.createDate(2005, 6, 20), TestUtil.createDate(2005, 7, 28), PRODUCT_1 ); Entitlement ent3 = mockEntitlement( consumer, TestUtil.createProduct("Provides Product 2 Past Ent1"), start, TestUtil.createDate(2005, 7, 18), PRODUCT_2 ); mockEntCurator(consumer, Arrays.asList(ent1, ent2, ent3)); Date statusDate = TestUtil.createDate(2005, 6, 14); Date expectedDate = addSecond(ent3.getEndDate()); ComplianceStatus status = compliance.getStatus(consumer, statusDate); assertEquals(expectedDate, status.getCompliantUntil()); }
@Test public void compliantUntilDateUsesFutureEntitlements() { Consumer consumer = mockConsumer(PRODUCT_1, PRODUCT_2); Date start = TestUtil.createDate(2005, 6, 12); List<Entitlement> ents = new LinkedList<>(); int iterations = 5; int interval = 1000; for (int i = 0; i < interval * iterations; i += interval) { ents.add(mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 For Short Period"), new Date(start.getTime() + i), new Date(start.getTime() + i + interval), PRODUCT_1 )); ents.add(mockEntitlement( consumer, TestUtil.createProduct("Provides Product 2 For Short Period"), new Date(start.getTime() + i), new Date(start.getTime() + i + interval), PRODUCT_2 )); } mockEntCurator(consumer, ents); Date expectedDate = addSecond(new Date(start.getTime() + interval * (iterations - 1) + interval)); ComplianceStatus status = compliance.getStatus(consumer, start); assertEquals("valid", status.getStatus()); assertEquals(expectedDate, status.getCompliantUntil()); }
@Test public void compliantUntilReturnsNullIfNoProductsInstalled() { Consumer consumer = mockConsumer(); Date start = TestUtil.createDate(2005, 6, 12); List<Entitlement> ents = new LinkedList<>(); int iterations = 5; int interval = 1000; for (int i = 0; i < interval * iterations; i += interval) { ents.add(mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 For Short Period"), new Date(start.getTime() + i), new Date(start.getTime() + i + interval), PRODUCT_1 )); ents.add(mockEntitlement( consumer, TestUtil.createProduct("Provides Product 2 For Short Period"), new Date(start.getTime() + i), new Date(start.getTime() + i + interval), PRODUCT_2 )); } mockEntCurator(consumer, ents); Date expectedDate = null; ComplianceStatus status = compliance.getStatus(consumer, start); assertEquals("valid", status.getStatus()); assertEquals(expectedDate, status.getCompliantUntil()); }
@Test public void compliantUntilDateIsOnDateWhenPartialStack() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); mockEntCurator(c, ents); Date expectedOnDate = TestUtil.createDate(2011, 8, 30); ComplianceStatus status = compliance.getStatus(c, expectedOnDate); assertEquals(1, status.getPartialStacks().size()); assertNull(status.getCompliantUntil()); }
@Test public void expiredEntitlementIsIgnoredWhenCalculatingCompliantUntilDate() { Consumer consumer = mockConsumer(PRODUCT_1); Date start = TestUtil.createDate(2005, 6, 12); Entitlement expired = mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 past Ent3"), TestUtil.createDate(2005, 5, 20), TestUtil.createDate(2005, 6, 2), PRODUCT_1 ); Entitlement ent = mockEntitlement( consumer, TestUtil.createProduct("Provides Product 1 For Short Period"), start, TestUtil.createDate(2005, 6, 22), PRODUCT_1 ); mockEntCurator(consumer, Arrays.asList(expired, ent)); Date expectedDate = addSecond(ent.getEndDate()); ComplianceStatus status = compliance.getStatus(consumer, start); assertEquals(expectedDate, status.getCompliantUntil()); }
@Test public void statusGreenWhenConsumerHasNoInstalledProducts() { Consumer c = mockConsumer(); List<Entitlement> ents = new LinkedList<>(); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void statusGreenWhenFullyEntitled() { Consumer c = mockFullyEntitledConsumer(); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void statusYellowWhenNoNonCompliantAndHasPartiallyCoveredProducts() { Consumer c = mockConsumer(PRODUCT_1); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void statusRedWhenNonCompliantProductOnly() { Consumer c = mockConsumerWithTwoProductsAndNoEntitlements(); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.RED, status.getStatus()); }
@Test public void statusRedWhenNonCompliantProductAndCompliantProduct() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getCompliantProducts().size()); assertEquals(1, status.getNonCompliantProducts().size()); assertEquals(ComplianceStatus.RED, status.getStatus()); }
@Test public void statusRedWhenNonCompliantProductAndPartialProduct() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getNonCompliantProducts().size()); assertEquals(ComplianceStatus.RED, status.getStatus()); }
@Test public void statusRedOneWhenNonCompliantProductAndCompliantAndPartial() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2, PRODUCT_3); 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)); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertEquals(1, status.getNonCompliantProducts().size()); assertEquals(ComplianceStatus.RED, status.getStatus()); }
@Test public void entPartialStackNoProductsInstalled() { Consumer c = mockConsumer(); c.setFact("uname.machine", "x86_64"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); ents.get(2).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64"); ents.get(3).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(1, status.getPartialStacks().size()); assertTrue(status.getPartialStacks().keySet().contains(STACK_ID_1)); assertEquals("partial", status.getStatus()); }
@Test public void productCoveredWhenSingleEntitlementCoversCores() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.core(s)_per_socket", "4"); Entitlement ent = mockEntitlement(c, PRODUCT_1); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); mockEntCurator(c, Arrays.asList(ent)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void productPartiallyCoveredWhenSingleEntitlementDoesNotCoverAllCores() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent = mockEntitlement(c, PRODUCT_1); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "4"); mockEntCurator(c, Arrays.asList(ent)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void productCoveredWhenStackedEntsCoverCores() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void productPartiallyCoveredWhenStackingEntsDoesNotCoverCores() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.CORES, "4"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "1"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(0, status.getCompliantProducts().size()); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void productCoveredWhenStackedEntitlementCoversBothSocketsAndCores() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.cpu_socket(s)", "4"); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); ent1.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); mockEntCurator(c, Arrays.asList(ent1)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void productCoveredWhenTwoStackedEntsCoversBothSocketsAndCores() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.cpu_socket(s)", "4"); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.CORES, "24"); ent1.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "2"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "8"); ent2.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "2"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void productCoveredWhenTwoStackedEntsCoverBothSocketsAndCoresSeperately() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.cpu_socket(s)", "4"); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(ComplianceStatus.GREEN, status.getStatus()); }
@Test public void productPartiallyCoveredWhenTwoStackedEntsCoverOnlyCores() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.cpu_socket(s)", "4"); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "2"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "8"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(0, status.getCompliantProducts().size()); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void productPartiallyCoveredWhenStackedEntsCoverSocketsOnly() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("cpu.cpu_socket(s)", "4"); c.setFact("cpu.core(s)_per_socket", "8"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.CORES, "4"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(0, status.getCompliantProducts().size()); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void productCoveredWhenStackedEntsCoverRam() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("memory.memtotal", "8000000"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.RAM, "4"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.RAM, "4"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_3.getId())); }
@Test public void productPartiallyCoveredWhenStackingEntsDoesNotCoverRam() { Consumer c = mockConsumer(PRODUCT_3); c.setFact("memory.memtotal", "8000000"); Entitlement ent1 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_1, PRODUCT_3); ent1.getPool().getProduct().setAttribute(Product.Attributes.RAM, "4"); Entitlement ent2 = mockBaseStackedEntitlement(c, STACK_ID_1, PRODUCT_2, PRODUCT_3); ent2.getPool().getProduct().setAttribute(Product.Attributes.RAM, "1"); mockEntCurator(c, Arrays.asList(ent1, ent2)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_3.getId())); assertEquals(0, status.getCompliantProducts().size()); }
@Test public void instanceBasedPhysicalGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).setQuantity(8); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void singleSocketInstanceBasedPhysicalGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("cpu.cpu_socket(s)", "1"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "1"); ents.get(0).setQuantity(2); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void instanceBasedPhysicalStackedGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).setQuantity(6); ents.get(1).setQuantity(2); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void instanceBasedPhysicalYellow() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); List<Entitlement> ents = new LinkedList<>(); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).setQuantity(7); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(2, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(1, status.getReasons().size()); ComplianceReason reason = status.getReasons().iterator().next(); assertEquals("SOCKETS", reason.getKey()); assertEquals("6", reason.getAttributes().get("covered")); }
@Test public void instanceBasedVirtualGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("virt.is_guest", "true"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).setQuantity(1); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void hostRestrictedVirtualGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("virt.is_guest", "true"); c.setFact("cpu.core(s)_per_socket", "20"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockHostRestrictedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.get(0).setQuantity(1); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void hostNonStackedRestrictedVirtualGreen() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("virt.is_guest", "true"); c.setFact("cpu.core(s)_per_socket", "20"); List<Entitlement> ents = new LinkedList<>(); ents.add(mockNonStackedHostRestrictedEntitlement( c, "Awesome Product", PRODUCT_1, PRODUCT_2 )); ents.get(0).setQuantity(1); ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.VCPU, "1"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.GREEN, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); }
@Test public void virtLimitSingleEntitlementCovered() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.core(s)_per_socket", "4"); for (int i = 0; i < 5; i++) { c.addGuestId(new GuestId("" + i, c, activeGuestAttrs)); } Entitlement ent = mockEntitlement(c, PRODUCT_1); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "8"); mockEntCurator(c, Arrays.asList(ent)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); }
@Test public void virtLimitSingleEntitlementPartial() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("cpu.core(s)_per_socket", "4"); for (int i = 0; i < 5; i++) { c.addGuestId(new GuestId("" + i, c, activeGuestAttrs)); } Entitlement ent = mockEntitlement(c, PRODUCT_1); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "32"); ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4"); mockEntCurator(c, Arrays.asList(ent)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@Test public void partiallyCompliantVirtLimitStack() { 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<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4"); } mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertEquals(2, status.getPartiallyCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantVirtLimitStackWithInactiveGuests() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); for (int i = 0; i < 5; i++) { c.addGuestId(new GuestId("" + i, c)); } List<Entitlement> ents = new LinkedList<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4"); } mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantVirtLimitStack() { 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<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "8"); } mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantVirtLimitStackVaryingLimits() { 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<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "1"); } ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "5"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantVirtLimitStackWithUnlimited() { 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<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "1"); } ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1"); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantVirtLimitStackAllUnlimited() { 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<>(); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2)); for (Entitlement ent : ents) { ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1"); } mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void fullyCompliantOverriddenVirtLimit() { 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 = mockEntitlement( c, TestUtil.createProduct("Awesome OS server"), PRODUCT_1, PRODUCT_2 ); mockServerEntitlement.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4"); ents.add(mockServerEntitlement); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals("partial", status.getStatus()); assertEquals(2, status.getPartiallyCompliantProducts().size()); 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); mockEntCurator(c, ents); status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(2, status.getCompliantProducts().get(PRODUCT_1.getId()).size()); assertEquals(2, status.getCompliantProducts().get(PRODUCT_2.getId()).size()); }
@Test public void virtualSingleEntOnlyUsesVcpuAndRam() { Consumer c = mockConsumer(PRODUCT_1); c.setFact("virt.is_guest", "true"); c.setFact("cpu.core(s)_per_socket", "8"); c.setFact("cpu.cpu_socket(s)", "10"); c.setFact("memory.memtotal", "8000000"); List<Entitlement> ents = new LinkedList<>(); Entitlement ent = mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.RAM, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.VCPU, "1"); ents.add(ent); ents.get(0).setQuantity(1); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(1, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(2, status.getReasons().size()); List<String> reasonKeys = new LinkedList<>(); for (ComplianceReason r : status.getReasons()) { reasonKeys.add(r.getKey()); } assertTrue(reasonKeys.contains("RAM")); assertTrue(reasonKeys.contains("VCPU")); }
@Test public void virtualStackedOnlyUsesVcpuAndRam() { Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2); c.setFact("virt.is_guest", "true"); c.setFact("cpu.core(s)_per_socket", "8"); c.setFact("cpu.cpu_socket(s)", "10"); c.setFact("memory.memtotal", "8000000"); List<Entitlement> ents = new LinkedList<>(); Entitlement ent = mockBaseStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2); ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.RAM, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "1"); ent.getPool().getProduct().setAttribute(Product.Attributes.VCPU, "1"); ents.add(ent); ents.get(0).setQuantity(1); mockEntCurator(c, ents); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(2, status.getPartiallyCompliantProducts().size()); assertEquals(0, status.getCompliantProducts().size()); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId())); assertEquals(2, status.getReasons().size()); List<String> reasonKeys = new LinkedList<>(); for (ComplianceReason r : status.getReasons()) { reasonKeys.add(r.getKey()); } assertTrue(reasonKeys.contains("RAM")); assertTrue(reasonKeys.contains("VCPU")); }
@Test public void ensureConsumerEntitlementStatusIsUpdatedWhenChanged() { Consumer c = mockFullyEntitledConsumer(); ComplianceStatus originalStatus = compliance.getStatus(c); assertEquals("valid", originalStatus.getStatus()); verify(consumerCurator).update(eq(c), eq(false)); String pid = "testinstalledprod"; c.addInstalledProduct(new ConsumerInstalledProduct(pid, pid)); ComplianceStatus updated = compliance.getStatus(c); assertNotEquals(originalStatus.getStatus(), updated.getStatus()); assertEquals(c.getEntitlementStatus(), updated.getStatus()); }
@Test public void unmappedGuestEntitlementYellow() { Consumer c = mockConsumer(PRODUCT_1); Entitlement ent = mockEntitlement(c, PRODUCT_1); ent.getPool().setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true"); ent.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "true"); ent.getPool().setAttribute(Pool.Attributes.DERIVED_POOL, "true"); mockEntCurator(c, Arrays.asList(ent)); ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30)); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId())); assertEquals(1, status.getReasons().size()); assertEquals(ComplianceStatus.YELLOW, status.getStatus()); }
@SuppressWarnings("checkstyle:localvariablename") @Test public void testRoleMismatchShouldNotAffectEntitlementComplianceStatus() { Product engineeringProduct = new Product(); engineeringProduct.setId("compliant-69"); Consumer myconsumer = mockConsumer(engineeringProduct); myconsumer.setRole("my_role"); List<Entitlement> ents = new LinkedList<>(); Product marketingProduct = TestUtil.createProduct("Awesome Product"); marketingProduct.setAttribute(Product.Attributes.ROLES, "provided_role"); ents.add(mockEntitlement(myconsumer, marketingProduct, engineeringProduct)); mockEntCurator(myconsumer, ents); ComplianceStatus status = compliance.getStatus(myconsumer, TestUtil.createDate(2011, 8, 30)); assertEquals(status.getStatus(), "valid"); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(engineeringProduct.getId())); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); }
@SuppressWarnings("checkstyle:localvariablename") @Test public void testAddonMismatchShouldNotAffectEntitlementComplianceStatus() { Product engineeringProduct = new Product(); engineeringProduct.setId("compliant-69"); Consumer myconsumer = mockConsumer(engineeringProduct); Set<String> addons = new HashSet<>(); addons.add("my_addon"); myconsumer.setAddOns(addons); List<Entitlement> ents = new LinkedList<>(); Product marketingProduct = TestUtil.createProduct("Awesome Product"); marketingProduct.setAttribute(Product.Attributes.ADDONS, "provided_addon"); ents.add(mockEntitlement(myconsumer, marketingProduct, engineeringProduct)); mockEntCurator(myconsumer, ents); ComplianceStatus status = compliance.getStatus(myconsumer, TestUtil.createDate(2011, 8, 30)); assertEquals(status.getStatus(), "valid"); assertEquals(1, status.getCompliantProducts().size()); assertTrue(status.getCompliantProducts().keySet().contains(engineeringProduct.getId())); assertEquals(0, status.getNonCompliantProducts().size()); assertEquals(0, status.getPartiallyCompliantProducts().size()); }