use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class EntitleByProductsJobTest method bindByProductsExec.
@Test
public void bindByProductsExec() throws Exception {
String[] pids = { "pid1", "pid2", "pid3" };
JobDetail detail = EntitleByProductsJob.bindByProducts(pids, consumer, null, null, owner.getKey());
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
List<Entitlement> ents = new ArrayList<>();
when(e.bindByProducts(eq(pids), eq(consumerUuid), eq((Date) null), eq((Collection<String>) null))).thenReturn(ents);
EntitleByProductsJob job = new EntitleByProductsJob(e, null);
injector.injectMembers(job);
job.execute(ctx);
verify(e).bindByProducts(eq(pids), eq(consumerUuid), eq((Date) null), eq((Collection<String>) null));
verify(e).sendEvents(eq(ents));
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class JobCuratorTest method updateWithLargeResult.
@Test
public void updateWithLargeResult() {
String longstr = RandomStringUtils.randomAlphanumeric(300);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getFireTime()).thenReturn(new Date());
when(ctx.getJobRunTime()).thenReturn(1000L);
when(ctx.getResult()).thenReturn(longstr);
JobStatus status = newJobStatus().owner("terps").create();
status.update(ctx);
curator.merge(status);
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class EntitlerJobTest method respondWithValidationErrors.
@Test
public void respondWithValidationErrors() throws JobExecutionException, EntitlementRefusedException {
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity("pool10", 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HashMap<String, ValidationResult> mapResult = new HashMap<>();
ValidationResult result = new ValidationResult();
result.addError("rulefailed.no.entitlements.available");
mapResult.put("hello", result);
when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenThrow(new EntitlementRefusedException(mapResult));
EntitlerJob job = new EntitlerJob(e, null, pC, i18n);
injector.injectMembers(job);
Pool p = new Pool();
p.setId("hello");
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(p).iterator());
when(pC.listAllByIds(anyListOf(String.class))).thenReturn(cqmock);
job.execute(ctx);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(ctx).setResult(argumentCaptor.capture());
List<PoolIdAndErrors> resultErrors = (List<PoolIdAndErrors>) argumentCaptor.getValue();
assertEquals(1, resultErrors.size());
assertEquals("hello", resultErrors.get(0).getPoolId());
assertEquals(1, resultErrors.get(0).getErrors().size());
assertEquals("No subscriptions are available from the pool with ID \"hello\".", resultErrors.get(0).getErrors().get(0));
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class EntitlerJobTest method handleException.
@Test(expected = JobExecutionException.class)
public void handleException() throws JobExecutionException, EntitlementRefusedException {
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity("pool10", 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
Class<HashMap<String, Integer>> className = (Class<HashMap<String, Integer>>) (Class) Map.class;
ArgumentCaptor<HashMap<String, Integer>> pqMapCaptor = ArgumentCaptor.forClass(className);
when(e.bindByPoolQuantities(eq(consumerUuid), pqMapCaptor.capture())).thenThrow(new ForbiddenException("job should fail"));
EntitlerJob job = new EntitlerJob(e, null, null, null);
injector.injectMembers(job);
job.execute(ctx);
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateExecCreate.
@Test
public void hypervisorUpdateExecCreate() throws JobExecutionException {
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);
job.execute(ctx);
verify(consumerCurator).create(any(Consumer.class), eq(false));
}
Aggregations