OwnerContentResource { @ApiOperation(notes = "Creates a Content", value = "createContent") @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public ContentDTO createContent(@PathParam("owner_key") String ownerKey, @ApiParam(name = "content", required = true) ContentDTO content) { Owner owner = this.getOwnerByKey(ownerKey); Content entity = this.createContentImpl(owner, content); this.contentAccessManager.refreshOwnerForContentAccess(owner); return this.translator.translate(entity, ContentDTO.class); } @Inject  OwnerContentResource(ContentCurator contentCurator, ContentManager contentManager,
        EnvironmentContentCurator envContentCurator, I18n i18n, OwnerCurator ownerCurator,
        OwnerContentCurator ownerContentCurator, PoolManager poolManager, ProductCurator productCurator,
        UniqueIdGenerator idGenerator,  ProductCachedSerializationModule productCachedModule,
        ContentAccessManager contentAccessManager, ModelTranslator translator); @ApiOperation(notes = "Retrieves list of Content", value = "list", response = ContentDTO.class, responseContainer = "list") @GET @Produces(MediaType.APPLICATION_JSON) CandlepinQuery<ContentDTO> listContent(
        @Verify(Owner.class) @PathParam("owner_key") String ownerKey); @ApiOperation(notes = "Retrieves a single Content", value = "getContent") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{content_id}") ContentDTO getContent(
        @Verify(Owner.class) @PathParam("owner_key") String ownerKey,
        @PathParam("content_id") String contentId); @ApiOperation(notes = "Creates a Content", value = "createContent") @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) ContentDTO createContent(@PathParam("owner_key") String ownerKey,
        @ApiParam(name = "content", required = true) ContentDTO content); @ApiOperation(notes = "Creates Contents in bulk", value = "createBatchContent") @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/batch") @Transactional Collection<ContentDTO> createBatchContent(@PathParam("owner_key") String ownerKey,
        @ApiParam(name = "contents", required = true) List<ContentDTO> contents); @ApiOperation(notes = "Updates a Content", value = "updateContent") @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/{content_id}") ContentDTO updateContent(@PathParam("owner_key") String ownerKey,
        @PathParam("content_id") String contentId,
        @ApiParam(name = "content", required = true) ContentDTO content); @ApiOperation(notes = "Deletes a Content", value = "remove") @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("/{content_id}") void remove(@PathParam("owner_key") String ownerKey,
        @PathParam("content_id") String contentId);  }
@Test public void createContent() { Owner owner = this.createOwner("test_owner"); ContentDTO cdto = TestUtil.createContentDTO("test_content"); cdto.setLabel("test-label"); cdto.setType("test-test"); cdto.setVendor("test-vendor"); assertNull(this.ownerContentCurator.getContentById(owner, cdto.getId())); ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), cdto); assertNotNull(output); assertEquals(cdto.getId(), output.getId()); Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId()); assertNotNull(entity); assertEquals(cdto.getName(), entity.getName()); assertEquals(cdto.getLabel(), entity.getLabel()); assertEquals(cdto.getType(), entity.getType()); assertEquals(cdto.getVendor(), entity.getVendor()); }
@Test public void createContentWhenContentAlreadyExists() { Owner owner = this.createOwner("test_owner"); Content content = this.createContent("test_content", "test_content", owner); ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name"); cdto.setLabel("test-label"); cdto.setType("test-test"); cdto.setVendor("test-vendor"); assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId())); ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), 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()); }
@Test public void createContentWhenContentAlreadyExistsAndLocked() { Owner owner = this.createOwner("test_owner"); Content content = this.createContent("test_content", "test_content", owner); ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name"); cdto.setLabel("test-label"); cdto.setType("test-test"); cdto.setVendor("test-vendor"); content.setLocked(true); this.contentCurator.merge(content); assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId())); assertThrows(ForbiddenException.class, () -> this.ownerContentResource.createContent(owner.getKey(), cdto) ); Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId()); assertNotNull(entity); assertEquals(content, entity); assertNotEquals(cdto.getName(), entity.getName()); }