Search in sources :

Example 1 with EntitlementDTO

use of org.candlepin.dto.api.v1.EntitlementDTO in project candlepin by candlepin.

the class EntitlementImporterTest method fullImport.

@Test
public void fullImport() throws Exception {
    Product parentProduct = TestUtil.createProduct();
    Product derivedProduct = TestUtil.createProduct();
    Product provided1 = TestUtil.createProduct();
    Set<Product> providedProducts = new HashSet<>();
    providedProducts.add(new Product(provided1));
    Product derivedProvided1 = TestUtil.createProduct();
    Set<Product> derivedProvidedProducts = new HashSet<>();
    derivedProvidedProducts.add(new Product(derivedProvided1));
    Pool pool = TestUtil.createPool(owner, parentProduct, new HashSet<>(), derivedProduct, new HashSet<>(), 3);
    pool.setProvidedProducts(providedProducts);
    pool.setDerivedProvidedProducts(derivedProvidedProducts);
    Entitlement ent = TestUtil.createEntitlement(owner, consumer, pool, cert);
    ent.setQuantity(3);
    EntitlementDTO dtoEnt = this.translator.translate(ent, EntitlementDTO.class);
    when(om.readValue(reader, EntitlementDTO.class)).thenReturn(dtoEnt);
    // Create our expected products
    Map<String, ProductDTO> productsById = buildProductCache(parentProduct, provided1, derivedProduct, derivedProvided1);
    Subscription sub = importer.importObject(om, reader, owner, productsById, consumerDTO.getUuid(), meta);
    assertEquals(pool.getId(), sub.getUpstreamPoolId());
    assertEquals(consumer.getUuid(), sub.getUpstreamConsumerId());
    assertEquals(ent.getId(), sub.getUpstreamEntitlementId());
    assertEquals(owner, sub.getOwner());
    assertEquals(ent.getStartDate(), sub.getStartDate());
    assertEquals(ent.getEndDate(), sub.getEndDate());
    assertEquals(pool.getAccountNumber(), sub.getAccountNumber());
    assertEquals(pool.getContractNumber(), sub.getContractNumber());
    assertEquals(pool.getOrderNumber(), sub.getOrderNumber());
    assertEquals(ent.getQuantity().intValue(), sub.getQuantity().intValue());
    assertEquals(parentProduct.toDTO(), sub.getProduct());
    assertEquals(providedProducts.size(), sub.getProvidedProducts().size());
    assertEquals(provided1.getId(), sub.getProvidedProducts().iterator().next().getId());
    assertEquals(derivedProduct.toDTO(), sub.getDerivedProduct());
    assertEquals(1, sub.getDerivedProvidedProducts().size());
    assertEquals(derivedProvided1.getId(), sub.getDerivedProvidedProducts().iterator().next().getId());
    assertNotNull(sub.getCertificate());
    CertificateSerial serial = sub.getCertificate().getSerial();
    assertEquals(cert.getSerial().isCollected(), serial.isCollected());
    assertEquals(cert.getSerial().getExpiration(), serial.getExpiration());
    assertEquals(cert.getSerial().getCreated(), serial.getCreated());
    assertEquals(cert.getSerial().getUpdated(), serial.getUpdated());
    assertEquals(sub.getCdn().getLabel(), meta.getCdnLabel());
}
Also used : EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) Product(org.candlepin.model.Product) CertificateSerial(org.candlepin.model.CertificateSerial) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Subscription(org.candlepin.model.dto.Subscription) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with EntitlementDTO

use of org.candlepin.dto.api.v1.EntitlementDTO 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 3 with EntitlementDTO

use of org.candlepin.dto.api.v1.EntitlementDTO 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 4 with EntitlementDTO

use of org.candlepin.dto.api.v1.EntitlementDTO in project candlepin by candlepin.

the class EntitlementResourceTest method getAllEntitlements.

@Test
public void getAllEntitlements() {
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    Entitlement e = TestUtil.createEntitlement();
    e.setId("getEntitlementList");
    List<Entitlement> entitlements = new ArrayList<>();
    entitlements.add(e);
    Page<List<Entitlement>> page = new Page<>();
    page.setPageData(entitlements);
    EntitlementDTO entitlementDTO = new EntitlementDTO();
    entitlementDTO.setId("getEntitlementList");
    when(entitlementCurator.listAll(isA(EntitlementFilterBuilder.class), isA(PageRequest.class))).thenReturn(page);
    when(modelTranslator.translate(isA(Entitlement.class), eq(EntitlementDTO.class))).thenReturn(entitlementDTO);
    List<EntitlementDTO> result = entResource.listAllForConsumer(null, null, null, req);
    assertEquals(1, result.size());
    assertEquals("getEntitlementList", result.get(0).getId());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Page(org.candlepin.common.paging.Page) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 5 with EntitlementDTO

use of org.candlepin.dto.api.v1.EntitlementDTO in project candlepin by candlepin.

the class OwnerResource method ownerEntitlements.

/**
 * Retrieves the list of Entitlements for an Owner
 *
 * @param ownerKey id of the owner whose entitlements are sought.
 * @return a list of Entitlement objects
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/entitlements")
@ApiOperation(notes = "Retrieves the list of Entitlements for an Owner", value = "List Owner Entitlements")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public List<EntitlementDTO> ownerEntitlements(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("product") String productId, @QueryParam("matches") String matches, @QueryParam("attribute") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
    Owner owner = findOwnerByKey(ownerKey);
    EntitlementFilterBuilder filters = EntitlementFinderUtil.createFilter(matches, attrFilters);
    Page<List<Entitlement>> entitlementsPage = entitlementCurator.listByOwner(owner, productId, filters, pageRequest);
    // Store the page for the LinkHeaderPostInterceptor
    ResteasyProviderFactory.pushContext(Page.class, entitlementsPage);
    List<EntitlementDTO> entitlementDTOs = new ArrayList<>();
    for (Entitlement entitlement : entitlementsPage.getPageData()) {
        entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class));
    }
    return entitlementDTOs;
}
Also used : Owner(org.candlepin.model.Owner) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) EntitlementFilterBuilder(org.candlepin.model.EntitlementFilterBuilder) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Entitlement (org.candlepin.model.Entitlement)15 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)11 ArrayList (java.util.ArrayList)10 List (java.util.List)8 Pool (org.candlepin.model.Pool)8 ConsumerDTO (org.candlepin.dto.rules.v1.ConsumerDTO)7 EntitlementDTO (org.candlepin.dto.rules.v1.EntitlementDTO)7 JsonJsContext (org.candlepin.policy.js.JsonJsContext)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6 Consumer (org.candlepin.model.Consumer)6 Test (org.junit.Test)6 Path (javax.ws.rs.Path)5 ConsumerType (org.candlepin.model.ConsumerType)5 EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)5 Owner (org.candlepin.model.Owner)5 LinkedList (java.util.LinkedList)4 GET (javax.ws.rs.GET)4 RuleExecutionException (org.candlepin.policy.js.RuleExecutionException)4