@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorDuration() throws Exception { new Session("", "", null); }
@Override public SessionRepresentation from(UriInfo uriInfo, Session source) { String id = source.getId(); String parentId = null; if(source.getConference() != null) { parentId = source.getConference().getId(); } SessionRepresentation rep = new SessionRepresentation(id, parentId, uriInfo); rep.setTitle(source.getTitle()); rep.setOutline(source.getOutline()); if(source.getDuration() != null) { rep.setStart(source.getDuration().getStart()); rep.setEnd(source.getDuration().getEnd()); } return rep; }
@Override public Session update(UriInfo uriInfo, SessionRepresentation representation, Session target) { target.setTitle(representation.getTitle()); target.setOutline(representation.getOutline()); target.setDuration(new Duration(representation.getStart(), representation.getEnd())); return target; } }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullSetterOutline() throws Exception { Session sess = new Session("", "", new Duration(new Date(), new Date())); sess.setOutline(null); }
@Override protected ResponseSpecification responseValidation(ResponseSpecification spec, Session session) { return spec. root("session"). body("title", equalTo(session.getTitle())). body("outline", equalTo(session.getOutline())). body("start", equalToXmlDate(session.getDuration().getStart())). body("end", equalToXmlDate(session.getDuration().getEnd())); } }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullSetterDuration() throws Exception { Session sess = new Session("", "", new Duration(new Date(), new Date())); sess.setDuration(null); } }
@Override public Session get(String id) { Session session = conferenceRepository.getSessionById(id); if(session == null) { for(Session s: sessions) { if(s.getId().equals(id)) { return s; } } } return session; }
@Override protected void validateUpdatedDomainObject(Session domain) { Assert.assertEquals(UPDATED_TITLE, domain.getTitle()); }
@Override protected Session updateDomainObject(Session domain) { return domain.setTitle(UPDATED_TITLE); }
@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 @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); }
@Override protected Session createInstance() throws Exception { return new Session("", "", new Duration(new Date(), new Date())); }
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(value = { "conference.yml", "session_updated.yml" }) public void shouldBeAbleToChangeSession() { Session session = repository.get("SA"); session.setTitle("UPDATED"); repository.store(session); Assert.assertTrue(createdEventFired); }
@Override protected Session createDomainObject() { return new Session("Title", "Outline", new Duration(new Date(), new Date())); }
@Override public void remove(Session entity) { Conference conf = conferenceRepository.getConferenceBySessionId(entity.getId()); if(conf != null) { conf.removeSession(entity); } sessions.remove(entity); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorTitle() throws Exception { new Session(null, "", new Duration(new Date(), new Date())); }
Session getSessionById(String id) { for(Conference conf : getStored()) { for(Session session : conf.getSessions()) { if(session.getId().equals(id)) { return session; } } } return null; }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorOutline() throws Exception { new Session("", null, new Duration(new Date(), new Date())); }