use of org.candlepin.model.ProductContent 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.getMultiplier(), dto.getMultiplier());
assertEquals(source.getId(), dto.getId());
assertEquals(source.getName(), dto.getName());
assertEquals(source.getAttributes(), dto.getAttributes());
assertEquals(source.getDependentProductIds(), dto.getDependentProductIds());
assertNotNull(dto.getProductContent());
if (childrenGenerated) {
for (ProductContent pc : source.getProductContent()) {
for (ProductDTO.ProductContentDTO pcdto : dto.getProductContent()) {
Content content = pc.getContent();
ContentDTO cdto = pcdto.getContent();
assertNotNull(cdto);
assertNotNull(cdto.getId());
if (cdto.getId().equals(content.getId())) {
assertEquals(pc.isEnabled(), pcdto.isEnabled());
// Pass the content off to the ContentTranslatorTest to verify it
this.contentTranslatorTest.verifyOutput(content, cdto, true);
}
}
}
} else {
assertTrue(dto.getProductContent().isEmpty());
}
} else {
assertNull(dto);
}
}
use of org.candlepin.model.ProductContent in project candlepin by candlepin.
the class X509V3ExtensionUtilTest method testPrefixLogic.
@Test
public void testPrefixLogic() {
Owner owner = new Owner("Test Corporation");
Product p = new Product("JarJar", "Binks");
Content c = new Content();
c.setContentUrl("/some/path");
ProductContent pc = new ProductContent(p, c, true);
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
c.setContentUrl("some/path");
assertEquals("/some/path", util.createFullContentPath(null, pc));
assertEquals("/some/path", util.createFullContentPath("", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
c.setContentUrl("///////some/path");
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
assertEquals("/some/path", util.createFullContentPath(null, pc));
assertEquals("/some/path", util.createFullContentPath("", pc));
c.setContentUrl("http://some/path");
assertEquals("http://some/path", util.createFullContentPath("/this/is", pc));
c.setContentUrl("https://some/path");
assertEquals("https://some/path", util.createFullContentPath("/this/is", pc));
c.setContentUrl("ftp://some/path");
assertEquals("ftp://some/path", util.createFullContentPath("/this/is", pc));
c.setContentUrl("file://some/path");
assertEquals("file://some/path", util.createFullContentPath("/this/is", pc));
}
use of org.candlepin.model.ProductContent in project candlepin by candlepin.
the class X509Util method filterProductContent.
/**
* Scan the product content looking for any we should filter out.
*
* Will filter out any content which modifies another product if the consumer does
* not have an entitlement granting them access to that product.
*
* Will also filter out any content not promoted to the consumer's environment
* if environment filtering is enabled.
*
* @param prod the product who's content we should filter
* @param promotedContent
* @param filterEnvironment show content also be filtered by environment.
* @return ProductContent to include in the certificate.
*/
public Set<ProductContent> filterProductContent(Product prod, Consumer consumer, Map<String, EnvironmentContent> promotedContent, boolean filterEnvironment, Set<String> entitledProductIds) {
Set<ProductContent> filtered = new HashSet<>();
for (ProductContent pc : prod.getProductContent()) {
// Filter any content not promoted to environment.
if (filterEnvironment && consumer.getEnvironmentId() != null && !promotedContent.containsKey(pc.getContent().getId())) {
log.debug("Skipping content not promoted to environment: {}" + pc.getContent());
continue;
}
boolean include = true;
if (pc.getContent().getModifiedProductIds().size() > 0) {
include = false;
Set<String> prodIds = pc.getContent().getModifiedProductIds();
// we will include this content set:
for (String prodId : prodIds) {
if (entitledProductIds.contains(prodId)) {
include = true;
break;
}
}
}
if (include) {
filtered.add(pc);
}
}
return filtered;
}
use of org.candlepin.model.ProductContent in project candlepin by candlepin.
the class X509V3ExtensionUtil method filterProductContent.
/**
* Scan the product content looking for any which modify some other product. If found
* we must check that this consumer has another entitlement granting them access
* to that modified product. If they do not, we should filter out this content.
*
* @param prod
* @return ProductContent to include in the certificate.
*/
public Set<ProductContent> filterProductContent(Product prod, Set<String> entitledProductIds) {
Set<ProductContent> filtered = new HashSet<>();
for (ProductContent pc : prod.getProductContent()) {
boolean include = true;
if (pc.getContent().getModifiedProductIds().size() > 0) {
include = false;
Set<String> prodIds = pc.getContent().getModifiedProductIds();
// we will include this content set
for (String prodId : prodIds) {
if (entitledProductIds.contains(prodId)) {
include = true;
break;
}
}
}
if (include) {
filtered.add(pc);
} else {
log.debug("No entitlements found for modified products.");
log.debug("Skipping content set: " + pc.getContent());
}
}
return filtered;
}
use of org.candlepin.model.ProductContent in project candlepin by candlepin.
the class ProductDataTest method testPopulateByEntityWithContent.
@Test
public void testPopulateByEntityWithContent() {
ProductData base = new ProductData();
Product source = new Product();
Content[] contentEntities = new Content[] { new Content("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new Content("c2", "content-2", "test_type", "test_label-2", "test_vendor-2"), new Content("c3", "content-3", "test_type", "test_label-3", "test_vendor-3") };
ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
ProductContent pcentity3 = new ProductContent(null, contentEntities[2], true);
ProductContentData pcdata1 = pcentity1.toDTO();
ProductContentData pcdata2 = pcentity2.toDTO();
ProductContentData pcdata3 = pcentity3.toDTO();
source.setProductContent(Arrays.asList(pcentity1, pcentity2, pcentity3));
// Verify base state
assertNull(base.getUuid());
assertNull(base.getId());
assertNull(base.getName());
assertNull(base.getMultiplier());
assertNull(base.getAttributes());
assertNull(base.getProductContent());
assertNull(base.getDependentProductIds());
assertNull(base.getHref());
assertNull(base.isLocked());
base.populate(source);
// Verify populated state
assertNull(base.getUuid());
assertNull(base.getId());
assertNull(base.getName());
assertNull(base.getMultiplier());
assertNull(base.getHref());
// Note: entities are always locked or unlocked, so this can never be null following a
// populate.
assertFalse(base.isLocked());
// Note: by default, entities have empty collections (NOT null, as was the case before
// DTOs). As a result, these will never be null after a populate.
assertNotNull(base.getAttributes());
assertTrue(base.getAttributes().isEmpty());
assertNotNull(base.getDependentProductIds());
assertTrue(base.getDependentProductIds().isEmpty());
assertNotNull(base.getProductContent());
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata2, pcdata3), base.getProductContent()));
}
Aggregations