Search in sources :

Example 11 with NeoServer

use of org.neo4j.server.NeoServer in project open-kilda by telstra.

the class TestConfig method graphDatabaseService.

/**
 * Neo4j Server bean.
 * Runs Neo4j server for integration tests and returns {@link GraphDatabaseService} instance.
 *
 * @return {@link GraphDatabaseService}
 */
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
    String homeDir = "./target";
    String configFile = "./src/test/resources/neo4j.conf";
    ServerBootstrapper serverBootstrapper = new CommunityBootstrapper();
    int i = serverBootstrapper.start(new File(homeDir), Optional.of(new File(configFile)));
    switch(i) {
        case ServerBootstrapper.OK:
            logger.debug("Server started");
            break;
        case ServerBootstrapper.GRAPH_DATABASE_STARTUP_ERROR_CODE:
            logger.error("Server failed to start: graph database startup error");
            break;
        case ServerBootstrapper.WEB_SERVER_STARTUP_ERROR_CODE:
            logger.error("Server failed to start: web server startup error");
            break;
        default:
            logger.error("Server failed to start: unknown error");
            break;
    }
    NeoServer neoServer = serverBootstrapper.getServer();
    return neoServer.getDatabase().getGraph();
}
Also used : NeoServer(org.neo4j.server.NeoServer) ServerBootstrapper(org.neo4j.server.ServerBootstrapper) File(java.io.File) CommunityBootstrapper(org.neo4j.server.CommunityBootstrapper) Bean(org.springframework.context.annotation.Bean)

Example 12 with NeoServer

use of org.neo4j.server.NeoServer in project neo4j-documentation by neo4j.

the class HTTPLoggingDocIT method givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess.

@Test
public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    final String query = "?explicitlyEnabled=" + randomString();
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), "true").withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.getAbsolutePath()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        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");
        assertEventually("request appears in log", fileContentSupplier(httpLog), containsString(query), 5, TimeUnit.SECONDS);
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Example 13 with NeoServer

use of org.neo4j.server.NeoServer in project neo4j-documentation by neo4j.

the class HTTPLoggingDocIT method givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses.

@Test
public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    FileUtils.forceMkdir(logDirectory);
    final File confDir = testDirectory.directory(directoryPrefix + "-confdir");
    FileUtils.forceMkdir(confDir);
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withProperty(ServerSettings.http_logging_enabled.name(), "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(200));
        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.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

Aggregations

NeoServer (org.neo4j.server.NeoServer)13 Test (org.junit.Test)10 File (java.io.File)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)4 Client (com.sun.jersey.api.client.Client)3 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)2 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)2 RestRequest (org.neo4j.doc.server.rest.RestRequest)2 Config (org.neo4j.kernel.configuration.Config)2 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)2 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)2 RestRequest (org.neo4j.server.rest.RestRequest)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Function (java.util.function.Function)1 Configuration (org.apache.commons.configuration.Configuration)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Mockito (org.mockito.Mockito)1