Search in sources :

Example 56 with Entitlement

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());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with Entitlement

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());
}
Also used : Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with Entitlement

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());
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) List(java.util.List) ArrayList(java.util.ArrayList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 59 with Entitlement

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));
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) GuestMigration(org.candlepin.resource.util.GuestMigration) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) ConsumerBindUtil(org.candlepin.resource.util.ConsumerBindUtil) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) List(java.util.List) ArrayList(java.util.ArrayList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 60 with Entitlement

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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15