Search in sources :

Example 11 with GuestIdDTO

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());
}
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 12 with GuestIdDTO

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());
}
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 13 with GuestIdDTO

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");
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 14 with GuestIdDTO

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);
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestId(org.candlepin.model.GuestId) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 15 with GuestIdDTO

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));
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Test(org.junit.Test)

Aggregations

GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)14 GuestId (org.candlepin.model.GuestId)12 Consumer (org.candlepin.model.Consumer)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)5 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)5 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Consumes (javax.ws.rs.Consumes)3 Produces (javax.ws.rs.Produces)3 Mockito.anyString (org.mockito.Mockito.anyString)3 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)2 Transactional (com.google.inject.persist.Transactional)1 ApiResponses (io.swagger.annotations.ApiResponses)1