Search in sources :

Example 31 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ContentManagerTest method testCreateContentThatAlreadyExists.

@Test(expected = IllegalStateException.class)
public void testCreateContentThatAlreadyExists() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    ContentDTO dto = TestUtil.createContentDTO("c1", "content-1");
    dto.setLabel("test-label");
    dto.setType("test-test");
    dto.setVendor("test-vendor");
    Content output = this.contentManager.createContent(dto, owner);
    // Verify the creation worked
    assertNotNull(output);
    assertEquals(output, this.ownerContentCurator.getContentById(owner, dto.getId()));
    // This should fail, since it already exists
    this.contentManager.createContent(dto, owner);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 32 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ContentManagerTest method testCreateContentMergeWithExisting.

@Test
public void testCreateContentMergeWithExisting() {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Content content1 = TestUtil.createContent("c1", "content-1");
    Content content2 = this.createContent("c1", "content-1", owner2);
    ContentDTO cdto = this.modelTranslator.translate(content1, ContentDTO.class);
    Content output = this.contentManager.createContent(cdto, owner1);
    assertEquals(content2.getUuid(), output.getUuid());
    assertEquals(content2, output);
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(output, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(output, owner2));
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 33 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ContentManagerTest method testUpdateContentDivergeFromExisting.

@Test
@Parameters({ "false", "true" })
public void testUpdateContentDivergeFromExisting(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", "product-1", owner1);
    Content content = this.createContent("c1", "content-1", owner1, owner2);
    ContentDTO update = TestUtil.createContentDTO("c1", "updated content");
    product.addContent(content, true);
    product = this.productCurator.merge(product);
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner2));
    Content output = this.contentManager.updateContent(update, owner1, regenCerts);
    assertNotEquals(output.getUuid(), content.getUuid());
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(output, owner1));
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(output, owner2));
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, 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) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 34 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ContentManagerTest method testCreateContent.

@Test
public void testCreateContent() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    ContentDTO dto = TestUtil.createContentDTO("c1", "content-1");
    dto.setLabel("test-label");
    dto.setType("test-test");
    dto.setVendor("test-vendor");
    assertNull(this.ownerContentCurator.getContentById(owner, dto.getId()));
    Content output = this.contentManager.createContent(dto, owner);
    assertEquals(output, this.ownerContentCurator.getContentById(owner, dto.getId()));
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 35 with Content

use of org.candlepin.model.Content in project candlepin by candlepin.

the class ContentManagerTest method testUpdateContentNoChange.

@Test
public void testUpdateContentNoChange() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "product-1", owner);
    Content content = this.createContent("c1", "content-1", owner);
    product.addContent(content, true);
    product = this.productCurator.merge(product);
    ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
    Content output = this.contentManager.updateContent(cdto, owner, true);
    assertEquals(output.getUuid(), content.getUuid());
    assertEquals(output, content);
    verifyZeroInteractions(this.mockEntCertGenerator);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) 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