Search in sources :

Example 76 with Content

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

the class ProductManagerTest method testUpdateProductContentOnSharedProduct.

// Move this to ContentManagerTest
@Test
public void testUpdateProductContentOnSharedProduct() {
    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);
    product.setProductContent(Arrays.asList(new ProductContent(product, content, true)));
    this.productCurator.merge(product);
    ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
    pdto.getProductContent(content.getId()).setEnabled(false);
    Product output = this.productManager.updateProduct(pdto, owner1, false);
    assertNotEquals(product, output);
    assertTrue(product.hasContent(content.getId()));
    assertTrue(output.hasContent(content.getId()));
    assertTrue(product.getProductContent().iterator().next().isEnabled());
    assertFalse(output.getProductContent().iterator().next().isEnabled());
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
    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) ProductContent(org.candlepin.model.ProductContent) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 77 with Content

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

the class ContentTranslatorTest method initSourceObject.

@Override
protected Content initSourceObject() {
    Content source = new Content();
    source.setUuid("test_value");
    source.setId("test_value");
    source.setType("test_value");
    source.setLabel("test_value");
    source.setName("test_value");
    source.setVendor("test_value");
    source.setContentUrl("test_value");
    source.setRequiredTags("test_value");
    source.setReleaseVersion("test_value");
    source.setGpgUrl("test_value");
    source.setMetadataExpire(1234L);
    source.setModifiedProductIds(Arrays.asList("1", "2", "3"));
    source.setArches("test_value");
    source.setLocked(Boolean.TRUE);
    return source;
}
Also used : Content(org.candlepin.model.Content)

Example 78 with Content

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

the class EnvironmentTranslatorTest method initSourceObject.

@Override
protected Environment initSourceObject() {
    Environment source = new Environment();
    source.setId("test_id");
    source.setName("test_name");
    source.setDescription("test_description");
    source.setOwner(ownerTranslatorTest.initSourceObject());
    Set<EnvironmentContent> environmentContents = new HashSet<>();
    for (int i = 0; i < 3; ++i) {
        Content content = TestUtil.createContent("content-" + i);
        content.setUuid(content.getId() + "_uuid");
        EnvironmentContent environmentContent = new EnvironmentContent(source, content, true);
        environmentContents.add(environmentContent);
    }
    source.setEnvironmentContent(environmentContents);
    return source;
}
Also used : EnvironmentContent(org.candlepin.model.EnvironmentContent) Content(org.candlepin.model.Content) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent) HashSet(java.util.HashSet)

Example 79 with Content

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

the class ContentManagerTest method testRemoveContentThatDoesntExist.

@Test(expected = IllegalStateException.class)
public void testRemoveContentThatDoesntExist() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Content content = TestUtil.createContent("c1", "content-1");
    assertFalse(this.ownerContentCurator.isContentMappedToOwner(content, owner));
    this.contentManager.removeContent(owner, content, true);
}
Also used : Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 80 with Content

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

the class ContentManagerTest method testUpdateContent.

@Test
@Parameters({ "false", "true" })
public void testUpdateContent(boolean regenCerts) {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "product-1", owner);
    Content content = this.createContent("c1", "content-1", owner);
    ContentDTO update = TestUtil.createContentDTO("c1", "new content name");
    product.addContent(content, true);
    product = this.productCurator.merge(product);
    Content output = this.contentManager.updateContent(update, owner, regenCerts);
    assertNotEquals(output.getUuid(), content.getUuid());
    assertEquals(output.getName(), update.getName());
    // We expect the original to be kept around as an orphan until the orphan removal job
    // gets around to removing them
    assertNotNull(this.contentCurator.find(content.getUuid()));
    assertEquals(0, this.ownerContentCurator.getOwnerCount(content));
    assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
    // The product should have also changed in the same way as a result of the content change
    assertNotNull(this.productCurator.find(product.getUuid()));
    assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
    assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
    if (regenCerts) {
        verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner)), 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)

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