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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations