ActiveEntitlementJob implements AsyncJob { @Override public void execute(JobExecutionContext context) throws JobExecutionException { List<String> ids = consumerCurator.getConsumerIdsWithStartedEnts(); if (ids != null && !ids.isEmpty()) { for (String id : ids) { Consumer c = consumerCurator.get(id); complianceRules.getStatus(c); systemPurposeComplianceRules.getStatus(c, c.getEntitlements(), null, true); } context.setJobResult("Entitlement status updated for consumers: %s", ids); } else { context.setJobResult("No consumers with entitlements pending activation found"); } } @Inject  ActiveEntitlementJob(ConsumerCurator consumerCurator, ComplianceRules complianceRules,
        SystemPurposeComplianceRules systemPurposeComplianceRules); @Override void execute(JobExecutionContext context); static final String JOB_KEY; static final String JOB_NAME; static final String DEFAULT_SCHEDULE; }
@Test public void testActiveEntitlementJobNoChange() throws JobExecutionException { Pool p = createPool(owner, prod, 5L, Util.yesterday(), Util.tomorrow()); Entitlement ent = this .createEntitlement(owner, consumer, p, createEntitlementCertificate("entkey", "ecert")); ent.setUpdatedOnStart(true); entitlementCurator.create(ent); JobExecutionContext context = mock(JobExecutionContext.class); job.execute(context); assertTrue(entitlementCurator.get(ent.getId()).isUpdatedOnStart()); }
@Test public void testActiveEntitlementJobStillInactive() throws JobExecutionException { Pool p = createPool(owner, prod, 5L, Util.tomorrow(), Util.addDaysToDt(10)); Entitlement ent = this .createEntitlement(owner, consumer, p, createEntitlementCertificate("entkey", "ecert")); ent.setUpdatedOnStart(false); entitlementCurator.create(ent); consumerCurator.refresh(consumer); assertNotEquals("valid", consumer.getEntitlementStatus()); JobExecutionContext context = mock(JobExecutionContext.class); job.execute(context); consumerCurator.refresh(consumer); assertNotEquals("valid", consumer.getEntitlementStatus()); assertFalse(entitlementCurator.get(ent.getId()).isUpdatedOnStart()); }