Search in sources :

Example 31 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductManagerTest method testUpdateProductThatDoesntExist.

@Test(expected = IllegalStateException.class)
public void testUpdateProductThatDoesntExist() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct("p1", "new_name");
    ProductDTO update = TestUtil.createProductDTO("p1", "new_name");
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner));
    this.productManager.updateProduct(update, owner, false);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 32 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.

the class ProductManagerTest method testCreateProductMergeWithExisting.

@Test
public void testCreateProductMergeWithExisting() {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Product product1 = TestUtil.createProduct("p1", "prod1");
    Product product2 = this.createProduct("p1", "prod1", owner2);
    ProductDTO pdto = this.modelTranslator.translate(product1, ProductDTO.class);
    Product output = this.productManager.createProduct(pdto, owner1);
    assertEquals(output.getUuid(), product2.getUuid());
    assertEquals(output, product2);
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 33 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO 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 34 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO 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)

Example 35 with ProductDTO

use of org.candlepin.dto.manifest.v1.ProductDTO 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)

Aggregations

ProductDTO (org.candlepin.dto.api.v1.ProductDTO)29 Product (org.candlepin.model.Product)27 Test (org.junit.Test)27 Owner (org.candlepin.model.Owner)25 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)12 Content (org.candlepin.model.Content)10 ProductContent (org.candlepin.model.ProductContent)9 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)7 Parameters (junitparams.Parameters)6 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)6 Transactional (com.google.inject.persist.Transactional)5 Reader (java.io.Reader)5 StringReader (java.io.StringReader)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 Subscription (org.candlepin.model.dto.Subscription)4 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)3