Search in sources :

Example 1 with VirtConsumerMap

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

the class ConsumerResourceUpdateTest method ensureEventIsNotFiredWhenGuestIDCaseChanges.

@Test
public void ensureEventIsNotFiredWhenGuestIDCaseChanges() {
    String uuid = "TEST_CONSUMER";
    Consumer existing = createConsumerWithGuests(createOwner(), "aaa123", "bbb123");
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    // flip case on one ID, should be treated as no change
    ConsumerDTO updated = createConsumerDTOWithGuests("aaa123", "BBB123");
    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 2 with VirtConsumerMap

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

the class HypervisorResourceTest method ensureEmptyHypervisorIdsAreIgnored.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void ensureEmptyHypervisorIdsAreIgnored() throws Exception {
    Owner owner = new Owner("admin");
    owner.setId("test-id");
    Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
    hostGuestMap.put("", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_A"), TestUtil.createGuestIdDTO("GUEST_B"))));
    hostGuestMap.put("HYPERVISOR_A", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_C"), TestUtil.createGuestIdDTO("GUEST_D"))));
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
    assertNotNull(result);
    assertEquals(1, result.getCreated().size());
    List<Consumer> created = new ArrayList<>(result.getCreated());
    assertEquals("hypervisor_a", created.get(0).getHypervisorId().getHypervisorId());
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IdentityCertificate(org.candlepin.model.IdentityCertificate) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Example 3 with VirtConsumerMap

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

the class HypervisorResourceTest method ensureEmptyGuestIdsAreIgnored.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void ensureEmptyGuestIdsAreIgnored() throws Exception {
    Owner owner = new Owner("admin");
    Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
    hostGuestMap.put("HYPERVISOR_A", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_A"), TestUtil.createGuestIdDTO(""))));
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
    assertNotNull(result);
    assertNotNull(result.getCreated());
    List<Consumer> created = new ArrayList<>(result.getCreated());
    assertEquals(1, created.size());
    List<GuestId> gids = created.get(0).getGuestIds();
    assertEquals(1, gids.size());
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) GuestId(org.candlepin.model.GuestId) List(java.util.List) ArrayList(java.util.ArrayList) IdentityCertificate(org.candlepin.model.IdentityCertificate) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Example 4 with VirtConsumerMap

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

the class HypervisorResourceTest method checkInCreatesNoNewConsumerWhenCreateIsFalse.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void checkInCreatesNoNewConsumerWhenCreateIsFalse() throws Exception {
    Owner owner = new Owner("admin");
    Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
    hostGuestMap.put("test-host", new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_A"), TestUtil.createGuestIdDTO("GUEST_B"))));
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
    HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), false);
    assertEquals(0, result.getCreated().size());
    assertEquals(1, result.getFailedUpdate().size());
    String failed = result.getFailedUpdate().iterator().next();
    String expected = "test-host: Unable to find hypervisor in org \"admin\"";
    assertEquals(expected, failed);
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IdentityCertificate(org.candlepin.model.IdentityCertificate) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Example 5 with VirtConsumerMap

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

the class HypervisorResourceTest method mockHypervisorConsumerMap.

private VirtConsumerMap mockHypervisorConsumerMap(String hypervisorId, Consumer c) {
    VirtConsumerMap mockMap = new VirtConsumerMap();
    mockMap.add(hypervisorId, c);
    return mockMap;
}
Also used : VirtConsumerMap(org.candlepin.model.VirtConsumerMap)

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