Search in sources :

Example 6 with JobExecutionContext

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));
}
Also used : JobDetail(org.quartz.JobDetail) ArrayList(java.util.ArrayList) JobExecutionContext(org.quartz.JobExecutionContext) Collection(java.util.Collection) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 7 with JobExecutionContext

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);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobExecutionContext(org.quartz.JobExecutionContext) Date(java.util.Date) Test(org.junit.Test)

Example 8 with JobExecutionContext

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));
}
Also used : PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) PoolIdAndErrors(org.candlepin.model.dto.PoolIdAndErrors) HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) CandlepinQuery(org.candlepin.model.CandlepinQuery) ValidationResult(org.candlepin.policy.ValidationResult) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with JobExecutionContext

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);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) HashMap(java.util.HashMap) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) HashMap(java.util.HashMap) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 10 with JobExecutionContext

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));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test)

Aggregations

JobExecutionContext (org.quartz.JobExecutionContext)47 Test (org.junit.Test)20 JobDetail (org.quartz.JobDetail)20 JobDataMap (org.quartz.JobDataMap)13 Set (java.util.Set)10 JobExecutionException (org.quartz.JobExecutionException)10 List (java.util.List)8 SchedulerException (org.quartz.SchedulerException)8 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 Job (org.quartz.Job)6 ArrayList (java.util.ArrayList)5 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)5 Consumer (org.candlepin.model.Consumer)4 InterruptableJob (org.quartz.InterruptableJob)4 Scheduler (org.quartz.Scheduler)4 Date (java.util.Date)3 Map (java.util.Map)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2