Search in sources :

Example 6 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverQuery.

@Test
public void terminateLongRunningDriverQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortDatabaseWithTimeout, driverConfig);
        Session session = driver.session()) {
        org.neo4j.driver.v1.Transaction transaction = session.beginTransaction();
        transaction.run("create (n)").consume();
        transaction.success();
        fakeClock.forward(3, TimeUnit.SECONDS);
        try {
            transaction.run("create (n)").consume();
            fail("Transaction should be already terminated by execution guard.");
        } catch (Exception expected) {
        // ignored
        }
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 7 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class DBMSModuleTest method shouldNotRegisterUserServiceWhenAuthDisabled.

@SuppressWarnings("unchecked")
@Test
public void shouldNotRegisterUserServiceWhenAuthDisabled() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(false);
    DBMSModule module = new DBMSModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
    verify(webServer, never()).addJAXRSClasses(Matchers.argThat(new ArgumentMatcher<List<String>>() {

        @Override
        public boolean matches(Object argument) {
            List<String> argumentList = (List<String>) argument;
            return argumentList.contains(UserService.class.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("<List containing " + UserService.class.getName() + ">");
        }
    }), anyString(), anyCollection());
}
Also used : Description(org.hamcrest.Description) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) UserService(org.neo4j.server.rest.dbms.UserService) Config(org.neo4j.kernel.configuration.Config) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 8 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class ManagementApiModuleTest method shouldRegisterASingleUri.

@Test
public void shouldRegisterASingleUri() throws Exception {
    WebServer webServer = mock(WebServer.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    Map<String, String> params = new HashMap();
    String managementPath = "/db/manage";
    params.put(ServerSettings.management_api_path.name(), managementPath);
    Config config = Config.embeddedDefaults(params);
    when(neoServer.getConfig()).thenReturn(config);
    ManagementApiModule module = new ManagementApiModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(any(List.class), anyString(), anyCollection());
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 9 with CommunityNeoServer

use of org.neo4j.server.CommunityNeoServer in project neo4j by neo4j.

the class ThirdPartyJAXRSModuleTest method shouldReportThirdPartyPackagesAtSpecifiedMount.

@Test
public void shouldReportThirdPartyPackagesAtSpecifiedMount() throws Exception {
    // Given
    WebServer webServer = mock(WebServer.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(neoServer.getDatabase()).thenReturn(mock(Database.class));
    Config config = mock(Config.class);
    List<ThirdPartyJaxRsPackage> jaxRsPackages = new ArrayList<ThirdPartyJaxRsPackage>();
    String path = "/third/party/package";
    jaxRsPackages.add(new ThirdPartyJaxRsPackage("org.example.neo4j", path));
    when(config.get(ServerSettings.third_party_packages)).thenReturn(jaxRsPackages);
    // When
    ThirdPartyJAXRSModule module = new ThirdPartyJAXRSModule(webServer, config, NullLogProvider.getInstance(), neoServer);
    module.start();
    // Then
    verify(webServer).addJAXRSPackages(any(List.class), anyString(), anyCollection());
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) Config(org.neo4j.kernel.configuration.Config) Database(org.neo4j.server.database.Database) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) ThirdPartyJaxRsPackage(org.neo4j.server.configuration.ThirdPartyJaxRsPackage) Test(org.junit.Test)

Aggregations

CommunityNeoServer (org.neo4j.server.CommunityNeoServer)9 Test (org.junit.Test)8 Config (org.neo4j.kernel.configuration.Config)5 URI (java.net.URI)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 WebServer (org.neo4j.server.web.WebServer)4 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Driver (org.neo4j.driver.v1.Driver)2 Session (org.neo4j.driver.v1.Session)2 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)2 ShellException (org.neo4j.shell.ShellException)2 HTTP (org.neo4j.test.server.HTTP)2 BindException (java.net.BindException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1