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