Search in sources :

Example 16 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method multipleUpdatesCanOccur.

@Test
public void multipleUpdatesCanOccur() {
    String uuid = "A Consumer";
    String expectedFactName = "FACT1";
    String expectedFactValue = "F1";
    GuestIdDTO expectedGuestId = TestUtil.createGuestIdDTO("GUEST_ID_1");
    Consumer existing = getFakeConsumer();
    existing.setFacts(new HashMap<>());
    existing.setInstalledProducts(new HashSet<>());
    ConsumerDTO updated = new ConsumerDTO();
    updated.setUuid(uuid);
    updated.setFact(expectedFactName, expectedFactValue);
    Product prod = TestUtil.createProduct("Product One");
    ConsumerInstalledProductDTO expectedInstalledProduct = new ConsumerInstalledProductDTO(prod.getId(), prod.getName());
    updated.addInstalledProduct(expectedInstalledProduct);
    updated.addGuestId(expectedGuestId);
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    this.resource.updateConsumer(existing.getUuid(), updated, principal);
    assertEquals(1, existing.getFacts().size());
    assertEquals(expectedFactValue, existing.getFact(expectedFactName));
    assertEquals(1, existing.getInstalledProducts().size());
    ConsumerInstalledProduct actualCIP = existing.getInstalledProducts().iterator().next();
    assertNotNull(actualCIP);
    assertEquals(actualCIP.getProductId(), expectedInstalledProduct.getProductId());
    assertEquals(actualCIP.getProductName(), expectedInstalledProduct.getProductName());
    assertEquals(actualCIP.getVersion(), expectedInstalledProduct.getVersion());
    assertEquals(actualCIP.getArch(), expectedInstalledProduct.getArch());
    assertEquals(actualCIP.getStatus(), expectedInstalledProduct.getStatus());
    assertEquals(actualCIP.getStartDate(), expectedInstalledProduct.getStartDate());
    assertEquals(actualCIP.getEndDate(), expectedInstalledProduct.getEndDate());
    assertEquals(1, existing.getGuestIds().size());
    GuestId actualGID = existing.getGuestIds().iterator().next();
    assertNotNull(actualGID);
    assertEquals(actualGID.getGuestId(), expectedGuestId.getGuestId());
    assertEquals(actualGID.getAttributes(), expectedGuestId.getAttributes());
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) GuestId(org.candlepin.model.GuestId) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) Test(org.junit.Test)

Example 17 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method ensureEventIsNotFiredWhenNoChangeWasMadeToConsumerGuestIds.

@Test
public void ensureEventIsNotFiredWhenNoChangeWasMadeToConsumerGuestIds() {
    String uuid = "TEST_CONSUMER";
    Consumer existing = createConsumerWithGuests(createOwner(), "Guest 1", "Guest 2");
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    ConsumerDTO updated = createConsumerDTOWithGuests("Guest 1", "Guest 2");
    updated.setUuid(uuid);
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    this.resource.updateConsumer(existing.getUuid(), updated, principal);
    verify(sink, never()).queueEvent(any(Event.class));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Event(org.candlepin.audit.Event) Test(org.junit.Test)

Example 18 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method testUpdateConsumerUpdatesGuestIds.

@Test
public void testUpdateConsumerUpdatesGuestIds() {
    String uuid = "TEST_CONSUMER";
    String[] existingGuests = new String[] { "Guest 1", "Guest 2", "Guest 3" };
    Consumer existing = createConsumerWithGuests(createOwner(), existingGuests);
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    ConsumerDTO updated = new ConsumerDTO();
    updated.setUuid(uuid);
    GuestIdDTO expectedGuestId = TestUtil.createGuestIdDTO("Guest 2");
    updated.addGuestId(expectedGuestId);
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    this.resource.updateConsumer(existing.getUuid(), updated, principal);
    assertEquals(1, existing.getGuestIds().size());
    GuestId actualGID = existing.getGuestIds().iterator().next();
    assertNotNull(actualGID);
    assertEquals(actualGID.getGuestId(), expectedGuestId.getGuestId());
    assertEquals(actualGID.getAttributes(), expectedGuestId.getAttributes());
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) GuestId(org.candlepin.model.GuestId) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 19 with VirtConsumerMap

use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method mockVirtConsumerMap.

private VirtConsumerMap mockVirtConsumerMap(String uuid, Consumer consumer) {
    VirtConsumerMap map = new VirtConsumerMap();
    map.add(uuid, consumer);
    return map;
}
Also used : VirtConsumerMap(org.candlepin.model.VirtConsumerMap)

Example 20 with VirtConsumerMap

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

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