@POST @Path("/{c_id}/session") @Consumes({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response createSession(@PathParam("c_id") String conferenceId, SessionRepresentation sessionRepresentation) { Conference conference = getRepository().get(conferenceId); if (conference == null) { return Response.status(Status.BAD_REQUEST).build(); // TODO: Need Business Exception type to explain why? } Session session = sessionConverter.to(getUriInfo(), sessionRepresentation); conference.addSession(session); getRepository().store(conference); return Response.created( UriBuilder.fromResource( SessionResource.class).segment("{id}") .build(session.getId())) .build(); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowToAddNullSession() throws Exception { Conference conf = new Conference("", "", new Duration(new Date(), new Date())); conf.addSession(null); }
@Test @ShouldMatchDataSet(value = { "conference.yml", "session.yml" }, excludeColumns = { "*id" }) public void shouldBeAbleToCreateConferenceWithSession() { Conference conference = createConference(); conference.addSession(createSession()); repository.store(conference); }
@Test @UsingDataSet("conference.yml") @ShouldMatchDataSet(value = { "conference.yml", "session.yml" }, excludeColumns = { "*id" }) public void shouldBeAbleToAddSessionToConference() { Conference conference = repository.get("CA"); conference.addSession(createSession()); repository.store(conference); }