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);
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations