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();
}
}
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));
}
}
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));
}
}
Aggregations