Search in sources :

Example 16 with ContentDTO

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

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

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

Example 19 with ContentDTO

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

the class ProductResourceTest method testCreateProductWithContent.

@Test(expected = BadRequestException.class)
public void testCreateProductWithContent() {
    Owner owner = this.createOwner("Example-Corporation");
    ProductDTO pdto = this.buildTestProductDTO();
    ContentDTO cdto = TestUtil.createContentDTO();
    pdto.addContent(cdto, true);
    assertNull(this.ownerProductCurator.getProductById(owner.getKey(), pdto.getId()));
    ProductDTO result = productResource.createProduct(pdto);
    Product entity = this.ownerProductCurator.getProductById(owner.getKey(), pdto.getId());
    ProductDTO expected = this.modelTranslator.translate(entity, ProductDTO.class);
    assertNotNull(entity);
    assertEquals(expected, result);
    assertNotNull(result.getProductContent());
    assertEquals(1, result.getProductContent().size());
    assertEquals(cdto, result.getProductContent().iterator().next().getContent());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 20 with ContentDTO

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

the class OwnerProductResource method addBatchContent.

@ApiOperation(notes = "Adds one or more Content entities to a Product", value = "addBatchContent")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, @ApiParam(name = "contentMap", required = true) Map<String, Boolean> contentMap) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Product product = this.fetchProduct(owner, productId);
    Collection<ProductContent> productContent = new LinkedList<>();
    if (product.isLocked()) {
        throw new ForbiddenException(i18n.tr("product \"{0}\" is locked", product.getId()));
    }
    this.productCurator.lock(product);
    ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
    // Impl note:
    // This is a wholely inefficient way of doing this. When we return to using ID-based linking
    // and we're not linking the universe with our model, we can just attach the IDs directly
    // without needing all this DTO conversion back and forth.
    // Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
    // calling commit methods as necessary so we don't have to work with DTOs internally.
    boolean changed = false;
    for (Entry<String, Boolean> entry : contentMap.entrySet()) {
        Content content = this.fetchContent(owner, entry.getKey());
        boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
        ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
        changed |= pdto.addContent(cdto, enabled);
    }
    if (changed) {
        product = this.productManager.updateProduct(pdto, owner, true);
    }
    return this.translator.translate(product, ProductDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) LinkedList(java.util.LinkedList) ContentDTO(org.candlepin.dto.api.v1.ContentDTO) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) Transactional(com.google.inject.persist.Transactional)

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