Search in sources :

Example 41 with GuestId

use of org.candlepin.model.GuestId 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 42 with GuestId

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

the class AutobindRulesTest method guestLimitAutobindNeitherAttached.

/*
     * Expect nothing to happen. We cannot bind the hypervisor in order to make
     * the guests compliant, but that'd be a nice feature in the future.
     */
@Test
public void guestLimitAutobindNeitherAttached() {
    consumer.setFact("cpu.cpu_socket(s)", "8");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
    }
    Product server = mockStackingProduct(productId, "some server", "stackid1", "2");
    server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    Product hypervisor = mockStackingProduct("hypervisor", "some hypervisor", "stackid2", "2");
    hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Pool serverPool = TestUtil.createPool(owner, server, 10);
    Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
    serverPool.setId("POOL-ID1");
    hyperPool.setId("Pool-ID2");
    List<Pool> pools = new LinkedList<>();
    pools.add(serverPool);
    pools.add(hyperPool);
    assertEquals(0, autobindRules.selectBestPools(consumer, new String[] { server.getUuid() }, pools, compliance, null, new HashSet<>(), false).size());
}
Also used : GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 43 with GuestId

use of org.candlepin.model.GuestId 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 44 with GuestId

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

the class GuestIdResourceTest method deleteGuestAndUnregister.

@Test
public void deleteGuestAndUnregister() {
    Consumer guestConsumer = new Consumer("guest_consumer", "guest_consumer", owner, ct);
    GuestId guest = new GuestId("guest-id", consumer);
    when(guestIdCurator.findByConsumerAndId(eq(consumer), eq(guest.getGuestId()))).thenReturn(guest);
    when(consumerCurator.findByVirtUuid(guest.getGuestId(), consumer.getOwnerId())).thenReturn(guestConsumer);
    guestIdResource.deleteGuest(consumer.getUuid(), guest.getGuestId(), true, null);
    Mockito.verify(guestIdCurator, Mockito.times(1)).delete(eq(guest));
    Mockito.verify(consumerResource, Mockito.never()).checkForMigration(eq(consumer), eq(guestConsumer));
    Mockito.verify(consumerResource, Mockito.times(1)).deleteConsumer(eq(guestConsumer.getUuid()), any(Principal.class));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 45 with GuestId

use of org.candlepin.model.GuestId 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

GuestId (org.candlepin.model.GuestId)49 Consumer (org.candlepin.model.Consumer)37 Test (org.junit.Test)34 LinkedList (java.util.LinkedList)15 Entitlement (org.candlepin.model.Entitlement)14 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)11 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Product (org.candlepin.model.Product)8 ArrayList (java.util.ArrayList)7 Owner (org.candlepin.model.Owner)7 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 List (java.util.List)5 Pool (org.candlepin.model.Pool)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4