FramesExtension extends AbstractRexsterExtension { @ExtensionDefinition(extensionPoint = ExtensionPoint.EDGE) @ExtensionDescriptor(description = "Frames extension for an edge.") public ExtensionResponse doFramesWorkOnEdge(@RexsterContext RexsterResourceContext rexsterResourceContext, @RexsterContext Graph graph, @RexsterContext Edge edge, @ExtensionRequestParameter(name = "direction", description = "the direction of the edge (must be \"" + TOKEN_BOTH + "\", \"" + TOKEN_IN + "\", or \"" + TOKEN_OUT + "\" with the default being \"" + TOKEN_BOTH + "\"") String directionString) { Direction direction = Direction.BOTH; if (directionString != null && !directionString.isEmpty()) { if (directionString.equals(TOKEN_IN)) { direction = Direction.IN; } else if (directionString.equals(TOKEN_OUT)) { direction = Direction.OUT; } else { ExtensionMethod extMethod = rexsterResourceContext.getExtensionMethod(); return ExtensionResponse.error( "the direction parameter must be \"" + TOKEN_BOTH + "\", \"" + TOKEN_IN + "\", or \"" + TOKEN_OUT + "\"", null, Response.Status.BAD_REQUEST.getStatusCode(), null, generateErrorJson(extMethod.getExtensionApiAsJson())); } } return this.frameItUp(rexsterResourceContext, graph, edge, direction); }  @ExtensionDefinition(extensionPoint = ExtensionPoint.EDGE) @ExtensionDescriptor(description = "Frames extension for an edge.") ExtensionResponse doFramesWorkOnEdge(@RexsterContext RexsterResourceContext rexsterResourceContext,
                                                @RexsterContext Graph graph,
                                                @RexsterContext Edge edge,

                                                @ExtensionRequestParameter(name = "direction", description = "the direction of the edge (must be \"" + TOKEN_BOTH + "\", \"" + TOKEN_IN + "\", or \"" + TOKEN_OUT + "\" with the default being \"" + TOKEN_BOTH + "\"") String directionString); @ExtensionDefinition(extensionPoint = ExtensionPoint.VERTEX) @ExtensionDescriptor(description = "Frames extension for a vertex.") ExtensionResponse doFramesWorkOnVertex(@RexsterContext RexsterResourceContext rexsterResourceContext,
                                                  @RexsterContext Graph graph,
                                                  @RexsterContext Vertex vertex); @Override boolean isConfigurationValid(ExtensionConfiguration extensionConfiguration); static final String EXTENSION_NAME; static final String EXTENSION_NAMESPACE; static final String TOKEN_BOTH; static final String TOKEN_IN; static final String TOKEN_OUT; }
@Test public void doFramesWorkOnEdgeShortUrl() { final UriInfo uri = mockTheUri(false, ""); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, null, null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), "in"); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("success")); Assert.assertFalse(jsonObject.optBoolean("success")); }
@Test public void doFramesWorkOnEdgeBadMapping() { final UriInfo uri = mockTheUri(true, "not-a-frame-in-config"); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, null, null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), "in"); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("success")); Assert.assertFalse(jsonObject.optBoolean("success")); }
@Test public void doFramesWorkOnEdgeInvalidFrameRequested() { final UriInfo uri = mockTheUri(true, "notreal"); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, null, null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), "in"); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("success")); Assert.assertFalse(jsonObject.optBoolean("success")); }
@Test public void doFramesWorkOnEdgeWrapWithCreatedFrameStandardDirection() { final UriInfo uri = mockTheUri(true, "created"); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, null, null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), "in"); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("weight")); Assert.assertEquals("0.4", jsonObject.optString("weight")); }
@Test public void doFramesWorkOnEdgeNoDirection() { final UriInfo uri = mockTheUri(true, "created"); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, null, null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), null); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("weight")); Assert.assertEquals("0.4", jsonObject.optString("weight")); }
@Test public void doFramesWorkOnEdgeBadDirection() { final UriInfo uri = mockTheUri(true, "created"); this.ctx = new RexsterResourceContext(this.rag, uri, null, null, null, new ExtensionMethod(null, null, null, null), null, null); ExtensionResponse extResp = this.framesExtension.doFramesWorkOnEdge(this.ctx, this.graph, this.graph.getEdge(11), "bad-direction"); Assert.assertNotNull(extResp); Assert.assertNotNull(extResp.getJerseyResponse()); Response response = extResp.getJerseyResponse(); Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); JSONObject jsonObject = (JSONObject) response.getEntity(); Assert.assertNotNull(jsonObject); Assert.assertTrue(jsonObject.has("success")); Assert.assertFalse(jsonObject.optBoolean("success")); }