use of org.candlepin.resource.dto.HypervisorCheckInResult 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.resource.dto.HypervisorCheckInResult 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.resource.dto.HypervisorCheckInResult 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.resource.dto.HypervisorCheckInResult in project candlepin by candlepin.
the class HypervisorResourceTest method hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
Owner owner = new Owner("owner-id", "Owner Id");
Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
String hypervisorId = "test-host";
hostGuestMap.put(hypervisorId, new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_B"))));
Owner o = new Owner("owner-id", "Owner ID");
o.setId("owner-id");
Consumer existing = new Consumer();
existing.setUuid("test-host");
existing.setOwner(o);
existing.addGuestId(new GuestId("GUEST_A"));
existing.setType(this.hypervisorType);
when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
// Force update
when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(mockHypervisorConsumerMap(hypervisorId, existing));
when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
List<Consumer> updated = new ArrayList<>(result.getUpdated());
assertEquals(1, updated.size());
Consumer c1 = updated.get(0);
assertEquals("test-host", c1.getUuid());
assertEquals(1, c1.getGuestIds().size());
assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
}
use of org.candlepin.resource.dto.HypervisorCheckInResult in project candlepin by candlepin.
the class HypervisorResourceTest method hypervisorCheckInReportsFailuresOnCreateFailure.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void hypervisorCheckInReportsFailuresOnCreateFailure() throws Exception {
Owner owner = new Owner("admin");
Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
String expectedHostVirtId = "test-host-id";
hostGuestMap.put(expectedHostVirtId, new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_A"), TestUtil.createGuestIdDTO("GUEST_B"))));
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(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(new IdentityCertificate());
String expectedMessage = "Forced Exception.";
RuntimeException exception = new RuntimeException(expectedMessage);
// Simulate failure when checking the owner
when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
when(consumerCurator.create(any(Consumer.class))).thenThrow(exception);
HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
List<String> failures = new ArrayList<>(result.getFailedUpdate());
assertEquals(1, failures.size());
assertTrue(failures.get(0).contains("Problem creating unit"));
}
Aggregations