Search in sources :

Example 26 with JobExecutionContext

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

Example 27 with JobExecutionContext

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

Example 28 with JobExecutionContext

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));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) JobExecutionContext(org.quartz.JobExecutionContext) ConsumerType(org.candlepin.model.ConsumerType) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 29 with JobExecutionContext

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());
}
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)

Example 30 with JobExecutionContext

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