@Test public void shouldStartServerWithHttpBoltEnabledAndHttpsDisabled() { testStartupWithConnectors( true, false, true ); }
trustAllSSLCerts(); try ( ServerControls server = getTestServerBuilder( testDir.directory() ) .withConfig( httpConnector.type, "HTTP" ) .withConfig( httpConnector.enabled, "true" ) assertDBConfig( server, "20", GraphDatabaseSettings.dense_node_threshold.name() );
@Test public void shouldLaunchAServerInSpecifiedDirectory() { // Given File workDir = testDir.directory( "specific" ); // When try ( ServerControls server = getTestServerBuilder( workDir ).newServer() ) { // Then assertThat( HTTP.GET( server.httpURI().toString() ).status(), equalTo( 200 ) ); assertThat( workDir.list().length, equalTo( 1 ) ); } // And after it's been closed, it should've cleaned up after itself. assertThat( Arrays.toString( workDir.list() ), workDir.list().length, equalTo( 0 ) ); }
private void assertDBConfig( ServerControls server, String expected, String key ) throws JsonParseException { JsonNode beans = HTTP.GET( server.httpURI().toString() + "db/manage/server/jmx/domain/org.neo4j/" ).get( "beans" ); JsonNode configurationBean = findNamedBean( beans, "Configuration" ).get( "attributes" ); boolean foundKey = false; for ( JsonNode attribute : configurationBean ) { if ( attribute.get( "name" ).asText().equals( key ) ) { assertThat( attribute.get( "value" ).asText(), equalTo( expected ) ); foundKey = true; break; } } if ( !foundKey ) { fail( "No config key '" + key + "'." ); } }
private void testStartupWithConnectors( boolean httpEnabled, boolean httpsEnabled, boolean boltEnabled ) { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.http.enabled", Boolean.toString( httpEnabled ) ) .withConfig( "dbms.connector.http.listen_address", ":0" ) .withConfig( "dbms.connector.https.enabled", Boolean.toString( httpsEnabled ) ) .withConfig( "dbms.connector.https.listen_address", ":0" ) .withConfig( "dbms.connector.bolt.enabled", Boolean.toString( boltEnabled ) ) .withConfig( "dbms.connector.bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { GraphDatabaseService db = server.graph(); assertDbAccessible( db ); verifyConnector( db, "http", httpEnabled ); verifyConnector( db, "https", httpsEnabled ); verifyConnector( db, "bolt", boltEnabled ); } }
@Test public void shouldFindFreePort() { // Given one server is running try ( ServerControls firstServer = getTestServerBuilder( testDir.directory() ).newServer() ) { // When I start a second server try ( ServerControls secondServer = getTestServerBuilder( testDir.directory() ).newServer() ) { // Then assertThat( secondServer.httpURI().getPort(), not( firstServer.httpURI().getPort() ) ); } } }
@Test public void shouldStartServerWithHttpEnabledAndHttpsBoltDisabled() { testStartupWithConnectors( true, false, false ); }
@Test public void shouldFailWhenProvidingANonDirectoryAsSource() throws IOException { File notADirectory = File.createTempFile( "prefix", "suffix" ); assertFalse( notADirectory.isDirectory() ); try ( ServerControls ignored = getTestServerBuilder( testDir.directory() ) .copyFrom( notADirectory ).newServer() ) { fail( "server should not start" ); } catch ( RuntimeException rte ) { Throwable cause = rte.getCause(); assertTrue( cause instanceof IOException ); assertTrue( cause.getMessage().contains( "exists but is not a directory" ) ); } }
@Test public void shouldStartServerWithHttpsEnabledAndHttpBoltDisabled() { testStartupWithConnectors( false, true, false ); }
@Test public void shouldMountUnmanagedExtensionsByClass() { // When try ( ServerControls server = getTestServerBuilder( testDir.directory() ) .withExtension( "/path/to/my/extension", MyUnmanagedExtension.class ) .newServer() ) { // Then assertThat( HTTP.GET( server.httpURI().toString() + "path/to/my/extension/myExtension" ).status(), equalTo( 234 ) ); } }
@Test public void shouldStartServerWithHttpHttpsEnabledAndBoltDisabled() { testStartupWithConnectors( true, true, false ); }
@Test public void shouldMountUnmanagedExtensionsByPackage() { // When try ( ServerControls server = getTestServerBuilder( testDir.directory() ) .withExtension( "/path/to/my/extension", "org.neo4j.harness.extensionpackage" ) .newServer() ) { // Then assertThat( HTTP.GET( server.httpURI().toString() + "path/to/my/extension/myExtension" ).status(), equalTo( 234 ) ); } }
@Test public void shouldStartServerWithHttpHttpsAndBoltDisabled() { testStartupWithConnectors( false, false, false ); }
@Test public void shouldOpenBoltPort() throws Throwable { // given try ( ServerControls controls = getTestServerBuilder( testDir.directory() ).newServer() ) { URI uri = controls.boltURI(); // when new SocketConnection().connect( new HostnamePort( uri.getHost(), uri.getPort() ) ); // then no exception } }
@Test public void shouldStartServerWithBoltEnabledAndHttpHttpsDisabled() { testStartupWithConnectors( false, false, true ); }
try ( ServerControls server = getTestServerBuilder( testDir.databaseDir() ).copyFrom( existingStoreDir ) .newServer() )
@Test public void shouldStartServerWithHttpsBoltEnabledAndHttpDisabled() { testStartupWithConnectors( false, true, true ); }