Search in sources :

Example 81 with Content

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

the class ContentManagerTest method testUpdateContentConvergeWithExisting.

@Test
@Parameters({ "false", "true" })
public void testUpdateContentConvergeWithExisting(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 content1 = this.createContent("c1", "content-1", owner1);
    Content content2 = this.createContent("c1", "updated content", owner2);
    ContentDTO update = TestUtil.createContentDTO("c1", "updated content");
    product.addContent(content1, true);
    product = this.productCurator.merge(product);
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content1, owner1));
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content2, owner1));
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner2));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, owner2));
    Content output = this.contentManager.updateContent(update, owner1, regenCerts);
    assertEquals(content2.getUuid(), output.getUuid());
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, owner1));
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content1, owner2));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content2, 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 82 with Content

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

the class ContentManagerTest method testRemoveContent.

@Test
@Parameters({ "false", "true" })
public void testRemoveContent(boolean regenCerts) {
    Owner owner = this.createOwner("test-owner-1", "Test Owner 1");
    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);
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner));
    try {
        this.beginTransaction();
        this.contentManager.removeContent(owner, content, regenCerts);
        this.commitTransaction();
    } catch (RuntimeException e) {
        this.rollbackTransaction();
    }
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner));
    assertNotNull(this.contentCurator.find(content.getUuid()));
    assertEquals(0, this.ownerContentCurator.getOwnerCount(content));
    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) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 83 with Content

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

the class ContentManagerTest method testUpdateContentThatDoesntExist.

@Test(expected = IllegalStateException.class)
public void testUpdateContentThatDoesntExist() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Content content = TestUtil.createContent("c1", "content-1");
    ContentDTO update = TestUtil.createContentDTO("c1", "new_name");
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner));
    this.contentManager.updateContent(update, owner, false);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 84 with Content

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

the class ContentManagerTest method testRemoveContentDivergeFromExisting.

@Test
@Parameters({ "false", "true" })
public void testRemoveContentDivergeFromExisting(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, owner2);
    Content content = this.createContent("c1", "content-1", owner1, owner2);
    product.addContent(content, true);
    product = this.productCurator.merge(product);
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner2));
    try {
        this.beginTransaction();
        this.contentManager.removeContent(owner1, content, regenCerts);
        this.commitTransaction();
    } catch (RuntimeException e) {
        this.rollbackTransaction();
    }
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner1));
    assertTrue(this.ownerContentCurator.isContentMappedToOwner(content, owner2));
    assertNotNull(this.contentCurator.find(content.getUuid()));
    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) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 85 with Content

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

the class EntitlerTest 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)

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