Search in sources :

Example 11 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductManagerTest method testUpdateProduct.

@Test
@Parameters({ "false", "true" })
public void testUpdateProduct(boolean regenCerts) {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "prod1", owner);
    ProductDTO update = TestUtil.createProductDTO("p1", "new product name");
    Product output = this.productManager.updateProduct(update, owner, regenCerts);
    assertNotEquals(output.getUuid(), product.getUuid());
    assertEquals(output.getName(), update.getName());
    // We expect the original to be kept around as an orphan until the orphan removal job
    // gets around to removing them
    assertNotNull(this.productCurator.find(product.getUuid()));
    assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
    assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
    if (regenCerts) {
        // TODO: Is there a better way to do this? We won't know the exact product instance,
        // we just know that a product should be refreshed as a result of this operation.
        verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner)), anyCollectionOf(Product.class), anyBoolean());
    } else {
        verifyZeroInteractions(this.mockEntCertGenerator);
    }
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 12 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductManagerTest method testUpdateProductDivergeFromExisting.

@Test
@Parameters({ "false", "true" })
public void testUpdateProductDivergeFromExisting(boolean regenCerts) {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Product product = this.createProduct("p1", "prod1", owner1, owner2);
    ProductDTO update = TestUtil.createProductDTO("p1", "updated product");
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    Product output = this.productManager.updateProduct(update, owner1, regenCerts);
    assertNotEquals(output.getUuid(), product.getUuid());
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    if (regenCerts) {
        verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner1)), anyCollectionOf(Product.class), anyBoolean());
    } else {
        verifyZeroInteractions(this.mockEntCertGenerator);
    }
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 13 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductDTOTranslatorTest method initSourceObject.

@Override
protected ProductDTO initSourceObject() {
    ProductDTO source = new ProductDTO();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attrib_1", "attrib_value_1");
    attributes.put("attrib_2", "attrib_value_2");
    attributes.put("attrib_3", "attrib_value_3");
    Collection<String> depProdIds = new LinkedList<>();
    depProdIds.add("dep_prod_1");
    depProdIds.add("dep_prod_2");
    depProdIds.add("dep_prod_3");
    source.setUuid("test_uuid");
    source.setId("test_id");
    source.setName("test_name");
    source.setMultiplier(10L);
    source.setAttributes(attributes);
    source.setDependentProductIds(depProdIds);
    for (int i = 0; i < 3; ++i) {
        ContentDTO contentDTO = new ContentDTO();
        contentDTO.setId("content-dto-" + i);
        contentDTO.setUuid(contentDTO.getId() + "_uuid");
        ProductContentDTO pcDTO = new ProductContentDTO(contentDTO, true);
        source.addProductContent(pcDTO);
    }
    return source;
}
Also used : ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) HashMap(java.util.HashMap) ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) LinkedList(java.util.LinkedList)

Example 14 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductDTOTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(ProductDTO source, ProductData dto, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getUuid(), dto.getUuid());
        assertEquals(source.getId(), dto.getId());
        assertEquals(source.getName(), dto.getName());
        assertEquals(source.getMultiplier(), dto.getMultiplier());
        assertEquals(source.getAttributes(), dto.getAttributes());
        assertEquals(source.getDependentProductIds(), dto.getDependentProductIds());
        assertNotNull(dto.getProductContent());
        if (childrenGenerated) {
            for (ProductContentDTO pcdto : source.getProductContent()) {
                for (ProductContentData pcdata : dto.getProductContent()) {
                    ContentDTO cdto = pcdto.getContent();
                    ContentData cdata = pcdata.getContent();
                    assertNotNull(cdata);
                    assertNotNull(cdata.getUuid());
                    if (cdata.getUuid().equals(cdto.getUuid())) {
                        assertEquals(pcdto.isEnabled(), pcdata.isEnabled());
                        // Pass the content off to the ContentTranslatorTest to verify it
                        this.contentDTOTranslatorTest.verifyOutput(cdto, cdata, true);
                    }
                }
            }
        } else {
            assertTrue(dto.getProductContent().isEmpty());
        }
    } else {
        assertNull(dto);
    }
}
Also used : ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ProductContentData(org.candlepin.model.dto.ProductContentData)

Example 15 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class EntitlementImporter method associateProvidedProducts.

/*
     * Transfer associations to provided and derived provided products over to the
     * subscription.
     *
     * WARNING: This is a bit tricky due to backward compatibility issues. Prior to
     * candlepin 2.0, pools serialized a collection of disjoint provided product info,
     * an object with just a product ID and name, not directly linked to anything in the db.
     *
     * In candlepin 2.0 we have referential integrity and links to full product objects,
     * but we need to maintain both API and import compatibility with old manifests and
     * servers that may import new manifests.
     *
     * To do this, we serialize the providedProductDtos and derivedProvidedProductDtos
     * collections on pool which keeps the API/manifest JSON identical to what it was
     * before. On import we load into these transient collections, and here we transfer
     * to the actual persisted location.
     */
public void associateProvidedProducts(Map<String, ProductDTO> productsById, Entitlement entitlement, Subscription subscription) throws SyncDataFormatException {
    // Associate main provided products:
    Set<ProductData> providedProducts = new HashSet<>();
    entitlement.getPool().populateAllTransientProvidedProducts(productCurator);
    for (ProvidedProduct providedProduct : entitlement.getPool().getProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, providedProduct.getProductId());
        providedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setProvidedProducts(providedProducts);
    // Associate derived provided products:
    Set<ProductData> derivedProvidedProducts = new HashSet<>();
    for (ProvidedProduct pp : entitlement.getPool().getDerivedProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, pp.getProductId());
        derivedProvidedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setDerivedProvidedProducts(derivedProvidedProducts);
    log.debug("Subscription has {} provided products.", derivedProvidedProducts.size());
    log.debug("Subscription has {} derived provided products.", derivedProvidedProducts.size());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) ProvidedProduct(org.candlepin.model.ProvidedProduct) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet)

Aggregations

ProductDTO (org.candlepin.dto.api.v1.ProductDTO)29 Product (org.candlepin.model.Product)27 Test (org.junit.Test)27 Owner (org.candlepin.model.Owner)25 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)12 Content (org.candlepin.model.Content)10 ProductContent (org.candlepin.model.ProductContent)9 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)7 Parameters (junitparams.Parameters)6 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)6 Transactional (com.google.inject.persist.Transactional)5 Reader (java.io.Reader)5 StringReader (java.io.StringReader)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 Subscription (org.candlepin.model.dto.Subscription)4 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)3