StatusReasonMessageGenerator { public void setMessage(Consumer c, ComplianceReason reason, Date onDate) { String marketingName, id; if (reason.isStacked()) { id = reason.getAttributes().get(ComplianceReason.Attributes.STACKING_ID); marketingName = getStackedMarketingName(id, c, onDate); reason.getAttributes().put(ComplianceReason.Attributes.MARKETING_NAME, marketingName); } else if (reason.isNonCovered()) { id = reason.getAttributes().get(ComplianceReason.Attributes.PRODUCT_ID); marketingName = getInstalledMarketingName(id, c); reason.getAttributes().put(ComplianceReason.Attributes.MARKETING_NAME, marketingName); } else { id = reason.getAttributes().get(ComplianceReason.Attributes.ENTITLEMENT_ID); marketingName = getMarketingName(id, c, onDate); reason.getAttributes().put(ComplianceReason.Attributes.MARKETING_NAME, marketingName); } String key = reason.getKey(); reason.setMessage(i18n.tr(getReasonMessage(key), key, reason.getAttributes().get(ComplianceReason.Attributes.COVERED), reason.getAttributes().get(ComplianceReason.Attributes.PRESENT) )); } @Inject  StatusReasonMessageGenerator(I18n i18n); void setMessage(Consumer c, ComplianceReason reason, Date onDate);  }
@Test public void testSocketsMessage() { ComplianceReason reason = buildReason("SOCKETS", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals("Only supports 4 of 8 sockets.", reason.getMessage()); }
@Test public void testStackedSubs() { ComplianceReason reason = buildReason("SOCKETS", buildStackedAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); String message = reason.getMessage(); assertEquals("Only supports 4 of 8 sockets.", message); String[] names = reason.getAttributes().get("name").split("/"); Arrays.sort(names); assertEquals("Stack Subscription One", names[0]); assertEquals("Stack Subscription Two", names[1]); }
@Test public void testArchMessage() { ComplianceReason reason = buildReason("ARCH", buildGeneralAttributes("x86_64", "ppc64")); generator.setMessage(consumer, reason, new Date()); assertEquals( "Supports architecture ppc64 but" + " the system is x86_64.", reason.getMessage()); }
@Test public void testRamMessage() { ComplianceReason reason = buildReason("RAM", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals( "Only supports 4GB of 8GB of RAM.", reason.getMessage()); }
@Test public void testVirtLimitMessage() { ComplianceReason reason = buildReason("GUEST_LIMIT", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals( "Only supports 4 of 8 virtual guests.", reason.getMessage()); }
@Test public void testCoresMessage() { ComplianceReason reason = buildReason("CORES", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals( "Only supports 4 of 8 cores.", reason.getMessage()); }
@Test public void testVcpuMessage() { ComplianceReason reason = buildReason("VCPU", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals( "Only supports 4 of 8 vCPUs.", reason.getMessage()); }
@Test public void testDefaultMessage() { ComplianceReason reason = buildReason("NOT_A_KEY", buildGeneralAttributes("8", "4")); generator.setMessage(consumer, reason, new Date()); assertEquals("NOT_A_KEY COVERAGE PROBLEM. Supports 4 of 8", reason.getMessage()); }
@Test public void testNonInstalled() { HashMap<String, String> attrs = new HashMap<>(); attrs.put("product_id", "prod1"); ComplianceReason reason = buildReason("NOTCOVERED", attrs); Owner owner = new Owner("test"); Product product = TestUtil.createProduct("prod1", "NonCovered Product"); ConsumerInstalledProduct installed = new ConsumerInstalledProduct(product.getId(), product.getName()); consumer.addInstalledProduct(installed); generator.setMessage(consumer, reason, new Date()); assertEquals("Not supported by a valid subscription.", reason.getMessage()); }