Search in sources :

Example 71 with Content

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);
}
Also used : HashMap(java.util.HashMap) Content(org.candlepin.model.Content) Matchers.anyString(org.mockito.Matchers.anyString)

Example 72 with Content

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);
    }
}
Also used : ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContentDTO(org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO) ProductContent(org.candlepin.model.ProductContent)

Example 73 with Content

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);
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 74 with Content

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);
    }
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 75 with Content

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);
    }
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) 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