Search in sources :

Example 16 with RestRequest

use of org.neo4j.server.rest.RestRequest 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 17 with RestRequest

use of org.neo4j.server.rest.RestRequest 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 18 with RestRequest

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

the class PluginFunctionalTest method shouldHandleNullPath.

@Test
public void shouldHandleNullPath() throws Exception {
    long n = functionalTestHelper.getGraphDbHelper().createNode();
    String url = getPluginMethodUri(functionalTestHelper.nodeUri(n), "pathToReference");
    JaxRsResponse response = new RestRequest().post(url, null);
    assertThat(response.getEntity(), response.getStatus(), is(204));
    response.close();
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest)

Example 19 with RestRequest

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

the class HTTPLoggingIT method givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses.

@Test
public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), Settings.FALSE).withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.toString()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        String query = "?implicitlyDisabled" + randomString();
        JaxRsResponse response = new RestRequest().get(functionalTestHelper.managementUri() + query);
        assertThat(response.getStatus(), is(HttpStatus.SC_OK));
        response.close();
        // then
        File httpLog = new File(logDirectory, "http.log");
        assertThat(httpLog.exists(), is(false));
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Example 20 with RestRequest

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

the class PluginFunctionalTestHelper method makePostMap.

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

Aggregations

RestRequest (org.neo4j.server.rest.RestRequest)31 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)29 Test (org.junit.Test)26 Matchers.containsString (org.hamcrest.Matchers.containsString)7 URI (java.net.URI)6 Client (com.sun.jersey.api.client.Client)3 Documented (org.neo4j.kernel.impl.annotations.Documented)3 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)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 Map (java.util.Map)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 CommunityServerBuilder (org.neo4j.server.helpers.CommunityServerBuilder)1 PrettyJSON (org.neo4j.server.rest.PrettyJSON)1 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)1 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)1