Search in sources :

Example 1 with TestWebContainer

use of org.neo4j.server.helpers.TestWebContainer in project neo4j by neo4j.

the class ConfigurationIT method shouldBeAbleToEvaluateSettingFromWebServer.

@Test
void shouldBeAbleToEvaluateSettingFromWebServer() throws IOException {
    assumeTrue(curlAvailable(), "Curl required");
    TestWebContainer testWebContainer = CommunityWebContainerBuilder.serverOnRandomPorts().build();
    try {
        // Given
        Config config = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).setRaw(Map.of(TestSettings.stringSetting.name(), "$(curl -I '" + testWebContainer.getBaseUri() + "')")).build();
        // Then
        assertThat(config.get(TestSettings.stringSetting)).contains("200 OK");
    } finally {
        testWebContainer.shutdown();
    }
}
Also used : TestWebContainer(org.neo4j.server.helpers.TestWebContainer) Test(org.junit.jupiter.api.Test)

Example 2 with TestWebContainer

use of org.neo4j.server.helpers.TestWebContainer in project neo4j by neo4j.

the class NeoWebServerPortConflictIT method shouldComplainIfServerPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException {
    try (ServerSocket socket = new ServerSocket(0, 0, InetAddress.getLocalHost())) {
        SocketAddress contestedAddress = new SocketAddress(socket.getInetAddress().getHostName(), socket.getLocalPort());
        AssertableLogProvider logProvider = new AssertableLogProvider();
        TestWebContainer testWebContainer = null;
        try {
            testWebContainer = builder(logProvider).onAddress(contestedAddress).usingDataDir(folder.directory(name.getMethodName()).toAbsolutePath().toString()).build();
            fail("Should have reported failure to start");
        } catch (Exception e) {
            assertThat(e.getMessage()).contains("Error starting Neo4j database server");
        } finally {
            if (testWebContainer != null) {
                testWebContainer.shutdown();
            }
        }
        assertThat(logProvider).forClass(CommunityNeoWebServer.class).forLevel(ERROR).containsMessageWithArguments("Failed to start Neo4j on %s: %s", contestedAddress, format("Address %s is already in use, cannot bind to it.", contestedAddress));
    }
}
Also used : TestWebContainer(org.neo4j.server.helpers.TestWebContainer) ServerSocket(java.net.ServerSocket) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 3 with TestWebContainer

use of org.neo4j.server.helpers.TestWebContainer in project neo4j by neo4j.

the class NeoWebServerPortConflictIT method shouldComplainIfServerHTTPSPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException {
    try (ServerSocket httpsSocket = new ServerSocket(0, 0, InetAddress.getLocalHost())) {
        SocketAddress unContestedAddress = new SocketAddress(httpsSocket.getInetAddress().getHostName(), 0);
        SocketAddress httpsAddress = new SocketAddress(httpsSocket.getInetAddress().getHostName(), httpsSocket.getLocalPort());
        AssertableLogProvider logProvider = new AssertableLogProvider();
        TestWebContainer testWebContainer = null;
        try {
            testWebContainer = builder(logProvider).onAddress(unContestedAddress).onHttpsAddress(httpsAddress).withHttpsEnabled().usingDataDir(folder.directory(name.getMethodName()).toAbsolutePath().toString()).build();
            fail("Should have reported failure to start");
        } catch (Exception e) {
            assertThat(e.getMessage()).contains("Error starting Neo4j database server");
        } finally {
            if (testWebContainer != null) {
                testWebContainer.shutdown();
            }
        }
        assertThat(logProvider).forClass(CommunityNeoWebServer.class).forLevel(ERROR).containsMessageWithArguments("Failed to start Neo4j on %s: %s", unContestedAddress, format("At least one of the addresses %s or %s is already in use, cannot bind to it.", unContestedAddress, httpsAddress));
    }
}
Also used : TestWebContainer(org.neo4j.server.helpers.TestWebContainer) ServerSocket(java.net.ServerSocket) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) IOException(java.io.IOException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

TestWebContainer (org.neo4j.server.helpers.TestWebContainer)3 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 Test (org.junit.Test)2 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 Test (org.junit.jupiter.api.Test)1