Search in sources :

Example 16 with ContentDTO

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

Example 17 with ContentDTO

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

the class ProductImporter method createObject.

public ProductDTO createObject(ObjectMapper mapper, Reader reader, Owner owner) throws IOException {
    ProductDTO importedProduct = mapper.readValue(reader, ProductDTO.class);
    // Make sure the (UU)ID's are null, otherwise Hibernate thinks these are
    // detached entities.
    importedProduct.setUuid(null);
    // Multiplication has already happened on the upstream candlepin. set this to 1
    // so we can use multipliers on local products if necessary.
    importedProduct.setMultiplier(1L);
    if (importedProduct.getProductContent() != null) {
        // Update attached content and ensure it isn't malformed
        for (ProductDTO.ProductContentDTO pc : importedProduct.getProductContent()) {
            ContentDTO content = pc.getContent();
            // Clear the UUID
            content.setUuid(null);
            // Fix the vendor string if it is/was cleared (BZ 990113)
            if (StringUtils.isBlank(content.getVendor())) {
                content.setVendor("unknown");
            }
            // On standalone servers we will set metadata expire to 1 second so
            // clients an immediately get changes to content when published on the
            // server. We would use 0, but the client plugin interprets this as unset
            // and ignores it completely resulting in the default yum values being
            // used.
            // 
            // We know this is a standalone server due to the fact that import is
            // being used, so there is no need to guard this behavior.
            content.setMetadataExpire(1L);
        }
    }
    return importedProduct;
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO)

Example 18 with ContentDTO

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

the class ContentResourceTest method createContentNoLongerSupported.

@Test(expected = BadRequestException.class)
public void createContentNoLongerSupported() {
    ContentDTO contentDTO = mock(ContentDTO.class);
    assertEquals(contentDTO, cr.createContent(contentDTO));
    verify(cc, never()).create(any());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Test(org.junit.Test)

Example 19 with ContentDTO

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

the class OwnerContentResourceTest method updateContentThatDoesntExist.

@Test(expected = NotFoundException.class)
public void updateContentThatDoesntExist() {
    Owner owner = this.createOwner("test_owner");
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    assertNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    try {
        this.ownerContentResource.updateContent(owner.getKey(), cdto.getId(), cdto);
    } catch (NotFoundException e) {
        assertNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
        throw e;
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Test(org.junit.Test)

Example 20 with ContentDTO

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

the class OwnerContentResourceTest method listContentNoContent.

@Test
public void listContentNoContent() throws Exception {
    Owner owner = this.createOwner("test_owner");
    CandlepinQuery<ContentDTO> response = this.ownerContentResource.listContent(owner.getKey());
    assertNotNull(response);
    Collection<ContentDTO> received = response.list();
    assertEquals(0, received.size());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Aggregations

ContentDTO (org.candlepin.dto.api.v1.ContentDTO)35 Content (org.candlepin.model.Content)30 Test (org.junit.Test)28 Owner (org.candlepin.model.Owner)26 Product (org.candlepin.model.Product)14 ProductContent (org.candlepin.model.ProductContent)9 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)8 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)7 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)7 LinkedList (java.util.LinkedList)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