use of org.candlepin.dto.api.v1.GuestIdDTO 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());
}
use of org.candlepin.dto.api.v1.GuestIdDTO 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());
}
use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.
the class GuestIdResourceTest method getGuestIdNoGuests.
@Test(expected = NotFoundException.class)
public void getGuestIdNoGuests() {
when(guestIdCurator.findByConsumerAndId(eq(consumer), any(String.class))).thenReturn(null);
GuestIdDTO result = guestIdResource.getGuestId(consumer.getUuid(), "some-id");
}
use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.
the class GuestIdResourceTest method getGuestId.
@Test
public void getGuestId() {
when(guestIdCurator.findByConsumerAndId(eq(consumer), any(String.class))).thenReturn(new GuestId("guest"));
GuestIdDTO result = guestIdResource.getGuestId(consumer.getUuid(), "some-id");
assertEquals(TestUtil.createGuestIdDTO("guest"), result);
}
use of org.candlepin.dto.api.v1.GuestIdDTO in project candlepin by candlepin.
the class GuestIdResourceTest method updateGuestRevokeHostSpecific.
@Test
public void updateGuestRevokeHostSpecific() {
Consumer guestConsumer = new Consumer("guest_consumer", "guest_consumer", owner, ct);
GuestId originalGuest = new GuestId("guest-id", guestConsumer);
GuestIdDTO guest = TestUtil.createGuestIdDTO("guest-id");
when(guestIdCurator.findByGuestIdAndOrg(eq(guest.getGuestId()), eq(owner.getId()))).thenReturn(originalGuest);
when(consumerCurator.findByVirtUuid(eq(guest.getGuestId()), eq(owner.getId()))).thenReturn(guestConsumer);
guestIdResource.updateGuest(consumer.getUuid(), guest.getGuestId(), guest);
ArgumentCaptor<GuestId> captor = ArgumentCaptor.forClass(GuestId.class);
Mockito.verify(guestIdCurator, Mockito.times(1)).merge(captor.capture());
GuestId guestId = captor.getValue();
assertEquals("guest-id", guestId.getGuestId());
// We now check for migration when the system checks in, not during guest ID updates.
Mockito.verify(consumerResource, Mockito.times(0)).checkForMigration(any(Consumer.class), any(Consumer.class));
}
Aggregations