Search in sources :

Example 1 with Database

use of org.neo4j.server.database.Database in project neo4j by neo4j.

the class CypherSessionTest method shouldReturnASingleNode.

@Test
public void shouldReturnASingleNode() throws Throwable {
    GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
    Database database = new WrappedDatabase(graphdb);
    CypherExecutor executor = new CypherExecutor(database, NullLogProvider.getInstance());
    executor.start();
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getScheme()).thenReturn("http");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getRemotePort()).thenReturn(5678);
    when(request.getServerName()).thenReturn("127.0.0.1");
    when(request.getServerPort()).thenReturn(7474);
    when(request.getRequestURI()).thenReturn("/");
    try {
        CypherSession session = new CypherSession(executor, NullLogProvider.getInstance(), request);
        Pair<String, String> result = session.evaluate("create (a) return a");
        assertThat(result.first(), containsString("Node[0]"));
    } finally {
        graphdb.shutdown();
    }
}
Also used : CypherExecutor(org.neo4j.server.database.CypherExecutor) HttpServletRequest(javax.servlet.http.HttpServletRequest) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Database(org.neo4j.server.database.Database) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) CypherSession(org.neo4j.server.rest.management.console.CypherSession) Test(org.junit.Test)

Example 2 with Database

use of org.neo4j.server.database.Database in project neo4j by neo4j.

the class DatabaseMetadataServiceTest method shouldAdvertiseRelationshipTypesThatCurrentlyInUseInTheDatabase.

@Test
public void shouldAdvertiseRelationshipTypesThatCurrentlyInUseInTheDatabase() throws Throwable {
    try (Transaction tx = db.beginTx()) {
        db.getRelationshipById(relId).delete();
        tx.success();
    }
    Database database = new WrappedDatabase(db);
    DatabaseMetadataService service = new DatabaseMetadataService(database);
    try (Transaction tx = db.beginTx()) {
        Response response = service.getRelationshipTypes(true);
        assertEquals(200, response.getStatus());
        List<Map<String, Object>> jsonList = JsonHelper.jsonToList(response.getEntity().toString());
        assertEquals(2, jsonList.size());
    }
    database.stop();
}
Also used : Response(javax.ws.rs.core.Response) Transaction(org.neo4j.graphdb.Transaction) Database(org.neo4j.server.database.Database) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Database

use of org.neo4j.server.database.Database in project neo4j by neo4j.

the class AbstractNeoServer method createDefaultInjectables.

protected Collection<InjectableProvider<?>> createDefaultInjectables() {
    Collection<InjectableProvider<?>> singletons = new ArrayList<>();
    Database database = getDatabase();
    singletons.add(new DatabaseProvider(database));
    singletons.add(new DatabaseActions.Provider(databaseActions));
    singletons.add(new GraphDatabaseServiceProvider(database));
    singletons.add(new NeoServerProvider(this));
    singletons.add(providerForSingleton(new ConfigAdapter(getConfig()), Configuration.class));
    singletons.add(providerForSingleton(getConfig(), Config.class));
    singletons.add(new WebServerProvider(getWebServer()));
    PluginInvocatorProvider pluginInvocatorProvider = new PluginInvocatorProvider(this);
    singletons.add(pluginInvocatorProvider);
    RepresentationFormatRepository repository = new RepresentationFormatRepository(this);
    singletons.add(new InputFormatProvider(repository));
    singletons.add(new OutputFormatProvider(repository));
    singletons.add(new CypherExecutorProvider(cypherExecutor));
    singletons.add(providerForSingleton(transactionFacade, TransactionFacade.class));
    singletons.add(providerFromSupplier(authManagerSupplier, AuthManager.class));
    singletons.add(providerFromSupplier(userManagerSupplier, UserManagerSupplier.class));
    singletons.add(new TransactionFilter(database));
    singletons.add(new LoggingProvider(logProvider));
    singletons.add(providerForSingleton(logProvider.getLog(NeoServer.class), Log.class));
    singletons.add(providerForSingleton(resolveDependency(UsageData.class), UsageData.class));
    return singletons;
}
Also used : DatabaseProvider(org.neo4j.server.database.DatabaseProvider) PluginInvocatorProvider(org.neo4j.server.plugins.PluginInvocatorProvider) TransactionFilter(org.neo4j.server.rest.transactional.TransactionFilter) CypherExecutorProvider(org.neo4j.server.database.CypherExecutorProvider) Configuration(org.apache.commons.configuration.Configuration) UsageData(org.neo4j.udc.UsageData) Config(org.neo4j.kernel.configuration.Config) ArrayList(java.util.ArrayList) UserManagerSupplier(org.neo4j.kernel.api.security.UserManagerSupplier) DatabaseActions(org.neo4j.server.rest.web.DatabaseActions) Database(org.neo4j.server.database.Database) InjectableProvider(org.neo4j.server.database.InjectableProvider) OutputFormatProvider(org.neo4j.server.rest.repr.OutputFormatProvider) InputFormatProvider(org.neo4j.server.rest.repr.InputFormatProvider) ConfigAdapter(org.neo4j.server.plugins.ConfigAdapter) AuthManager(org.neo4j.kernel.api.security.AuthManager) Log(org.neo4j.logging.Log) AsyncRequestLog(org.neo4j.server.web.AsyncRequestLog) TransactionFacade(org.neo4j.server.rest.transactional.TransactionFacade) GraphDatabaseServiceProvider(org.neo4j.server.database.GraphDatabaseServiceProvider) RepresentationFormatRepository(org.neo4j.server.rest.repr.RepresentationFormatRepository) WebServerProvider(org.neo4j.server.web.WebServerProvider)

