Search in sources :

Example 36 with ProductDTO

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

the class ProductManagerTest method testRemoveContentFromSharedProduct.

@Test
@Parameters({ "false", "true" })
public void testRemoveContentFromSharedProduct(boolean regenCerts) {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Product product = TestUtil.createProduct("p1", "prod1");
    Content content = TestUtil.createContent("c1");
    product.addContent(content, true);
    content = this.contentCurator.create(content);
    product = this.productCurator.create(product);
    this.ownerProductCurator.mapProductToOwners(product, owner1, owner2);
    this.ownerContentCurator.mapContentToOwner(content, owner1);
    ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
    boolean removed = pdto.removeContent(content.getId());
    assertTrue(removed);
    Product output = this.productManager.updateProduct(pdto, owner1, regenCerts);
    assertNotEquals(product, output);
    assertFalse(output.hasContent(content.getId()));
    assertTrue(product.hasContent(content.getId()));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, 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) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 37 with ProductDTO

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

the class ProductManagerTest method testRemoveProductContent.

@Test
@Parameters({ "false", "true" })
public void testRemoveProductContent(boolean regenCerts) {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct("p1", "prod1");
    Content content = TestUtil.createContent("c1");
    product.addContent(content, true);
    this.contentCurator.create(content);
    this.productCurator.create(product);
    this.ownerProductCurator.mapProductToOwners(product, owner);
    this.ownerContentCurator.mapContentToOwner(content, owner);
    ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
    boolean removed = pdto.removeContent(content.getId());
    assertTrue(removed);
    Product output = this.productManager.updateProduct(pdto, owner, regenCerts);
    assertFalse(output.hasContent(content.getId()));
    // When we change the content associated with a product, we're making a net change to the
    // product itself, which should trigger the creation of a new product object (since reuse
    // is currently disabled). The old product will still, temporarily, exist as an orphan
    // until the orphan cleanup job has a chance to run and remove them.
    assertNotNull(this.productCurator.find(product.getUuid()));
    assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
    assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
    assertNotNull(this.contentCurator.find(content.getUuid()));
    if (regenCerts) {
        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) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 38 with ProductDTO

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

the class ProductManagerTest method testUpdateProductContentOnSharedProduct.

// Move this to ContentManagerTest
@Test
public void testUpdateProductContentOnSharedProduct() {
    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);
    Content content = this.createContent("c1", "content1", owner1);
    this.ownerProductCurator.mapProductToOwners(product, owner1, owner2);
    product.setProductContent(Arrays.asList(new ProductContent(product, content, true)));
    this.productCurator.merge(product);
    ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
    pdto.getProductContent(content.getId()).setEnabled(false);
    Product output = this.productManager.updateProduct(pdto, owner1, false);
    assertNotEquals(product, output);
    assertTrue(product.hasContent(content.getId()));
    assertTrue(output.hasContent(content.getId()));
    assertTrue(product.getProductContent().iterator().next().isEnabled());
    assertFalse(output.getProductContent().iterator().next().isEnabled());
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
    verifyZeroInteractions(this.mockEntCertGenerator);
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 39 with ProductDTO

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

the class ProductDTOTranslator method populate.

/**
 * {@inheritDoc}
 *
 * <p>Note: the 'locked' field is always set to false and the 'href' field is not translated,
 * since these fields are not currently being exported.</p>
 */
@Override
public ProductData populate(ModelTranslator modelTranslator, ProductDTO source, ProductData dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest is null");
    }
    dest.setCreated(source.getCreated());
    dest.setUpdated(source.getUpdated());
    dest.setUuid(source.getUuid());
    dest.setId(source.getId());
    dest.setName(source.getName());
    dest.setMultiplier(source.getMultiplier());
    dest.setAttributes(source.getAttributes());
    dest.setDependentProductIds(source.getDependentProductIds());
    // We manually set this to false since it is not included in the exported data.
    dest.setLocked(false);
    Collection<ProductDTO.ProductContentDTO> productContentDTOs = source.getProductContent();
    dest.setProductContent(Collections.emptyList());
    if (modelTranslator != null && productContentDTOs != null) {
        ObjectTranslator<ContentDTO, ContentData> contentDTOTranslator = modelTranslator.findTranslatorByClass(ContentDTO.class, ContentData.class);
        for (ProductDTO.ProductContentDTO pcdto : productContentDTOs) {
            if (pcdto != null && pcdto.getContent() != null) {
                ContentData contentData = contentDTOTranslator.translate(modelTranslator, pcdto.getContent());
                dest.addContent(contentData, pcdto.isEnabled());
            }
        }
    }
    return dest;
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Example 40 with ProductDTO

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

the class ProductDataTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ProductDTO populate(ModelTranslator modelTranslator, ProductData source, ProductDTO dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest is null");
    }
    dest.setCreated(source.getCreated());
    dest.setUpdated(source.getUpdated());
    dest.setUuid(source.getUuid());
    dest.setId(source.getId());
    dest.setName(source.getName());
    dest.setMultiplier(source.getMultiplier());
    dest.setAttributes(source.getAttributes());
    dest.setDependentProductIds(source.getDependentProductIds());
    dest.setHref(source.getHref());
    dest.setLocked(source.isLocked());
    Collection<ProductContentData> productContentData = source.getProductContent();
    dest.setProductContent(null);
    if (modelTranslator != null && productContentData != null) {
        ObjectTranslator<ContentData, ContentDTO> contentTranslator = modelTranslator.findTranslatorByClass(ContentData.class, ContentDTO.class);
        for (ProductContentData pcd : productContentData) {
            if (pcd != null && pcd.getContent() != null) {
                ContentDTO dto = contentTranslator.translate(modelTranslator, pcd.getContent());
                dest.addContent(dto, pcd.isEnabled());
            }
        }
    }
    return dest;
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductContentData(org.candlepin.model.dto.ProductContentData) ProductContentData(org.candlepin.model.dto.ProductContentData)

Aggregations

ProductDTO (org.candlepin.dto.api.v1.ProductDTO)29 Product (org.candlepin.model.Product)28 Test (org.junit.Test)27 Owner (org.candlepin.model.Owner)25 Content (org.candlepin.model.Content)15 ProductContent (org.candlepin.model.ProductContent)13 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)12 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)11 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)7 Parameters (junitparams.Parameters)6 Transactional (com.google.inject.persist.Transactional)5 Reader (java.io.Reader)5 LinkedList (java.util.LinkedList)5 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)5 StringReader (java.io.StringReader)4 HashSet (java.util.HashSet)4 Subscription (org.candlepin.model.dto.Subscription)4 HashMap (java.util.HashMap)3 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3