@SuppressWarnings({ "unchecked", "rawtypes" }) @GET @Path("/{c_id}/session") @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response getSessions(@PathParam("c_id") String conferenceId) { Conference conference = getRepository().get(conferenceId); if (conference == null) { return Response.status(Status.BAD_REQUEST).build(); // TODO: Need Business Exception type to explain why? } Collection<SessionRepresentation> sessions = sessionConverter.from(getUriInfo(), (Collection)conference.getSessions()); return Response.ok(new GenericEntity<Collection<SessionRepresentation>>(sessions){}) .type(matchMediaType( SessionResource.SESSION_XML_MEDIA_TYPE, SessionResource.SESSION_JSON_MEDIA_TYPE)) .build(); } }
Session getSessionById(String id) { for(Conference conf : getStored()) { for(Session session : conf.getSessions()) { if(session.getId().equals(id)) { return session; } } } return null; }
@Test(expected = UnsupportedOperationException.class) public void shouldNotAllowToAddSessionToSessions() throws Exception { Conference conf = new Conference("", "", new Duration(new Date(), new Date())); Session sess = new Session("", "", new Duration(new Date(), new Date())); conf.getSessions().add(sess); } }
Conference getConferenceBySessionId(String id) { for(Conference conf : getStored()) { for(Session session : conf.getSessions()) { if(session.getId().equals(id)) { return conf; } } } return null; } }
@Test @UsingDataSet({ "conference.yml", "session.yml" }) @ShouldMatchDataSet({ "conference.yml", "session_empty.yml" }) public void shouldBeAbleToRemoveConferenceWithSession() { Conference conference = repository.get("CA"); Session session = conference.getSessions().toArray(new Session[0])[0]; conference.removeSession(session); repository.store(conference); }
@Test @UsingDataSet({ "conference.yml", "session.yml" }) @ShouldMatchDataSet(value = { "conference.yml", "session_updated.yml" }) public void shouldBeAbleToChangeSession() { Conference conference = repository.get("CA"); conference.getSessions().toArray(new Session[0])[0].setTitle("UPDATED"); repository.store(conference); }