use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class EntitlerJobTest method bindByPoolExec.
@Test
public void bindByPoolExec() throws JobExecutionException, EntitlementRefusedException {
String pool = "pool10";
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity(pool, 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
List<Entitlement> ents = new ArrayList<>();
Pool p = new Pool();
p.setId(pool);
Entitlement ent = new Entitlement();
ent.setPool(p);
ent.setQuantity(100);
ents.add(ent);
when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenReturn(ents);
EntitlerJob job = new EntitlerJob(e, null, pC, null);
injector.injectMembers(job);
job.execute(ctx);
verify(e).bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class));
verify(e).sendEvents(eq(ents));
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(ctx).setResult(argumentCaptor.capture());
List<PoolIdAndQuantity> result = (List<PoolIdAndQuantity>) argumentCaptor.getValue();
assertEquals(1, result.size());
assertEquals(pool, result.get(0).getPoolId());
assertEquals(100, result.get(0).getQuantity().intValue());
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method ensureJobFailsWhenAutobindDisabledForTargetOwner.
@Test
public void ensureJobFailsWhenAutobindDisabledForTargetOwner() throws Exception {
// Disabled autobind
when(owner.isAutobindDisabled()).thenReturn(true);
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
try {
job.execute(ctx);
fail("Expected exception due to autobind being disabled.");
} catch (JobExecutionException jee) {
assertEquals(jee.getCause().getMessage(), "Could not update host/guest mapping. Auto-attach is disabled for owner joe.");
}
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateExecCreateNoHypervisorId.
@Test
public void hypervisorUpdateExecCreateNoHypervisorId() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
hypervisorJson = "{\"hypervisors\":" + "[{" + "\"name\" : \"hypervisor_999\"," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}]" + "}]}";
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
verify(consumerResource, never()).createConsumerFromDTO(any(ConsumerDTO.class), any(ConsumerType.class), any(Principal.class), anyString(), anyString(), anyString(), eq(false));
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method reporterIdOnCreateTest.
@Test
public void reporterIdOnCreateTest() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, "createReporterId");
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
ArgumentCaptor<Consumer> argument = ArgumentCaptor.forClass(Consumer.class);
verify(consumerCurator).create(argument.capture(), eq(false));
assertEquals("createReporterId", argument.getValue().getHypervisorId().getReporterId());
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method reporterIdOnUpdateTest.
@Test
public void reporterIdOnUpdateTest() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
Consumer hypervisor = new Consumer();
String hypervisorId = "uuid_999";
hypervisor.setHypervisorId(new HypervisorId(hypervisorId));
VirtConsumerMap vcm = new VirtConsumerMap();
vcm.add(hypervisorId, hypervisor);
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(vcm);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, "updateReporterId");
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
assertEquals("updateReporterId", hypervisor.getHypervisorId().getReporterId());
}
Aggregations