ConsumerTypeResource { @ApiOperation(notes = "Updates a Consumer Type", value = "update") @ApiResponses({ @ApiResponse(code = 400, message = "") }) @PUT @Path("/{id}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ConsumerTypeDTO update( @ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto) throws BadRequestException { ConsumerType type = consumerTypeCurator.get(dto.getId()); if (type == null) { throw new NotFoundException(i18n.tr("Unit type with label {0} could not be found.", dto.getId())); } this.populateEntity(type, dto); type = consumerTypeCurator.merge(type); return this.translator.translate(type, ConsumerTypeDTO.class); } @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 testUpdateTypeUpdatesLabelButNotManifest() { String label = "updated_label"; boolean manifest = this.testType.isManifest(); ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setId(this.testType.getId()); dto.setLabel(label); ConsumerTypeDTO output = this.consumerTypeResource.update(dto); assertNotNull(output); assertEquals(dto.getLabel(), output.getLabel()); assertEquals(manifest, output.isManifest()); this.consumerTypeCurator.flush(); this.consumerTypeCurator.clear(); ConsumerType existing = this.consumerTypeCurator.getByLabel(label); assertNotNull(existing); assertEquals(dto.getLabel(), existing.getLabel()); assertEquals(manifest, existing.isManifest()); }
@Test public void testUpdateTypeUpdatesManifestButNotLabel() { String label = this.testType.getLabel(); boolean manifest = !this.testType.isManifest(); ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setId(this.testType.getId()); dto.setManifest(manifest); ConsumerTypeDTO output = this.consumerTypeResource.update(dto); assertNotNull(output); assertEquals(label, output.getLabel()); assertEquals(dto.isManifest(), output.isManifest()); this.consumerTypeCurator.flush(); this.consumerTypeCurator.clear(); ConsumerType existing = this.consumerTypeCurator.get(this.testType.getId()); assertNotNull(existing); assertEquals(label, existing.getLabel()); assertEquals(dto.isManifest(), existing.isManifest()); }
@Test public void testUpdateTypeUpdatesNothing() { String label = this.testType.getLabel(); boolean manifest = this.testType.isManifest(); ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setId(this.testType.getId()); ConsumerTypeDTO output = this.consumerTypeResource.update(dto); assertNotNull(output); assertEquals(label, output.getLabel()); assertEquals(manifest, output.isManifest()); this.consumerTypeCurator.flush(); this.consumerTypeCurator.clear(); ConsumerType existing = this.consumerTypeCurator.get(this.testType.getId()); assertNotNull(existing); assertEquals(label, existing.getLabel()); assertEquals(manifest, existing.isManifest()); }
@Test public void testUpdateTypeWithBadId() { ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setId("some bad id"); assertThrows(NotFoundException.class, () -> this.consumerTypeResource.update(dto) ); }
@Test public void testUpdateTypeWithNullId() { ConsumerTypeDTO dto = new ConsumerTypeDTO(); dto.setId(null); assertThrows(NotFoundException.class, () -> this.consumerTypeResource.update(dto) ); }