Search in sources :

Example 6 with ExecutionResult

use of org.neo4j.cypher.internal.javacompat.ExecutionResult in project neo4j by neo4j.

the class ExportTest method testEscapingOfRelationshipStringPropertyValue.

@Test
public void testEscapingOfRelationshipStringPropertyValue() throws Exception {
    Node n = gdb.createNode();
    final Relationship rel = n.createRelationshipTo(n, RelationshipType.withName("REL"));
    rel.setProperty("name", "Brutus \"Brutal\" Howell");
    final ExecutionResult result = result("rel", rel);
    final SubGraph graph = CypherResultSubGraph.from(result, gdb, true);
    assertEquals("create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:\"Brutus \\\"Brutal\\\" Howell\"}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph(graph));
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) ExecutionResult(org.neo4j.cypher.internal.javacompat.ExecutionResult) Test(org.junit.Test)

Example 7 with ExecutionResult

use of org.neo4j.cypher.internal.javacompat.ExecutionResult in project neo4j by neo4j.

the class ExportTest method result.

@SuppressWarnings("unchecked")
private ExecutionResult result(String column, Object value) {
    ExecutionResult result = Mockito.mock(ExecutionResult.class);
    Mockito.when(result.columns()).thenReturn(asList(column));
    final Iterator<Map<String, Object>> inner = asList(singletonMap(column, value)).iterator();
    final ResourceIterator<Map<String, Object>> iterator = new ResourceIterator<Map<String, Object>>() {

        @Override
        public void close() {
        }

        @Override
        public boolean hasNext() {
            return inner.hasNext();
        }

        @Override
        public Map<String, Object> next() {
            return inner.next();
        }

        @Override
        public void remove() {
            inner.remove();
        }
    };
    Mockito.when(result.iterator()).thenReturn(iterator);
    Mockito.when(result.hasNext()).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return iterator.hasNext();
        }
    });
    Mockito.when(result.next()).thenAnswer(new Answer<Map<String, Object>>() {

        @Override
        public Map<String, Object> answer(InvocationOnMock invocation) throws Throwable {
            return iterator.next();
        }
    });
    return result;
}
Also used : ExecutionResult(org.neo4j.cypher.internal.javacompat.ExecutionResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 8 with ExecutionResult

use of org.neo4j.cypher.internal.javacompat.ExecutionResult in project neo4j by neo4j.

the class ExportTest method testSingleNodeWithProperties.

@Test
public void testSingleNodeWithProperties() throws Exception {
    Node n = gdb.createNode();
    n.setProperty("name", "Node1");
    n.setProperty("age", 42);
    final ExecutionResult result = result("node", n);
    final SubGraph graph = CypherResultSubGraph.from(result, gdb, false);
    assertEquals("create (_" + n.getId() + " {`age`:42, `name`:\"Node1\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph(graph));
}
Also used : Node(org.neo4j.graphdb.Node) ExecutionResult(org.neo4j.cypher.internal.javacompat.ExecutionResult) Test(org.junit.Test)

Example 9 with ExecutionResult

use of org.neo4j.cypher.internal.javacompat.ExecutionResult in project neo4j by neo4j.

the class ExportTest method testExportIndexesViaCypherResult.

@Test
public void testExportIndexesViaCypherResult() throws Exception {
    final Label label = Label.label("Foo");
    gdb.schema().indexFor(label).on("bar").create();
    gdb.schema().indexFor(label).on("bar2").create();
    commitAndStartNewTransactionAfterSchemaChanges();
    Node n = gdb.createNode(label);
    final ExecutionResult result = result("node", n);
    final SubGraph graph = CypherResultSubGraph.from(result, gdb, true);
    assertEquals("create index on :`Foo`(`bar2`);" + lineSeparator() + "create index on :`Foo`(`bar`);" + lineSeparator() + "create (_0:`Foo`)" + lineSeparator() + ";" + lineSeparator(), doExportGraph(graph));
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) ExecutionResult(org.neo4j.cypher.internal.javacompat.ExecutionResult) Test(org.junit.Test)

Example 10 with ExecutionResult

use of org.neo4j.cypher.internal.javacompat.ExecutionResult in project neo4j by neo4j.

the class ExportTest method testFromRelCypherResult.

@Test
public void testFromRelCypherResult() throws Exception {
    Node n = gdb.createNode();
    final Relationship rel = n.createRelationshipTo(n, RelationshipType.withName("REL"));
    final ExecutionResult result = result("rel", rel);
    final SubGraph graph = CypherResultSubGraph.from(result, gdb, true);
    assertEquals("create (_0)" + lineSeparator() + "create (_0)-[:`REL`]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph(graph));
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) ExecutionResult(org.neo4j.cypher.internal.javacompat.ExecutionResult) Test(org.junit.Test)

Aggregations

ExecutionResult (org.neo4j.cypher.internal.javacompat.ExecutionResult)16 Test (org.junit.Test)15 Node (org.neo4j.graphdb.Node)15 Relationship (org.neo4j.graphdb.Relationship)4 Label (org.neo4j.graphdb.Label)2 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Path (org.neo4j.graphdb.Path)1 ResourceIterator (org.neo4j.graphdb.ResourceIterator)1