Search in sources :

Example 21 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap 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 22 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap 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 23 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap 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

VirtConsumerMap (org.candlepin.model.VirtConsumerMap)23 Set (java.util.Set)18 Consumer (org.candlepin.model.Consumer)18 Test (org.junit.Test)18 Owner (org.candlepin.model.Owner)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 HypervisorCheckInResult (org.candlepin.resource.dto.HypervisorCheckInResult)8 HashSet (java.util.HashSet)7 GuestId (org.candlepin.model.GuestId)7 JobDetail (org.quartz.JobDetail)7 JobExecutionContext (org.quartz.JobExecutionContext)7 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)6 IdentityCertificate (org.candlepin.model.IdentityCertificate)6 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)4 Transactional (com.google.inject.persist.Transactional)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2