Search in sources :

Example 96 with Content

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));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 97 with Content

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));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Aggregations

Content (org.candlepin.model.Content)97 Test (org.junit.Test)45 ProductContent (org.candlepin.model.ProductContent)41 Product (org.candlepin.model.Product)40 Owner (org.candlepin.model.Owner)39 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)25 HashMap (java.util.HashMap)18 EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)11 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)10 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)9 Transactional (com.google.inject.persist.Transactional)8 Produces (javax.ws.rs.Produces)8 Parameters (junitparams.Parameters)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)7 Path (javax.ws.rs.Path)6 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)6