use of org.candlepin.dto.api.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());
}
use of org.candlepin.dto.api.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);
}
use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.
the class ProductDataTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(ProductData source, ProductDTO dto, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getUuid(), dto.getUuid());
assertEquals(source.getId(), dto.getId());
assertEquals(source.getName(), dto.getName());
assertEquals(source.getMultiplier(), dto.getMultiplier());
assertEquals(source.getAttributes(), dto.getAttributes());
assertEquals(source.getDependentProductIds(), dto.getDependentProductIds());
assertEquals(source.isLocked(), dto.isLocked());
assertEquals(source.getHref(), dto.getHref());
if (childrenGenerated) {
assertNotNull(dto.getProductContent());
for (ProductContentData pc : source.getProductContent()) {
for (ProductContentDTO pcdto : dto.getProductContent()) {
ContentData content = pc.getContent();
ContentDTO cdto = pcdto.getContent();
assertNotNull(cdto);
assertNotNull(cdto.getUuid());
if (cdto.getUuid().equals(content.getUuid())) {
assertEquals(pc.isEnabled(), pcdto.isEnabled());
// Pass the content off to the ContentTranslatorTest to verify it
this.contentDataTranslatorTest.verifyOutput(content, cdto, childrenGenerated);
}
}
}
} else {
assertNull(dto.getProductContent());
}
} else {
assertNull(dto);
}
}
use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.
the class ContentResourceTest method testUpdateContentNoLongerSupported.
@Test(expected = BadRequestException.class)
public void testUpdateContentNoLongerSupported() {
final String contentId = "10";
ContentDTO contentDTO = mock(ContentDTO.class);
cr.updateContent(contentId, contentDTO);
verify(cc, never()).find(any());
verify(cc, never()).merge(any());
verify(productCurator, never()).getProductsByContent(any(), any());
}
use of org.candlepin.dto.api.v1.ContentDTO in project candlepin by candlepin.
the class ContentResourceTest method getContent.
@Test
public void getContent() {
Owner owner = mock(Owner.class);
Content content = mock(Content.class);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
ContentDTO expected = this.modelTranslator.translate(content, ContentDTO.class);
when(cqmock.list()).thenReturn(Arrays.asList(owner));
when(oc.listAll()).thenReturn(cqmock);
when(cc.lookupByUuid(eq("10"))).thenReturn(content);
ContentDTO output = cr.getContent("10");
assertEquals(expected, output);
}
Aggregations