/** * Gets the identified resource without its representation's content. * * @param resourceRef * The reference of the resource to get. * @return The response. */ public final Response head(Reference resourceRef) { return handle(new Request(Method.HEAD, resourceRef)); }
/** * Puts a representation in the identified resource. * * @param resourceUri * The URI of the resource to modify. * @param entity * The entity to put. * @return The response. */ public final Response put(String resourceUri, Representation entity) { return handle(new Request(Method.PUT, resourceUri, entity)); }
/** * Gets the identified resource. * * @param resourceRef * The reference of the resource to get. * @return The response. */ public final Response get(Reference resourceRef) { return handle(new Request(Method.GET, resourceRef)); }
/** * Deletes the identified resource. * * @param resourceRef * The reference of the resource to delete. * @return The response. */ public final Response delete(Reference resourceRef) { return handle(new Request(Method.DELETE, resourceRef)); }
/** * Deletes the identified resource. * * @param resourceUri * The URI of the resource to delete. * @return The response. */ public final Response delete(String resourceUri) { return handle(new Request(Method.DELETE, resourceUri)); }
/** * Gets the identified resource. * * @param resourceUri * The URI of the resource to get. * @return The response. */ public final Response get(String resourceUri) { return handle(new Request(Method.GET, resourceUri)); }
/** * Gets the options for the identified resource. * * @param resourceUri * The URI of the resource to get. * @return The response. */ public final Response options(String resourceUri) { return handle(new Request(Method.OPTIONS, resourceUri)); }
/** * Gets the identified resource without its representation's content. * * @param resourceUri * The URI of the resource to get. * @return The response. */ public final Response head(String resourceUri) { return handle(new Request(Method.HEAD, resourceUri)); }
/** * Gets the options for the identified resource. * * @param resourceRef * The reference of the resource to get. * @return The response. */ public final Response options(Reference resourceRef) { return handle(new Request(Method.OPTIONS, resourceRef)); }
/** * Posts a representation to the identified resource. * * @param resourceRef * The reference of the resource to post to. * @param entity * The entity to post. * @return The response. */ public final Response post(Reference resourceRef, Representation entity) { return handle(new Request(Method.POST, resourceRef, entity)); }
/** * Posts a representation to the identified resource. * * @param resourceUri * The URI of the resource to post to. * @param entity * The entity to post. * @return The response. */ public final Response post(String resourceUri, Representation entity) { return handle(new Request(Method.POST, resourceUri, entity)); }
/** * Puts a representation in the identified resource. * * @param resourceRef * The reference of the resource to modify. * @param entity * The entity to put. * @return The response. */ public final Response put(Reference resourceRef, Representation entity) { return handle(new Request(Method.PUT, resourceRef, entity)); }
@Test public void testGetByIdHTML() throws Exception { Request req = new Request(); Response res = new Response(req); RequestResource.HTMLFormat format = new RequestResource.HTMLFormat(req, res, resource, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(monitor.getDAO().getRequest(2)).write(out); assertTrue(new String(out.toByteArray()).startsWith("<html>")); }
@Test public void testGetAll() throws Exception { Request req = new Request(); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet(); assertEquals(monitor.getDAO().getRequests().size(), monitor.getDAO().getRequests(q).size()); }
@Test public void testGetById() throws Exception { Request req = new Request(); req.getAttributes().put("request", 2); Response res = new Response(req); resource.init(null, req, res); RequestData data = (RequestData) resource.handleObjectGet(); assertEquals("/two", data.getPath()); }
@Test public void testFilterIn() throws Exception { Request req = new Request(); setKVP(req, "filter", "path:IN:/seven,/six,/five"); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet(); List<RequestData> datas = (List<RequestData>) monitor.getDAO().getRequests(q); assertCovered(datas, 5, 6, 7); }
@Test public void testGetDateRange() throws Exception { Request req = new Request(); setKVP(req, "from", "2010-07-23T15:56:44", "to", "2010-07-23T16:16:44"); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet(); List<RequestData> datas = (List<RequestData>) monitor.getDAO().getRequests(q); assertCoveredInOrder(datas, 6, 5, 4); }
@Test public void testFilter() throws Exception { Request req = new Request(); setKVP(req, "filter", "path:EQ:/seven"); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet(); List<RequestData> datas = (List<RequestData>) monitor.getDAO().getRequests(q); assertCoveredInOrder(datas, 7); }
@Test public void testFilterStatus() throws Exception { Request req = new Request(); setKVP(req, "filter", "status:EQ:WAITING"); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet(); List<RequestData> datas = (List<RequestData>) monitor.getDAO().getRequests(q); assertCovered(datas, 2,6); }
@Test public void testLive() throws Exception { Request req = new Request(); setKVP(req, "live", "yes"); Response res = new Response(req); resource.init(null, req, res); Query q = (Query) resource.handleObjectGet();; List<RequestData> datas = monitor.getDAO().getRequests(q); assertCovered(datas, 1, 2, 5, 6, 9, 10); }