use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class ProductManagerTest method testUpdateProductThatDoesntExist.
@Test(expected = IllegalStateException.class)
public void testUpdateProductThatDoesntExist() {
Owner owner = this.createOwner("test-owner", "Test Owner");
Product product = TestUtil.createProduct("p1", "new_name");
ProductDTO update = TestUtil.createProductDTO("p1", "new_name");
assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner));
this.productManager.updateProduct(update, owner, false);
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class ProductManagerTest method testCreateProductMergeWithExisting.
@Test
public void testCreateProductMergeWithExisting() {
Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
Product product1 = TestUtil.createProduct("p1", "prod1");
Product product2 = this.createProduct("p1", "prod1", owner2);
ProductDTO pdto = this.modelTranslator.translate(product1, ProductDTO.class);
Product output = this.productManager.createProduct(pdto, owner1);
assertEquals(output.getUuid(), product2.getUuid());
assertEquals(output, product2);
assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
}
use of org.candlepin.dto.manifest.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.manifest.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.manifest.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);
}
Aggregations