@Override public Neo4jRule withExtension( String mountPath, Class<?> extension ) { builder = builder.withExtension( mountPath, extension ); return this; }
@Override public Neo4jRule withExtension( String mountPath, String packageName ) { builder = builder.withExtension( mountPath, packageName ); return this; }
@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 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 ) ); } }
@Override public Neo4jRule withExtension( String mountPath, Class<?> extension ) { builder = builder.withExtension( mountPath, extension ); return this; }
@Override public Neo4jRule withExtension( String mountPath, String packageName ) { builder = builder.withExtension( mountPath, packageName ); return this; }
@Test public void testOgmPluginExtension() 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); HTTP.Response saveResponse = HTTP.POST(testURI.toString()); assertThat(saveResponse.status()).isEqualTo(200); HTTP.Response loadResponse = HTTP.GET(testURI.toString()); assertThat(loadResponse.rawContent()).isEqualTo("[{\"id\":0,\"name\":\"new user\"}]"); } }
@Test public void testMyExtension() throws Exception { // Given try ( ServerControls server = TestServerBuilders.newInProcessBuilder() .withExtension( "/myExtension", MyUnmanagedExtension.class ) .newServer() ) { // When HTTP.Response response = HTTP.GET( server.httpURI().resolve( "myExtension" ).toString() ); // Then assertEquals( 200, response.status() ); } }
@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\"}]"); } }
@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