Search in sources :

Example 31 with ContentDTO

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

the class OwnerContentResourceTest method testUpdateContentThrowsExceptionWhenOwnerDoesNotExist.

@Test(expected = NotFoundException.class)
public void testUpdateContentThrowsExceptionWhenOwnerDoesNotExist() {
    ContentDTO cdto = TestUtil.createContentDTO("test_content");
    this.ownerContentResource.updateContent("fake_owner_key", cdto.getId(), cdto);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Test(org.junit.Test)

Example 32 with ContentDTO

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

the class OwnerContentResourceTest method updateContent.

@Test
public void updateContent() {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    ContentDTO output = this.ownerContentResource.updateContent(owner.getKey(), cdto.getId(), cdto);
    assertNotNull(output);
    assertEquals(cdto.getId(), output.getId());
    assertEquals(cdto.getName(), output.getName());
    Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
    assertNotNull(entity);
    assertEquals(cdto.getName(), entity.getName());
}
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 ContentDTO

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

the class ProductImporterTest method testVendorSetToUnknown.

@Test
public void testVendorSetToUnknown() throws Exception {
    Product product = TestUtil.createProduct();
    addNoVendorContentTo(product);
    String json = getJsonForProduct(product);
    Reader reader = new StringReader(json);
    ProductDTO created = importer.createObject(mapper, reader, owner);
    ContentDTO c = created.getProductContent().iterator().next().getContent();
    assertEquals("unknown", c.getVendor());
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) StringReader(java.io.StringReader) Product(org.candlepin.model.Product) Reader(java.io.Reader) StringReader(java.io.StringReader) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) Test(org.junit.Test)

Example 34 with ContentDTO

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

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

the class ProductDTOTranslator method populate.

/**
 * {@inheritDoc}
 *
 * <p>Note: the 'locked' field is always set to false and the 'href' field is not translated,
 * since these fields are not currently being exported.</p>
 */
@Override
public ProductData populate(ModelTranslator modelTranslator, ProductDTO source, ProductData dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest is null");
    }
    dest.setCreated(source.getCreated());
    dest.setUpdated(source.getUpdated());
    dest.setUuid(source.getUuid());
    dest.setId(source.getId());
    dest.setName(source.getName());
    dest.setMultiplier(source.getMultiplier());
    dest.setAttributes(source.getAttributes());
    dest.setDependentProductIds(source.getDependentProductIds());
    // We manually set this to false since it is not included in the exported data.
    dest.setLocked(false);
    Collection<ProductDTO.ProductContentDTO> productContentDTOs = source.getProductContent();
    dest.setProductContent(Collections.emptyList());
    if (modelTranslator != null && productContentDTOs != null) {
        ObjectTranslator<ContentDTO, ContentData> contentDTOTranslator = modelTranslator.findTranslatorByClass(ContentDTO.class, ContentData.class);
        for (ProductDTO.ProductContentDTO pcdto : productContentDTOs) {
            if (pcdto != null && pcdto.getContent() != null) {
                ContentData contentData = contentDTOTranslator.translate(modelTranslator, pcdto.getContent());
                dest.addContent(contentData, pcdto.isEnabled());
            }
        }
    }
    return dest;
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ContentData(org.candlepin.model.dto.ContentData) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Aggregations

ContentDTO (org.candlepin.dto.api.v1.ContentDTO)35 Test (org.junit.Test)28 Owner (org.candlepin.model.Owner)26 Content (org.candlepin.model.Content)25 Product (org.candlepin.model.Product)13 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)7 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)7 ProductContent (org.candlepin.model.ProductContent)7 LinkedList (java.util.LinkedList)5 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)5 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)5 Transactional (com.google.inject.persist.Transactional)4 Parameters (junitparams.Parameters)4 ContentData (org.candlepin.model.dto.ContentData)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)3 ProductContentData (org.candlepin.model.dto.ProductContentData)3