Search in sources :

Example 1 with InternalRelationship

use of org.neo4j.driver.internal.InternalRelationship in project neo4j by neo4j.

the class TableOutputFormatterTest method printRelationshipsAndNodesWithEscapingForSpecialCharacters.

@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() {
    // given
    Record record = mock(Record.class);
    Map<String, Value> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", Values.value("prop1, value"));
    propertiesAsMap.put("prop2", Values.value(1));
    Value relVal = new RelationshipValue(new InternalRelationship(1, 1, 2, "RELATIONSHIP,TYPE", propertiesAsMap));
    List<String> labels = asList("label `1", "label2");
    Map<String, Value> nodeProperties = new HashMap<>();
    nodeProperties.put("prop1", Values.value("prop1:value"));
    String doubleQuotes = "\"\"";
    nodeProperties.put("1prop1", Values.value(doubleQuotes));
    nodeProperties.put("ä", Values.value("not-escaped"));
    Value nodeVal = new NodeValue(new InternalNode(1, labels, nodeProperties));
    Map<String, Value> recordMap = new LinkedHashMap<>();
    recordMap.put("rel", relVal);
    recordMap.put("node", nodeVal);
    List<String> keys = asList("rel", "node");
    when(record.keys()).thenReturn(keys);
    when(record.size()).thenReturn(2);
    when(record.get(0)).thenReturn(relVal);
    when(record.get(1)).thenReturn(nodeVal);
    when(record.<Value>asMap(anyObject())).thenReturn(recordMap);
    when(record.values()).thenReturn(asList(relVal, nodeVal));
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| [:`RELATIONSHIP,TYPE` {prop2: 1, prop1: \"prop1, value\"}] |"));
    assertThat(actual, containsString("| (:`label ``1`:label2 {`1prop1`: \"\\\"\\\"\", " + "prop1: \"prop1:value\", ä: \"not-escaped\"}) |"));
}
Also used : NodeValue(org.neo4j.driver.internal.value.NodeValue) InternalRelationship(org.neo4j.driver.internal.InternalRelationship) ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) InternalNode(org.neo4j.driver.internal.InternalNode) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with InternalRelationship

use of org.neo4j.driver.internal.InternalRelationship in project neo4j by neo4j.

the class TableOutputFormatterTest method prettyPrintRelationships.

@Test
public void prettyPrintRelationships() {
    // given
    List<String> keys = asList("rel");
    Map<String, Value> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", Values.value("prop1_value"));
    propertiesAsMap.put("prop2", Values.value("prop2_value"));
    RelationshipValue relationship = new RelationshipValue(new InternalRelationship(1, 1, 2, "RELATIONSHIP_TYPE", propertiesAsMap));
    Record record = new InternalRecord(keys, new Value[] { relationship });
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| [:RELATIONSHIP_TYPE {prop2: \"prop2_value\", prop1: \"prop1_value\"}] |"));
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) InternalRelationship(org.neo4j.driver.internal.InternalRelationship) ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) Test(org.junit.Test)

Example 3 with InternalRelationship

use of org.neo4j.driver.internal.InternalRelationship in project neo4j by neo4j.

the class TableOutputFormatterTest method formatEntities.

@Test
public void formatEntities() {
    // GIVEN
    Map<String, Value> properties = singletonMap("name", Values.value("Mark"));
    Map<String, Value> relProperties = singletonMap("since", Values.value(2016));
    InternalNode node = new InternalNode(12, asList("Person"), properties);
    InternalRelationship relationship = new InternalRelationship(24, 12, 12, "TEST", relProperties);
    Result result = mockResult(asList("a", "b", "c"), node, relationship, new InternalPath(node, relationship, node));
    // WHEN
    String table = formatResult(result);
    // THEN
    assertThat(table, containsString("| (:Person {name: \"Mark\"}) | [:TEST {since: 2016}] |"));
    assertThat(table, containsString("| (:Person {name: \"Mark\"})-[:TEST {since: 2016}]->(:Person {name: \"Mark\"}) |"));
}
Also used : InternalRelationship(org.neo4j.driver.internal.InternalRelationship) InternalPath(org.neo4j.driver.internal.InternalPath) Value(org.neo4j.driver.Value) RelationshipValue(org.neo4j.driver.internal.value.RelationshipValue) NodeValue(org.neo4j.driver.internal.value.NodeValue) DurationValue(org.neo4j.driver.internal.value.DurationValue) PathValue(org.neo4j.driver.internal.value.PathValue) PointValue(org.neo4j.driver.internal.value.PointValue) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InternalNode(org.neo4j.driver.internal.InternalNode) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Result(org.neo4j.driver.Result) Test(org.junit.Test)

Aggregations

StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Test (org.junit.Test)3 Value (org.neo4j.driver.Value)3 InternalRelationship (org.neo4j.driver.internal.InternalRelationship)3 DurationValue (org.neo4j.driver.internal.value.DurationValue)3 NodeValue (org.neo4j.driver.internal.value.NodeValue)3 PathValue (org.neo4j.driver.internal.value.PathValue)3 PointValue (org.neo4j.driver.internal.value.PointValue)3 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)3 ListBoltResult (org.neo4j.shell.state.ListBoltResult)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Record (org.neo4j.driver.Record)2 InternalNode (org.neo4j.driver.internal.InternalNode)2 InternalRecord (org.neo4j.driver.internal.InternalRecord)2 Result (org.neo4j.driver.Result)1 InternalPath (org.neo4j.driver.internal.InternalPath)1 BoltResult (org.neo4j.shell.state.BoltResult)1