Search in sources :

Example 1 with RelationshipValue

use of org.neo4j.driver.internal.value.RelationshipValue 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 RelationshipValue

use of org.neo4j.driver.internal.value.RelationshipValue 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)

Aggregations

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