use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class QuantityRulesTest method testTotalConsumedIsZeroWhenNoMatches.
@Test
public void testTotalConsumedIsZeroWhenNoMatches() {
consumer.setFact(IS_VIRT, "");
consumer.setFact(SOCKET_FACT, "4");
pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
Product product2 = TestUtil.createProduct();
Pool pool2 = TestUtil.createPool(owner, product2);
Entitlement e = createValidEntitlement(pool2);
e.setQuantity(2);
Set<Entitlement> ents = new HashSet<>();
ents.add(e);
consumer.setEntitlements(ents);
SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
assertEquals(new Long(2), suggested.getSuggested());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class QuantityRulesTest method testCalculatedValueIsZeroWhenNegativeIsCalculated.
@Test
public void testCalculatedValueIsZeroWhenNegativeIsCalculated() {
consumer.setFact(IS_VIRT, "");
consumer.setFact(SOCKET_FACT, "4");
pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
Entitlement e = createValidEntitlement(pool);
e.setQuantity(1000);
Set<Entitlement> ents = new HashSet<>();
ents.add(e);
consumer.setEntitlements(ents);
SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
assertEquals(new Long(0), suggested.getSuggested());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testBindByPool.
@SuppressWarnings("unchecked")
@Test
public void testBindByPool() throws Exception {
Response rsp = consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
List<EntitlementDTO> resultList = (List<EntitlementDTO>) rsp.getEntity();
consumer = consumerCurator.findByUuid(consumer.getUuid());
assertEquals(1, consumer.getEntitlements().size());
pool = poolManager.find(pool.getId());
assertEquals(Long.valueOf(1), pool.getConsumed());
assertEquals(1, resultList.size());
assertEquals(pool.getId(), resultList.get(0).getPool().getId());
Entitlement ent = new Entitlement();
ent.setId(resultList.get(0).getId());
assertEquals(1, entitlementCertificateCurator.listForEntitlement(ent).size());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testRegenerateEntitlementCertificateWithValidConsumerByEntitlement.
/**
* Test verifies that list of certs changes after regeneration
*/
@SuppressWarnings("unchecked")
@Test
public void testRegenerateEntitlementCertificateWithValidConsumerByEntitlement() {
GuestMigration testMigration = new GuestMigration(consumerCurator);
Provider<GuestMigration> migrationProvider = Providers.of(testMigration);
ConsumerResource cr = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, null, null, this.entitlementCurator, null, null, null, null, null, null, null, null, this.poolManager, null, null, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, mock(ConsumerBindUtil.class), null, null, null, null, consumerEnricher, migrationProvider, this.modelTranslator);
Response rsp = consumerResource.bind(consumer.getUuid(), pool.getId().toString(), null, 1, null, null, false, null, null);
List<EntitlementDTO> resultList = (List<EntitlementDTO>) rsp.getEntity();
EntitlementDTO ent = resultList.get(0);
assertEquals(1, ent.getCertificates().size());
CertificateDTO entCertBefore = ent.getCertificates().iterator().next();
cr.regenerateEntitlementCertificates(this.consumer.getUuid(), ent.getId(), false);
Entitlement entWithRefreshedCerts = entitlementCurator.find(ent.getId());
ent = this.modelTranslator.translate(entWithRefreshedCerts, EntitlementDTO.class);
assertEquals(1, ent.getCertificates().size());
CertificateDTO entCertAfter = ent.getCertificates().iterator().next();
assertFalse(entCertBefore.equals(entCertAfter));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method ensureGuestEntitlementsAreNotRemovedWhenGuestsAndHostAreTheSame.
@Test
public void ensureGuestEntitlementsAreNotRemovedWhenGuestsAndHostAreTheSame() {
String uuid = "TEST_CONSUMER";
Consumer host = createConsumerWithGuests(createOwner(), "Guest 1");
host.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
updatedHost.setUuid(uuid);
Entitlement entitlement = TestUtil.createEntitlement();
entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
Consumer guest1 = new Consumer();
guest1.setUuid("Guest 1");
guest1.addEntitlement(entitlement);
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
Aggregations