TreatmentsResource extends BaseResource { @POST @Path("/{treatmentName}") public void updateTreatment(@PathParam("experimentName") String experimentName, @PathParam("treatmentName") String treatmentName, @Valid UpdateTreatmentRequest request) { final Experiment experiment = ensureExists(experiments.get(experimentName)); final Treatment treatment = ensureExists(ensureExists(experiment).getTreatment(treatmentName)); if (request.getDescription() != null) { treatment.setDescription(request.getDescription().orElse(null)); } experiment.save(); } @Inject  TreatmentsResource(Experiments experiments, Mappers mapper); @GET Iterable<TreatmentDto> getTreatments(@PathParam("experimentName") String experimentName); @GET @Path("/{treatmentName}") TreatmentDto getTreatment(@PathParam("experimentName") String experimentName,
                                     @PathParam("treatmentName") String treatmentName); @PUT Response addTreatment(@PathParam("experimentName") String experimentName,
                                 @Valid TreatmentDto treatmentDto); @DELETE @Path("/{treatmentName}") void removeTreatment(@PathParam("experimentName") String experimentName,
                                @PathParam("treatmentName") String treatmentName); @POST @Path("/{treatmentName}") void updateTreatment(@PathParam("experimentName") String experimentName,
                                @PathParam("treatmentName") String treatmentName,
                                @Valid UpdateTreatmentRequest request); @DELETE void clearTreatments(@PathParam("experimentName") String experimentName);  }
@Test public void testUpdateTreatment() { final UpdateTreatmentRequest request = new UpdateTreatmentRequest(Optional.of("new description")); post(TREATMENT_ENDPOINT, EXPERIMENT_BAD, EXP_1_TREATMENT_1) .entity(request) .assertStatus(Status.NOT_FOUND); post(TREATMENT_ENDPOINT, EXPERIMENT_1, TREATMENT_BAD) .entity(request) .assertStatus(Status.NOT_FOUND); post(TREATMENT_ENDPOINT, EXPERIMENT_1, EXP_1_TREATMENT_1) .entity(request) .assertStatus(Status.NO_CONTENT); final TreatmentDto treatment = get(TREATMENT_ENDPOINT, EXPERIMENT_1, EXP_1_TREATMENT_1) .assertStatus(Status.OK) .result(TreatmentDto.class); assertEquals(request.getDescription().orElse(null), treatment.getDescription()); final Iterable<AllocationDto> allocations = get(ALLOCATIONS_ENDPOINT, EXPERIMENT_1) .assertStatus(Status.OK) .result(iterable(AllocationDto.class)); assertNotNull( Iterables.find(allocations, new Predicate<AllocationDto>() { @Override public boolean apply(@Nullable AllocationDto input) { return input != null && input.getTreatment().equals(EXP_1_TREATMENT_1); } }) ); }