use of org.candlepin.model.Content in project candlepin by candlepin.
the class PoolManagerTest method mockContentImport.
private void mockContentImport(Owner owner, Content... contents) {
Map<String, Content> contentMap = new HashMap<>();
for (Content content : contents) {
contentMap.put(content.getId(), content);
}
this.mockContentImport(owner, contentMap);
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Product source, ProductDTO 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());
assertEquals(source.isLocked(), dto.isLocked());
assertEquals(source.getHref(), dto.getHref());
assertNotNull(dto.getProductContent());
if (childrenGenerated) {
for (ProductContent pc : source.getProductContent()) {
for (ProductContentDTO pcdto : dto.getProductContent()) {
Content content = pc.getContent();
ContentDTO cdto = pcdto.getContent();
assertNotNull(cdto);
assertNotNull(cdto.getUuid());
if (cdto.getUuid().equals(content.getUuid())) {
assertEquals(pc.isEnabled(), pcdto.isEnabled());
// Pass the content off to the ContentTranslatorTest to verify it
this.contentTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
}
}
}
} else {
assertTrue(dto.getProductContent().isEmpty());
}
} else {
assertNull(dto);
}
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductManagerTest method testAddContentToSharedProduct.
@Test
@Parameters({ "false", "true" })
public void testAddContentToSharedProduct(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);
Content content = this.createContent("c1", "content1", owner1);
this.ownerProductCurator.mapProductToOwners(product, owner1, owner2);
ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
pdto.addContent(cdto, true);
Product output = this.productManager.updateProduct(pdto, owner1, regenCerts);
assertNotEquals(product, output);
assertFalse(product.hasContent(content.getId()));
assertTrue(output.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.model.Content 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.model.Content 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);
}
}
Aggregations