Search in sources :

Example 31 with Value

use of org.neo4j.driver.Value in project neo4j by neo4j.

the class PrettyPrinterTest method checkMapForPrettyPrint.

private void checkMapForPrettyPrint(Map<String, String> map, String expectedResult) {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.MAP());
    when(value.asMap((Function<Value, String>) anyObject())).thenReturn(map);
    when(record.keys()).thenReturn(asList("map"));
    when(record.values()).thenReturn(asList(value));
    BoltResult result = new ListBoltResult(asList(record), mock(ResultSummary.class));
    // when
    String actual = plainPrinter.format(result);
    // then
    assertThat(actual, is(expectedResult));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult)

Example 32 with Value

use of org.neo4j.driver.Value in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintProfileInformation.

@Test
public void prettyPrintProfileInformation() {
    // given
    ResultSummary resultSummary = mock(ResultSummary.class);
    ProfiledPlan plan = mock(ProfiledPlan.class);
    when(plan.dbHits()).thenReturn(1000L);
    when(plan.records()).thenReturn(20L);
    when(resultSummary.hasPlan()).thenReturn(true);
    when(resultSummary.hasProfile()).thenReturn(true);
    when(resultSummary.plan()).thenReturn(plan);
    when(resultSummary.profile()).thenReturn(plan);
    when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L);
    when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L);
    when(resultSummary.queryType()).thenReturn(QueryType.READ_ONLY);
    Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED", "GlobalMemory", 10).asMap(v -> v);
    when(plan.arguments()).thenReturn(argumentMap);
    BoltResult result = new ListBoltResult(Collections.emptyList(), resultSummary);
    // when
    String actual = plainPrinter.format(result);
    // then
    String expected = "Plan: \"PROFILE\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12\n" + "Rows: 20\n" + "DbHits: 1000\n" + "Memory (Bytes): 10";
    Stream.of(expected.split("\n")).forEach(e -> assertThat(actual, containsString(e)));
}
Also used : ProfiledPlan(org.neo4j.driver.summary.ProfiledPlan) ListBoltResult(org.neo4j.shell.state.ListBoltResult) ResultSummary(org.neo4j.driver.summary.ResultSummary) Value(org.neo4j.driver.Value) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 33 with Value

use of org.neo4j.driver.Value 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 34 with Value

use of org.neo4j.driver.Value in project neo4j by neo4j.

the class TableOutputFormatterTest method prettyPrintPoint.

@Test
public void prettyPrintPoint() {
    // given
    List<String> keys = asList("p1", "p2");
    Value point2d = new PointValue(new InternalPoint2D(4326, 42.78, 56.7));
    Value point3d = new PointValue(new InternalPoint3D(4326, 1.7, 26.79, 34.23));
    Record record = new InternalRecord(keys, new Value[] { point2d, point3d });
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| point({srid:4326, x:42.78, y:56.7}) |"));
    assertThat(actual, containsString("| point({srid:4326, x:1.7, y:26.79, z:34.23}) |"));
}
Also used : InternalRecord(org.neo4j.driver.internal.InternalRecord) ListBoltResult(org.neo4j.shell.state.ListBoltResult) PointValue(org.neo4j.driver.internal.value.PointValue) 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) InternalPoint3D(org.neo4j.driver.internal.InternalPoint3D) InternalRecord(org.neo4j.driver.internal.InternalRecord) Record(org.neo4j.driver.Record) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InternalPoint2D(org.neo4j.driver.internal.InternalPoint2D) Test(org.junit.Test)

Example 35 with Value

use of org.neo4j.driver.Value 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

Value (org.neo4j.driver.Value)37 Test (org.junit.Test)29 ListBoltResult (org.neo4j.shell.state.ListBoltResult)22 Record (org.neo4j.driver.Record)21 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 BoltResult (org.neo4j.shell.state.BoltResult)15 ResultSummary (org.neo4j.driver.summary.ResultSummary)14 HashMap (java.util.HashMap)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)9 DurationValue (org.neo4j.driver.internal.value.DurationValue)9 NodeValue (org.neo4j.driver.internal.value.NodeValue)9 PathValue (org.neo4j.driver.internal.value.PathValue)9 PointValue (org.neo4j.driver.internal.value.PointValue)9 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)9 InternalRecord (org.neo4j.driver.internal.InternalRecord)8 Plan (org.neo4j.driver.summary.Plan)7 Node (org.neo4j.driver.types.Node)7 Relationship (org.neo4j.driver.types.Relationship)7 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)6 FloatValue (org.neo4j.driver.internal.value.FloatValue)5