GuestIdResource { @ApiOperation(notes = "Updates a single Guest on a Consumer. Allows virt-who to avoid uploading" + " an entire list of guests", value = "updateGuest") @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/{guest_id}") public void updateGuest( @ApiParam("consumer who owns or hosts the guest in question") @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @ApiParam("guest virtual uuid") @PathParam("guest_id") String guestId, @ApiParam(name = "updated", required = true, value = "updated guest data to use") GuestIdDTO updatedDTO) { if (guestId == null || guestId.isEmpty()) { throw new BadRequestException( i18n.tr("Please supply a valid guest id")); } if (updatedDTO == null) { updatedDTO = new GuestIdDTO().setGuestId(guestId); } if (updatedDTO.getGuestId() == null) { updatedDTO.setGuestId(guestId); } if (!guestId.equalsIgnoreCase(updatedDTO.getGuestId())) { throw new BadRequestException( i18n.tr("Guest ID in json \"{0}\" does not match path guest ID \"{1}\"", updatedDTO.getGuestId(), guestId)); } Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid); GuestId guestIdEntity = new GuestId(); populateEntity(guestIdEntity, updatedDTO); guestIdEntity.setConsumer(consumer); GuestId toUpdate = guestIdCurator.findByGuestIdAndOrg(guestId, consumer.getOwnerId()); if (toUpdate != null) { guestIdEntity.setId(toUpdate.getId()); } guestIdCurator.merge(guestIdEntity); } @Inject  GuestIdResource(GuestIdCurator guestIdCurator, ConsumerCurator consumerCurator,
        ConsumerTypeCurator consumerTypeCurator, ConsumerResource consumerResource, I18n i18n,
        EventFactory eventFactory, EventSink sink, Provider<GuestMigration> migrationProvider,
        ModelTranslator translator); @ApiOperation(notes = "Retrieves the List of a Consumer's Guests", value = "getGuestIds", response = GuestIdDTO.class, responseContainer = "list") @ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") }) @GET @Produces(MediaType.APPLICATION_JSON) CandlepinQuery<GuestIdDTO> getGuestIds(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid); @ApiOperation(notes = "Retrieves a single Guest By its consumer and the guest UUID", value = "getGuestId") @GET @Produces(MediaType.APPLICATION_JSON) @Path("/{guest_id}") GuestIdDTO getGuestId(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("guest_id") String guestId); @ApiOperation(notes = "Updates the List of Guests on a Consumer This method should work " + "just like updating the consumer, except that it only updates GuestIds. " + " Eventually we should move All the logic here, and depricate updating guests " + "through the consumer update.", value = "updateGuests") @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) void updateGuests(
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @ApiParam(name = "guestIds", required = true) List<GuestIdDTO> guestIdDTOs); @ApiOperation(notes = "Updates a single Guest on a Consumer. Allows virt-who to avoid uploading" + " an entire list of guests", value = "updateGuest") @PUT @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/{guest_id}") void updateGuest(
        @ApiParam("consumer who owns or hosts the guest in question")
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @ApiParam("guest virtual uuid")
        @PathParam("guest_id") String guestId,
        @ApiParam(name = "updated", required = true, value = "updated guest data to use")
        GuestIdDTO updatedDTO); @ApiOperation(notes = "Removes the Guest from the Consumer", value = "deleteGuest") @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("/{guest_id}") void deleteGuest(
        @ApiParam("consumer who owns or hosts the guest in question")
        @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid,
        @PathParam("guest_id") String guestId,
        @QueryParam("unregister") @DefaultValue("false") boolean unregister,
        @Context Principal principal);  }
@Test public void updateGuest() { GuestIdDTO guest = TestUtil.createGuestIdDTO("some_guest"); GuestId guestEnt = new GuestId(); guestEnt.setId("some_id"); guestIdResource.updateGuest(consumer.getUuid(), guest.getGuestId(), guest); when(guestIdCurator.findByGuestIdAndOrg(anyString(), any(String.class))).thenReturn(guestEnt); ArgumentCaptor<GuestId> guestCaptor = ArgumentCaptor.forClass(GuestId.class); verify(guestIdCurator, times(1)).merge(guestCaptor.capture()); GuestId result = guestCaptor.getValue(); assertEquals(consumer, result.getConsumer()); }
@Test public void updateGuestMismatchedGuestId() { GuestIdDTO guest = TestUtil.createGuestIdDTO("some_guest"); assertThrows(BadRequestException.class, () -> guestIdResource.updateGuest(consumer.getUuid(), "other_id", guest)); }