ConsumerTypeResource { @ApiOperation(notes = "Creates a Consumer Type", value = "create") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ConsumerTypeDTO create( @ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto) throws BadRequestException { try { ConsumerType type = new ConsumerType(); this.populateEntity(type, dto); type = consumerTypeCurator.create(type); return this.translator.translate(type, ConsumerTypeDTO.class); } catch (Exception e) { log.error("Problem creating unit type: ", e); throw new BadRequestException(i18n.tr("Problem creating unit type: {0}", dto)); } } @Inject  ConsumerTypeResource(ConsumerTypeCurator consumerTypeCurator, I18n i18n,
        ModelTranslator translator); @ApiOperation(notes = "Retrieves a list of Consumer Types", value = "list", response = ConsumerTypeDTO.class, responseContainer = "list") @GET @Produces({ MediaType.APPLICATION_JSON }) @Wrapped(element = "consumertypes") CandlepinQuery<ConsumerTypeDTO> list(); @ApiOperation(notes = "Retrieves a single Consumer Type", value = "getConsumerType") @ApiResponses({ @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{id}") ConsumerTypeDTO getConsumerType(@PathParam("id") String id); @ApiOperation(notes = "Creates a Consumer Type", value = "create") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) ConsumerTypeDTO create(
        @ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto); @ApiOperation(notes = "Updates a Consumer Type", value = "update") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @PUT @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) ConsumerTypeDTO update(
        @ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto); @ApiOperation(notes = "Removes a Consumer Type", value = "deleteConsumerType") @DELETE @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) void deleteConsumerType(@PathParam("id") String id);  }
@Test public void testCreateType() { String label = "test_label"; ConsumerType existing = this.consumerTypeCurator.getByLabel(label); assertNull(existing); ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setLabel(label); dto.setManifest(true); ConsumerTypeDTO output = this.consumerTypeResource.create(dto); assertNotNull(output); assertEquals(dto.getLabel(), output.getLabel()); assertEquals(dto.isManifest(), output.isManifest()); this.consumerTypeCurator.flush(); this.consumerTypeCurator.clear(); existing = this.consumerTypeCurator.getByLabel(label); assertNotNull(existing); assertEquals(dto.getLabel(), existing.getLabel()); assertEquals(dto.isManifest(), existing.isManifest()); }
@Test public void testCreateTypeWithBadData() { assertThrows(BadRequestException.class, () -> this.consumerTypeResource.create(new ConsumerTypeDTO()) ); }