RexsterResource extends BaseResource { @GET @Timed(name = "http.rest.graphs.collection.get", absolute = true) public Response getRexsterRoot() { try { final Set<String> graphNames = this.getRexsterApplication().getGraphNames(); final JSONArray jsonArrayNames = new JSONArray(graphNames); this.resultObject.put("name", "Rexster: A Graph Server"); this.resultObject.put("graphs", jsonArrayNames); this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch()); this.resultObject.put(Tokens.UP_TIME, this.getTimeAlive()); return Response.ok(this.resultObject).build(); } catch (JSONException ex) { final JSONObject error = generateErrorObject(ex.getMessage()); throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(error).build()); } } RexsterResource();  RexsterResource(final RexsterApplication ra); @OPTIONS Response optionsRexsterRoot(); @GET @Timed(name = "http.rest.graphs.collection.get", absolute = true) Response getRexsterRoot(); @Context
    public ServletContext servletCtx; }
@Test public void evaluateMultipleGraphs() { final RexsterApplication ra = this.mockery.mock(RexsterApplication.class); final HttpServletRequest httpServletRequest = this.mockery.mock(HttpServletRequest.class); final Set<String> graphNames = new HashSet<String>(); graphNames.add("graph1"); graphNames.add("graph2"); graphNames.add("graph3"); final long startTime = System.currentTimeMillis() - 1000; this.mockery.checking(new Expectations() {{ allowing(httpServletRequest).getParameterMap(); will(returnValue(new HashMap<String, String>())); allowing(ra).getGraphNames(); will(returnValue(graphNames)); allowing(ra).getStartTime(); will(returnValue(startTime)); }}); final RexsterResource resource = new RexsterResource(ra); final Response response = resource.getRexsterRoot(); Assert.assertNotNull(response); Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); Assert.assertTrue(response.getEntity() instanceof JSONObject); final JSONObject json = (JSONObject) response.getEntity(); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); Assert.assertTrue(json.has("name")); Assert.assertTrue(json.has("graphs")); Assert.assertTrue(json.has(Tokens.UP_TIME)); Assert.assertNotNull(json.optJSONArray("graphs")); final JSONArray jsonArray = json.optJSONArray("graphs"); Assert.assertEquals(3, jsonArray.length()); }
@Test public void evaluateNoGraphs() { final RexsterApplication ra = this.mockery.mock(RexsterApplication.class); final HttpServletRequest httpServletRequest = this.mockery.mock(HttpServletRequest.class); final Set<String> graphNames = new HashSet<String>(); final long startTime = System.currentTimeMillis() - 1000; this.mockery.checking(new Expectations() {{ allowing(httpServletRequest).getParameterMap(); will(returnValue(new HashMap<String, String>())); allowing(ra).getGraphNames(); will(returnValue(graphNames)); allowing(ra).getStartTime(); will(returnValue(startTime)); }}); final RexsterResource resource = new RexsterResource(ra); final Response response = resource.getRexsterRoot(); Assert.assertNotNull(response); Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); Assert.assertTrue(response.getEntity() instanceof JSONObject); final JSONObject json = (JSONObject) response.getEntity(); Assert.assertTrue(json.has(Tokens.QUERY_TIME)); Assert.assertTrue(json.has("name")); Assert.assertTrue(json.has("graphs")); Assert.assertTrue(json.has(Tokens.UP_TIME)); Assert.assertNotNull(json.optJSONArray("graphs")); final JSONArray jsonArray = json.optJSONArray("graphs"); Assert.assertEquals(0, jsonArray.length()); }