Search in sources :

Example 31 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class PluginFunctionalTestHelper method makePostMap.

protected static Map<String, Object> makePostMap(String url, Map<String, Object> params) throws JsonParseException {
    String json = JsonHelper.createJsonFrom(params);
    JaxRsResponse response = new RestRequest().post(url, json, MediaType.APPLICATION_JSON_TYPE);
    String body = getResponseText(response);
    response.close();
    return deserializeMap(body);
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse)

Example 32 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class CloneSubgraphPluginTest method shouldAdvertiseExtenstionThatPluginCreates.

@Test
public void shouldAdvertiseExtenstionThatPluginCreates() throws JsonParseException, ClientHandlerException, UniformInterfaceException {
    int originalCount = nodeCount();
    // Find the start node URI from the server
    JaxRsResponse response = new RestRequest().get(functionalTestHelper.dataUri() + "node/1");
    String entity = response.getEntity();
    Map<String, Object> map = JsonHelper.jsonToMap(entity);
    HashMap<?, ?> extensionsMap = (HashMap<?, ?>) map.get("extensions");
    assertNotNull(extensionsMap);
    assertFalse(extensionsMap.isEmpty());
    final String GRAPH_CLONER_KEY = "GraphCloner";
    assertTrue(extensionsMap.keySet().contains(GRAPH_CLONER_KEY));
    final String CLONE_SUBGRAPH_KEY = "clonedSubgraph";
    String clonedSubgraphUri = (String) ((HashMap<?, ?>) extensionsMap.get(GRAPH_CLONER_KEY)).get(CLONE_SUBGRAPH_KEY);
    assertNotNull(clonedSubgraphUri);
    final String CLONE_DEPTH_MUCH_LARGER_THAN_THE_GRAPH = "99";
    response.close();
    response = new RestRequest().post(clonedSubgraphUri, "depth=" + CLONE_DEPTH_MUCH_LARGER_THAN_THE_GRAPH, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
    Assert.assertEquals(response.getEntity(), 200, response.getStatus());
    int doubleTheNumberOfNodes = originalCount * 2;
    assertEquals(doubleTheNumberOfNodes, nodeCount());
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) HashMap(java.util.HashMap) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 33 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class ExtensionListingFunctionalTest method canListExtensionMethodsForServerExtension.

@SuppressWarnings("unchecked")
@Test
public void canListExtensionMethodsForServerExtension() throws Exception {
    JaxRsResponse response = RestRequest.req().get(functionalTestHelper.extensionUri());
    assertThat(response.getStatus(), equalTo(200));
    Map<String, Object> json = JsonHelper.jsonToMap(response.getEntity());
    String refNodeService = (String) json.get(FunctionalTestPlugin.class.getSimpleName());
    response.close();
    response = RestRequest.req().get(refNodeService);
    String result = response.getEntity();
    assertThat(response.getStatus(), equalTo(200));
    json = JsonHelper.jsonToMap(result);
    json = (Map<String, Object>) json.get("graphdb");
    assertThat(json, hasKey(FunctionalTestPlugin.CREATE_NODE));
    response.close();
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 34 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class ExtensionListingFunctionalTest method canListAllAvailableServerExtensions.

@Test
public void canListAllAvailableServerExtensions() throws Exception {
    JaxRsResponse response = RestRequest.req().get(functionalTestHelper.extensionUri());
    assertThat(response.getStatus(), equalTo(200));
    Map<String, Object> json = JsonHelper.jsonToMap(response.getEntity());
    assertFalse(json.isEmpty());
    response.close();
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 35 with JaxRsResponse

use of org.neo4j.server.rest.JaxRsResponse in project neo4j by neo4j.

the class ExtensionListingFunctionalTest method datarootContainsReferenceToExtensions.

@Test
public void datarootContainsReferenceToExtensions() throws Exception {
    JaxRsResponse response = RestRequest.req().get(functionalTestHelper.dataUri());
    assertThat(response.getStatus(), equalTo(200));
    Map<String, Object> json = JsonHelper.jsonToMap(response.getEntity());
    String extInfo = (String) json.get("extensions_info");
    assertNotNull(new URI(extInfo));
    response.close();
}
Also used : JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)58 Test (org.junit.Test)52 RestRequest (org.neo4j.server.rest.RestRequest)29 Matchers.containsString (org.hamcrest.Matchers.containsString)19 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)13 PrettyJSON (org.neo4j.server.rest.PrettyJSON)8 URI (java.net.URI)7 Documented (org.neo4j.kernel.impl.annotations.Documented)6 Map (java.util.Map)4 Client (com.sun.jersey.api.client.Client)3 Title (org.neo4j.test.TestData.Title)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 HashMap (java.util.HashMap)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 CommunityServerBuilder (org.neo4j.server.helpers.CommunityServerBuilder)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)1 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)1