public GraphDatabaseService getGraphDatabaseService() { return controls.graph(); }
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 shouldReturnBoltUriWhenDefaultBoltConnectorOffAndOtherConnectorConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.bolt.enabled", "false" ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( anotherBoltHostPort.getHost(), boltUri.getHost() ); assertEquals( anotherBoltHostPort.getPort(), boltUri.getPort() ); } }
@Test public void shouldReturnBoltUriWhenMultipleBoltConnectorsConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ) .withConfig( "dbms.connector.bolt.enabled", "true" ) .withConfig( "dbms.connector.bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNotNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); assertNotEquals( boltHostPort, anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( boltHostPort.getHost(), boltUri.getHost() ); assertEquals( boltHostPort.getPort(), boltUri.getPort() ); } }
public GraphDatabaseService getGraphDatabaseService() { return controls.graph(); }
this.database = this.controls.graph();
@Test public void ogmExtensionShouldUseProvidedDatabase() throws Exception { try (ServerControls controls = TestServer.newInProcessBuilder() .withConfig(GraphDatabaseSettings.auth_enabled, "false") .withExtension(TEST_PATH, TestOgmExtension.class) .newServer()) { URI testURI = controls.httpURI().resolve(TEST_PATH); GraphDatabaseService service = controls.graph(); try (Transaction tx = service.beginTx()) { service.execute("CREATE (u:User {name:'new user'})"); tx.success(); } HTTP.Response loadResponse = HTTP.GET(testURI.toString()); assertThat(loadResponse.rawContent()).isEqualTo("[{\"id\":0,\"name\":\"new user\"}]"); } }
@BeforeClass public static void initSessionFactory() { Driver driver = new EmbeddedDriver(serverControls.graph(), new Configuration.Builder().build()); sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE); }
@Test public void testMyExtensionWithFunctionFixture() throws Exception { // Given try ( ServerControls server = TestServerBuilders.newInProcessBuilder() .withExtension( "/myExtension", MyUnmanagedExtension.class ) .withFixture( new Function<GraphDatabaseService, Void>() { @Override public Void apply( GraphDatabaseService graphDatabaseService ) throws RuntimeException { try ( Transaction tx = graphDatabaseService.beginTx() ) { graphDatabaseService.createNode( DynamicLabel.label( "User" ) ); tx.success(); } return null; } } ) .newServer() ) { // When Result result = server.graph().execute( "MATCH (n:User) return n" ); // Then assertEquals( 1, IteratorUtil.count( result ) ); } } // END SNIPPET: testExtension