KeyIndexResource extends AbstractSubResource { @GET @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.collection.get", absolute = true) public Response getKeyIndices(@PathParam("graphname") final String graphName) { final KeyIndexableGraph graph = this.getKeyIndexableGraph(graphName); final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName); try { final JSONArray keyVertexArray = new JSONArray(); for (String key : graph.getIndexedKeys(Vertex.class)) { keyVertexArray.put(key); } final JSONArray keyEdgeArray = new JSONArray(); for (String key : graph.getIndexedKeys(Edge.class)) { keyEdgeArray.put(key); } this.resultObject.put(Tokens.RESULTS, new JSONObject(new HashMap() {{ put(Tokens.VERTEX, keyVertexArray); put(Tokens.EDGE, keyEdgeArray); }})); this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch()); } catch (JSONException ex) { logger.error(ex); final JSONObject error = generateErrorObjectJsonFail(ex); throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build()); } finally { rag.tryCommit(); } return Response.ok(this.resultObject).build(); } KeyIndexResource();  KeyIndexResource(final UriInfo ui, final HttpServletRequest req, final RexsterApplication ra); @OPTIONS Response optionsKeyIndices(); @GET @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.collection.get", absolute = true) Response getKeyIndices(@PathParam("graphname") final String graphName); @OPTIONS @Path("/{clazz}") Response optionsIndexKeys(); @GET @Path("/{clazz}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.class.collection.get", absolute = true) Response getIndexKeys(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz); @OPTIONS @Path("/{clazz}/{keyName}") Response optionsIndexKey(); @DELETE @Path("{clazz}/{keyName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.object.delete", absolute = true) Response deleteIndexKey(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz, 
                                   @PathParam("keyName") final String keyName); @POST @Path("/{clazz}/{keyName}") @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON}) @Timed(name = "http.rest.key-indices.class.object.post", absolute = true) Response postIndexKey(@PathParam("graphname") final String graphName, @PathParam("clazz") final String clazz,
                                 @PathParam("keyName") final String keyName);  }
@Test(expected = WebApplicationException.class) public void getKeyIndexNonIndexableGraph() { final KeyIndexResource resource = mockNonKeyIndexableGraph(); resource.getKeyIndices(graphName); }
@Test public void getKeyIndices() { final KeyIndexResource resource = constructKeyIndexResourceWithToyGraph().getResource(); final Response response = resource.getKeyIndices(graphName); Assert.assertNotNull(response); Assert.assertEquals(Response.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(Tokens.RESULTS)); final JSONObject jsonKeys = json.optJSONObject(Tokens.RESULTS); Assert.assertTrue(jsonKeys.has(Tokens.VERTEX)); Assert.assertTrue(jsonKeys.has(Tokens.EDGE)); final JSONArray vertexKeys = jsonKeys.optJSONArray(Tokens.VERTEX); Assert.assertEquals(2, vertexKeys.length()); final JSONArray edgeKeys = jsonKeys.optJSONArray(Tokens.EDGE); Assert.assertEquals(1, edgeKeys.length()); Assert.assertEquals("weight", edgeKeys.optString(0)); }