Search in sources :

Example 1 with CypherExecutor

use of org.neo4j.server.database.CypherExecutor 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 CypherExecutor

use of org.neo4j.server.database.CypherExecutor 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)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)2 CypherExecutor (org.neo4j.server.database.CypherExecutor)2 Database (org.neo4j.server.database.Database)2 WrappedDatabase (org.neo4j.server.database.WrappedDatabase)2 CypherSession (org.neo4j.server.rest.management.console.CypherSession)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2