@Override public Conference to(UriInfo uriInfo, ConferenceRepresentation representation) { Conference conf = new Conference( representation.getName(), representation.getTagLine(), new Duration(representation.getStart(), representation.getEnd())); return conf; }
@Override public ConferenceRepresentation from(UriInfo uriInfo, Conference source) { ConferenceRepresentation rep = new ConferenceRepresentation(source.getId(), uriInfo); rep.setName(source.getName()); rep.setTagLine(source.getTagLine()); if(source.getDuration() != null) { rep.setStart(source.getDuration().getStart()); rep.setEnd(source.getDuration().getEnd()); } return rep; }
@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 to(UriInfo uriInfo, SessionRepresentation representation) { Session session = new Session( representation.getTitle(), representation.getOutline(), new Duration(representation.getStart(), representation.getEnd())); return session; }
@Override protected ResponseSpecification responseValidation(ResponseSpecification spec, Conference conference) { return spec. root("conference"). body("name", equalTo(conference.getName())). body("tagLine", equalTo(conference.getTagLine())). body("start", equalToXmlDate(conference.getDuration().getStart())). body("end", equalToXmlDate(conference.getDuration().getEnd())); }
@Override protected Conference createDomainObject() { return new Conference("Name", "TagLine", new Duration(new Date(), new Date())); }
@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())); } }
@Override protected Conference createInstance() { return new Conference("", "", new Duration(new Date(), new Date())); }
@Override protected Session createInstance() throws Exception { return new Session("", "", new Duration(new Date(), new Date())); }
@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); } }
@Override protected Session createDomainObject() { return new Session("Title", "Outline", new Duration(new Date(), new Date())); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorName() throws Exception { new Conference(null, "", new Duration(new Date(), new Date())); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorTagline() throws Exception { new Conference("", null, new Duration(new Date(), new Date())); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorStart() throws Exception { new Duration(null, new Date()); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorEndBeforeStart() throws Exception { new Duration(new Date(), new Date(System.currentTimeMillis()-4000)); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowNullConstructorTitle() throws Exception { new Session(null, "", new Duration(new Date(), new Date())); }