use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductDataTest method testAddContentByEntity.
@Test
public void testAddContentByEntity() {
ProductData dto = new ProductData();
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") };
ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
ProductContent pcentity3 = new ProductContent(null, contentEntities[1], true);
ContentData[] content = new ContentData[] { contentEntities[0].toDTO(), contentEntities[1].toDTO() };
ProductContentData pcdata1 = new ProductContentData(content[0], true);
ProductContentData pcdata2 = new ProductContentData(content[1], false);
ProductContentData pcdata3 = new ProductContentData(content[1], true);
assertNull(dto.getProductContent());
boolean output = dto.addContent(pcentity1.getContent(), pcentity1.isEnabled());
Collection<ProductContentData> output2 = dto.getProductContent();
assertTrue(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
output = dto.addContent(pcentity1.getContent(), pcentity1.isEnabled());
output2 = dto.getProductContent();
assertFalse(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
output = dto.addContent(pcentity2.getContent(), pcentity2.isEnabled());
output2 = dto.getProductContent();
assertTrue(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata2), output2));
output = dto.addContent(pcentity3.getContent(), pcentity3.isEnabled());
output2 = dto.getProductContent();
assertTrue(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata3), output2));
}
use of org.candlepin.model.Content in project candlepin by candlepin.
the class ProductDataTest method testRemoveProductContentByEntity.
@Test
public void testRemoveProductContentByEntity() {
ProductData dto = new ProductData();
ContentData[] content = new ContentData[] { new ContentData("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new ContentData("c2", "content-2", "test_type", "test_label-2", "test_vendor-2") };
ProductContentData pcdata1 = new ProductContentData(content[0], true);
ProductContentData pcdata2 = new ProductContentData(content[1], false);
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("c2", "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);
assertNull(dto.getProductContent());
assertFalse(dto.removeProductContent(pcentity1));
assertFalse(dto.removeProductContent(pcentity2));
assertFalse(dto.removeProductContent(pcentity3));
dto.setProductContent(Arrays.asList(pcdata1, pcdata2));
boolean output = dto.removeProductContent(pcentity1);
Collection<ProductContentData> output2 = dto.getProductContent();
assertTrue(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata2), output2));
output = dto.removeProductContent(pcentity1);
output2 = dto.getProductContent();
assertFalse(output);
assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata2), output2));
// This should work because we remove by content ID, not by exact element match
// Note that the collection should not be nulled by removing the final element
output = dto.removeProductContent(pcentity3);
output2 = dto.getProductContent();
assertTrue(output);
assertTrue(Util.collectionsAreEqual(Collections.<ProductContentData>emptyList(), output2));
}
Aggregations