@Test public void testUpdateRating() { Attendee jonathanDoe = sessionVote.registerAttendee(new Attendee("Jonathan Doe")); String id = jonathanDoe.getId(); SessionRating originalRating = new SessionRating("session1", id, 5); originalRating = sessionVote.rateSession(originalRating); Attendee jonathanDoe2 = sessionVote.registerAttendee(new Attendee("Jonathan Doe2")); String id2 = jonathanDoe2.getId(); SessionRating updatedRating = new SessionRating(originalRating.getId(), "session2", id2, 7); updatedRating = sessionVote.updateRating(updatedRating.getId(), updatedRating); assertEquals("Unexpected session in updated rating", "session2", updatedRating.getSession()); assertEquals("Unexpected attendee ID in updated rating", id2, updatedRating.getAttendeeId()); assertEquals("Unexpected rating value in updated rating", 7, updatedRating.getRating()); assertTrue("The session vote service is missing the newly-updated session rating", sessionVote.getAllSessionRatings().contains(updatedRating)); }
@PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) public SessionRating updateRating(@PathParam("id") String id, SessionRating newRating) { SessionRating original = selectedSessionRatingDAO.getRating(id); if (original == null) { throw new NotFoundException("Session Rating not found: " + id); } original.setSession(newRating.getSession()); original.setRating(newRating.getRating()); Attendee attendee = selectedAttendeeDAO.getAttendee(newRating.getAttendeeId()); if (attendee == null) { throw new BadRequestException("Invalid attendee id: " + newRating.getAttendeeId()); } original.setAttendee(attendee.getId()); SessionRating updated = selectedSessionRatingDAO.updateRating(original); return updated; }
SessionVote { @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) public SessionRating updateRating(@PathParam("id") String id, SessionRating newRating) { SessionRating original = selectedSessionRatingDAO.getRating(id); if (original == null) { throw new NotFoundException("Session Rating not found: " + id); } original.setSession(newRating.getSession()); original.setRating(newRating.getRating()); Attendee attendee = selectedAttendeeDAO.getAttendee(newRating.getAttendeeId()); if (attendee == null) { throw new BadRequestException("Invalid attendee id: " + newRating.getAttendeeId()); } original.setAttendee(attendee.getId()); SessionRating updated = selectedSessionRatingDAO.updateRating(original); return updated; } }
SessionVote { @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) public SessionRating updateRating(@PathParam("id") String id, SessionRating newRating) { SessionRating original = selectedSessionRatingDAO.getRating(id); if (original == null) { throw new NotFoundException("Session Rating not found: " + id); } original.setSession(newRating.getSession()); original.setRating(newRating.getRating()); Attendee attendee = selectedAttendeeDAO.getAttendee(newRating.getAttendeeId()); if (attendee == null) { throw new BadRequestException("Invalid attendee id: " + newRating.getAttendeeId()); } original.setAttendee(attendee.getId()); SessionRating updated = selectedSessionRatingDAO.updateRating(original); return updated; }  }
SessionVote { @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) public SessionRating updateRating(@PathParam("id") String id, SessionRating newRating) { SessionRating original = selectedSessionRatingDAO.getRating(id); if (original == null) { throw new NotFoundException("Session Rating not found: " + id); } original.setSession(newRating.getSession()); original.setRating(newRating.getRating()); Attendee attendee = selectedAttendeeDAO.getAttendee(newRating.getAttendeeId()); if (attendee == null) { throw new BadRequestException("Invalid attendee id: " + newRating.getAttendeeId()); } original.setAttendee(attendee.getId()); SessionRating updated = selectedSessionRatingDAO.updateRating(original); return updated; }  @GET @Path("/") @Produces(TEXT_HTML) String info(); @GET @Path("/nessProbe") @Produces(TEXT_PLAIN) Response nessProbe(); void setAttendeeSessionRating(AttendeeDAO attendee, SessionRatingDAO rating); @POST @Path("/attendee") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Attendee registerAttendee(Attendee name); @PUT @Path("/attendee/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Attendee updateAttendee(@PathParam("id") String id, Attendee attendee); @GET @Path("/attendee") @Produces(APPLICATION_JSON) Collection<Attendee> getAllAttendees(); @GET @Path("/attendee/{id}") @Produces(APPLICATION_JSON) Attendee getAttendee(@PathParam("id") String id); @DELETE @Path("/attendee/{id}") @Produces(APPLICATION_JSON) void deleteAttendee(@PathParam("id") String id); @POST @Path("/rate") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) SessionRating rateSession(SessionRating sessionRating); @GET @Path("/rate") @Produces(APPLICATION_JSON) Collection<SessionRating> getAllSessionRatings(); @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) SessionRating updateRating(@PathParam("id") String id, SessionRating newRating); @GET @Path("/rate/{id}") @Produces(APPLICATION_JSON) SessionRating getRating(@PathParam("id") String id); @DELETE @Path("/rate/{id}") @Produces(APPLICATION_JSON) void deleteRating(@PathParam("id") String id); @GET @Path("/ratingsBySession") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Collection<SessionRating> allSessionVotes(@QueryParam("sessionId") String sessionId); @GET @Path("/averageRatingBySession") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) double sessionRatingAverage(@QueryParam("sessionId") String sessionId); @GET @Path("/ratingsByAttendee") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Collection<SessionRating> votesByAttendee(@QueryParam("attendeeId") String attendeeId); }
SessionVote { @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) public SessionRating updateRating(@PathParam("id") String id, SessionRating newRating) { SessionRating original = selectedSessionRatingDAO.getRating(id); if (original == null) { throw new NotFoundException("Session Rating not found: " + id); } original.setSession(newRating.getSession()); original.setRating(newRating.getRating()); Attendee attendee = selectedAttendeeDAO.getAttendee(newRating.getAttendeeId()); if (attendee == null) { throw new BadRequestException("Invalid attendee id: " + newRating.getAttendeeId()); } original.setAttendee(attendee.getId()); SessionRating updated = selectedSessionRatingDAO.updateRating(original); return updated; }  @GET @Path("/") @Produces(TEXT_HTML) String info(); @GET @Path("/nessProbe") @Produces(TEXT_PLAIN) Response nessProbe(); void setAttendeeSessionRating(AttendeeDAO attendee, SessionRatingDAO rating); @POST @Path("/attendee") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Attendee registerAttendee(Attendee name); @PUT @Path("/attendee/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Attendee updateAttendee(@PathParam("id") String id, Attendee attendee); @GET @Path("/attendee") @Produces(APPLICATION_JSON) Collection<Attendee> getAllAttendees(); @GET @Path("/attendee/{id}") @Produces(APPLICATION_JSON) Attendee getAttendee(@PathParam("id") String id); @DELETE @Path("/attendee/{id}") @Produces(APPLICATION_JSON) void deleteAttendee(@PathParam("id") String id); @POST @Path("/rate") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) SessionRating rateSession(SessionRating sessionRating); @GET @Path("/rate") @Produces(APPLICATION_JSON) Collection<SessionRating> getAllSessionRatings(); @PUT @Path("/rate/{id}") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) SessionRating updateRating(@PathParam("id") String id, SessionRating newRating); @GET @Path("/rate/{id}") @Produces(APPLICATION_JSON) SessionRating getRating(@PathParam("id") String id); @DELETE @Path("/rate/{id}") @Produces(APPLICATION_JSON) void deleteRating(@PathParam("id") String id); @GET @Path("/ratingsBySession") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Collection<SessionRating> allSessionVotes(@QueryParam("sessionId") String sessionId); @GET @Path("/averageRatingBySession") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) double sessionRatingAverage(@QueryParam("sessionId") String sessionId); @GET @Path("/ratingsByAttendee") @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) Collection<SessionRating> votesByAttendee(@QueryParam("attendeeId") String attendeeId);  }