Example 4 with Database

use of org.neo4j.server.database.Database in project neo4j-documentation by neo4j.

the class CypherSessionDocTest method shouldReturnASingleNode.

@Test
public void shouldReturnASingleNode() throws Throwable {
    GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
    Database database = new WrappedDatabase(graphdb);
    CypherExecutor executor = new CypherExecutor(database, NullLogProvider.getInstance());
    executor.start();
    try {
        HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
        when(httpServletRequest.getScheme()).thenReturn("http");
        when(httpServletRequest.getHeader("User-Agent")).thenReturn("user-agent");
        when(httpServletRequest.getRemoteAddr()).thenReturn("remote-addr");
        when(httpServletRequest.getRemotePort()).thenReturn(1234);
        when(httpServletRequest.getServerName()).thenReturn("server-name");
        when(httpServletRequest.getServerPort()).thenReturn(6789);
        CypherSession session = new CypherSession(executor, NullLogProvider.getInstance(), httpServletRequest);
        Pair<String, String> result = session.evaluate("create (a) return a");
        assertThat(result.first(), containsString("Node[0]"));
    } finally {
        graphdb.shutdown();
    }
}
Also used : CypherExecutor(org.neo4j.server.database.CypherExecutor) HttpServletRequest(javax.servlet.http.HttpServletRequest) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Database(org.neo4j.server.database.Database) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) CypherSession(org.neo4j.server.rest.management.console.CypherSession) Test(org.junit.Test)

Example 5 with Database

use of org.neo4j.server.database.Database in project neo4j by neo4j.

the class RESTApiModuleTest method shouldRegisterASingleUri.

@Test
public void shouldRegisterASingleUri() throws Exception {
    // Given
    WebServer webServer = mock(WebServer.class);
    Map<String, String> params = new HashMap();
    String path = "/db/data";
    params.put(ServerSettings.rest_api_path.name(), path);
    Config config = Config.embeddedDefaults(params);
    Dependencies deps = new Dependencies();
    deps.satisfyDependency(new UsageData(mock(JobScheduler.class)));
    Database db = mock(Database.class);
    // When
    RESTApiModule module = new RESTApiModule(webServer, config, deps, NullLogProvider.getInstance());
    module.start();
    // Then
    verify(webServer).addJAXRSClasses(any(List.class), anyString(), anyCollection());
}
Also used : UsageData(org.neo4j.udc.UsageData) WebServer(org.neo4j.server.web.WebServer) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Database(org.neo4j.server.database.Database) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Dependencies(org.neo4j.kernel.impl.util.Dependencies) Test(org.junit.Test)

Aggregations

Database (org.neo4j.server.database.Database)6 Test (org.junit.Test)5 WrappedDatabase (org.neo4j.server.database.WrappedDatabase)4 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Response (javax.ws.rs.core.Response)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Transaction (org.neo4j.graphdb.Transaction)2 Config (org.neo4j.kernel.configuration.Config)2 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)2 CypherExecutor (org.neo4j.server.database.CypherExecutor)2 CypherSession (org.neo4j.server.rest.management.console.CypherSession)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 UsageData (org.neo4j.udc.UsageData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Configuration (org.apache.commons.configuration.Configuration)1 Matchers.anyString (org.mockito.Matchers.anyString)1 AuthManager (org.neo4j.kernel.api.security.AuthManager)1