Search in sources :

Example 16 with GuestId

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackWithUnlimited.

@Test
public void fullyCompliantVirtLimitStackWithUnlimited() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "1");
    }
    ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 17 with GuestId

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

the class ComplianceRulesTest method partiallyCompliantVirtLimitStack.

@Test
public void partiallyCompliantVirtLimitStack() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    }
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(0, status.getCompliantProducts().size());
    assertEquals(2, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getPartiallyCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 18 with GuestId

use of org.candlepin.model.GuestId 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());
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) GuestId(org.candlepin.model.GuestId) List(java.util.List) ArrayList(java.util.ArrayList) IdentityCertificate(org.candlepin.model.IdentityCertificate) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Example 19 with GuestId

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

the class GuestIdResourceTest method updateGuest.

@Test
public void updateGuest() {
    GuestIdDTO guest = TestUtil.createGuestIdDTO("some_guest");
    GuestId guestEnt = new GuestId();
    guestEnt.setId("some_id");
    guestIdResource.updateGuest(consumer.getUuid(), guest.getGuestId(), guest);
    when(guestIdCurator.findByGuestIdAndOrg(anyString(), any(String.class))).thenReturn(guestEnt);
    ArgumentCaptor<GuestId> guestCaptor = ArgumentCaptor.forClass(GuestId.class);
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(guestCaptor.capture());
    GuestId result = guestCaptor.getValue();
    assertEquals(consumer, result.getConsumer());
}
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 20 with GuestId

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

the class GuestIdResourceTest method updateGuestNoGuestId.

/*
     * Update should add the id from the url to the GuestId object
     * if it does not already have one.
     */
@Test
public void updateGuestNoGuestId() {
    GuestIdDTO guestIdDTO = new GuestIdDTO();
    guestIdResource.updateGuest(consumer.getUuid(), "some_id", guestIdDTO);
    ArgumentCaptor<GuestId> guestCaptor = ArgumentCaptor.forClass(GuestId.class);
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(guestCaptor.capture());
    GuestId guest = guestCaptor.getValue();
    assertEquals(consumer, guest.getConsumer());
    assertEquals("some_id", guest.getGuestId());
    Mockito.verify(guestIdCurator, Mockito.times(1)).merge(eq(guest));
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) 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