GraphDatabase { public static Driver driver( String uri ) { return driver( uri, Config.defaultConfig() ); }  static Driver driver( String uri ); static Driver driver( URI uri ); static Driver driver( URI uri, Config config ); static Driver driver( String uri, Config config ); static Driver driver( String uri, AuthToken authToken ); static Driver driver( URI uri, AuthToken authToken ); static Driver driver( String uri, AuthToken authToken, Config config ); static Driver driver( URI uri, AuthToken authToken, Config config ); static Driver routingDriver( Iterable<URI> routingUris, AuthToken authToken, Config config );  }
@Test void boltSchemeShouldInstantiateDirectDriver() throws Exception { StubServer server = StubServer.start( "dummy_connection.script", 9001 ); URI uri = URI.create( "bolt: Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ); driver.verifyConnectivity(); assertThat( driver, is( directDriver() ) ); driver.close(); assertThat( server.exitStatus(), equalTo( 0 ) ); }
@Test void boltPlusDiscoverySchemeShouldInstantiateClusterDriver() throws Exception { StubServer server = StubServer.start( "discover_servers.script", 9001 ); URI uri = URI.create( "neo4j: Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ); driver.verifyConnectivity(); assertThat( driver, is( clusterDriver() ) ); driver.close(); assertThat( server.exitStatus(), equalTo( 0 ) ); }
@Test void throwsWhenBoltSchemeUsedWithRoutingParams() { assertThrows( IllegalArgumentException.class, () -> GraphDatabase.driver( "bolt: }
@Test void shouldRespondToInterruptsWhenConnectingToUnresponsiveServer() throws Exception { try ( ServerSocket serverSocket = new ServerSocket( 0 ) ) { TestUtil.interruptWhenInWaitingState( Thread.currentThread() ); final Driver driver = GraphDatabase.driver( "bolt: try { assertThrows( ServiceUnavailableException.class, driver::verifyConnectivity ); } finally { Thread.interrupted(); } } }
@Test void shouldPrintNiceErrorWhenConnectingToUnresponsiveServer() throws Exception { int localPort = -1; try ( ServerSocket serverSocket = new ServerSocket( 0 ) ) { localPort = serverSocket.getLocalPort(); } final Driver driver = GraphDatabase.driver( "bolt: final ServiceUnavailableException error = assertThrows( ServiceUnavailableException.class, driver::verifyConnectivity ); assertThat( error.getMessage(), containsString( "Unable to connect to" ) ); }
@Test void shouldPrintNiceRoutingErrorWhenConnectingToUnresponsiveServer() throws Exception { int localPort = -1; try ( ServerSocket serverSocket = new ServerSocket( 0 ) ) { localPort = serverSocket.getLocalPort(); } final Driver driver = GraphDatabase.driver( "neo4j: final ServiceUnavailableException error = assertThrows( ServiceUnavailableException.class, driver::verifyConnectivity ); error.printStackTrace(); assertThat( error.getMessage(), containsString( "Unable to connect to" ) ); }