GuestIdResource { @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) public void updateGuests( @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @ApiParam(name = "guestIds", required = true) List<GuestIdDTO> guestIdDTOs) { Consumer toUpdate = consumerCurator.findByUuid(consumerUuid); ConsumerDTO consumer = new ConsumerDTO(); consumer.setGuestIds(guestIdDTOs); Set<String> allGuestIds = new HashSet<>(); for (GuestIdDTO gid : consumer.getGuestIds()) { allGuestIds.add(gid.getGuestId()); } VirtConsumerMap guestConsumerMap = consumerCurator.getGuestConsumersMap( toUpdate.getOwnerId(), allGuestIds); GuestMigration guestMigration = migrationProvider.get().buildMigrationManifest(consumer, toUpdate); if (consumerResource.performConsumerUpdates(consumer, toUpdate, guestMigration)) { if (guestMigration.isMigrationPending()) { guestMigration.migrate(); } else { consumerCurator.update(toUpdate); } } } @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 updateGuests() { List<GuestIdDTO> guestIds = new LinkedList<>(); guestIds.add(TestUtil.createGuestIdDTO("1")); when(consumerResource.performConsumerUpdates(any(ConsumerDTO.class), eq(consumer), any(GuestMigration.class))). thenReturn(true); guestIdResource.updateGuests(consumer.getUuid(), guestIds); verify(consumerResource, times(1)) .performConsumerUpdates(any(ConsumerDTO.class), eq(consumer), any(GuestMigration.class)); verify(testMigration, times(1)).migrate(); }
@Test public void updateGuestsNoUpdate() { List<GuestIdDTO> guestIds = new LinkedList<>(); guestIds.add(TestUtil.createGuestIdDTO("1")); when(consumerResource.performConsumerUpdates(any(ConsumerDTO.class), eq(consumer), any(GuestMigration.class))). thenReturn(false); guestIdResource.updateGuests(consumer.getUuid(), guestIds); verify(consumerResource, times(1)) .performConsumerUpdates(any(ConsumerDTO.class), eq(consumer), any(GuestMigration.class)); verify(consumerCurator, never()).update(eq(consumer)); }