Search in sources :

Example 11 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintThreeSegmentPath.

@Test
public void prettyPrintThreeSegmentPath() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Node start = mock(Node.class);
    when(start.labels()).thenReturn(asList("start"));
    when(start.id()).thenReturn(1L);
    Node second = mock(Node.class);
    when(second.labels()).thenReturn(asList("second"));
    when(second.id()).thenReturn(2L);
    Node third = mock(Node.class);
    when(third.labels()).thenReturn(asList("third"));
    when(third.id()).thenReturn(3L);
    Node end = mock(Node.class);
    when(end.labels()).thenReturn(asList("end"));
    when(end.id()).thenReturn(4L);
    Path path = mock(Path.class);
    when(path.start()).thenReturn(start);
    Relationship relationship = mock(Relationship.class);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.startNodeId()).thenReturn(1L).thenReturn(3L).thenReturn(3L);
    Path.Segment segment1 = mock(Path.Segment.class);
    when(segment1.start()).thenReturn(start);
    when(segment1.end()).thenReturn(second);
    when(segment1.relationship()).thenReturn(relationship);
    Path.Segment segment2 = mock(Path.Segment.class);
    when(segment2.start()).thenReturn(second);
    when(segment2.end()).thenReturn(third);
    when(segment2.relationship()).thenReturn(relationship);
    Path.Segment segment3 = mock(Path.Segment.class);
    when(segment3.start()).thenReturn(third);
    when(segment3.end()).thenReturn(end);
    when(segment3.relationship()).thenReturn(relationship);
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
    when(value.asPath()).thenReturn(path);
    when(path.iterator()).thenReturn(asList(segment1, segment2, segment3).iterator());
    when(record.keys()).thenReturn(asList("path"));
    when(record.values()).thenReturn(asList(value));
    BoltResult result = new ListBoltResult(singletonList(record), mock(ResultSummary.class));
    // when
    String actual = plainPrinter.format(result);
    // then
    assertThat(actual, is("path" + NEWLINE + "(:start)-[:RELATIONSHIP_TYPE]->" + "(:second)<-[:RELATIONSHIP_TYPE]-(:third)-[:RELATIONSHIP_TYPE]->(:end)" + NEWLINE));
}
Also used : Path(org.neo4j.driver.types.Path) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Node(org.neo4j.driver.types.Node) Relationship(org.neo4j.driver.types.Relationship) 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) Test(org.junit.Test)

Example 12 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class CypherShellTest method setParamShouldAddParamWithSpecialCharactersAndValue.

@Test
public void setParamShouldAddParamWithSpecialCharactersAndValue() throws ParameterException, CommandException {
    Value value = mock(Value.class);
    Record recordMock = mock(Record.class);
    BoltResult boltResult = new ListBoltResult(asList(recordMock), mock(ResultSummary.class));
    when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
    when(recordMock.get("bo`b")).thenReturn(value);
    when(value.asObject()).thenReturn("99");
    assertTrue(offlineTestShell.getParameterMap().allParameterValues().isEmpty());
    Object result = offlineTestShell.getParameterMap().setParameter("`bo``b`", "99");
    assertEquals(99L, result);
    assertEquals(99L, offlineTestShell.getParameterMap().allParameterValues().get("bo`b"));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) Mockito.anyObject(org.mockito.Mockito.anyObject) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 13 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintSingleNodePath.

@Test
public void prettyPrintSingleNodePath() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Node start = mock(Node.class);
    when(start.labels()).thenReturn(asList("start"));
    when(start.id()).thenReturn(1L);
    Node end = mock(Node.class);
    when(end.labels()).thenReturn(asList("end"));
    when(end.id()).thenReturn(2L);
    Path path = mock(Path.class);
    when(path.start()).thenReturn(start);
    Relationship relationship = mock(Relationship.class);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.startNodeId()).thenReturn(1L);
    Path.Segment segment1 = mock(Path.Segment.class);
    when(segment1.start()).thenReturn(start);
    when(segment1.end()).thenReturn(end);
    when(segment1.relationship()).thenReturn(relationship);
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.PATH());
    when(value.asPath()).thenReturn(path);
    when(path.iterator()).thenReturn(asList(segment1).iterator());
    when(record.keys()).thenReturn(asList("path"));
    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("path" + NEWLINE + "(:start)-[:RELATIONSHIP_TYPE]->(:end)" + NEWLINE));
}
Also used : Path(org.neo4j.driver.types.Path) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Node(org.neo4j.driver.types.Node) Relationship(org.neo4j.driver.types.Relationship) 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) Test(org.junit.Test)

Example 14 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintRelationships.

@Test
public void prettyPrintRelationships() {
    // given
    Record record = mock(Record.class);
    Value value = mock(Value.class);
    Relationship relationship = mock(Relationship.class);
    HashMap<String, Object> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", "prop1_value");
    propertiesAsMap.put("prop2", "prop2_value");
    when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP());
    when(value.asRelationship()).thenReturn(relationship);
    when(relationship.type()).thenReturn("RELATIONSHIP_TYPE");
    when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap));
    when(record.keys()).thenReturn(asList("rel"));
    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("rel" + NEWLINE + "[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]" + NEWLINE));
}
Also used : ListBoltResult(org.neo4j.shell.state.ListBoltResult) HashMap(java.util.HashMap) Relationship(org.neo4j.driver.types.Relationship) Value(org.neo4j.driver.Value) ResultSummary(org.neo4j.driver.summary.ResultSummary) Record(org.neo4j.driver.Record) Matchers.anyObject(org.mockito.Matchers.anyObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BoltResult(org.neo4j.shell.state.BoltResult) ListBoltResult(org.neo4j.shell.state.ListBoltResult) Test(org.junit.Test)

Example 15 with ListBoltResult

use of org.neo4j.shell.state.ListBoltResult in project neo4j by neo4j.

the class PrettyPrinterTest method prettyPrintList.

@Test
public void prettyPrintList() {
    // given
    Record record1 = mock(Record.class);
    Record record2 = mock(Record.class);
    Value value1 = Values.value("val1_1", "val1_2");
    Value value2 = Values.value(new String[] { "val2_1" });
    when(record1.keys()).thenReturn(asList("col1", "col2"));
    when(record1.values()).thenReturn(asList(value1, value2));
    when(record2.values()).thenReturn(asList(value2));
    BoltResult result = new ListBoltResult(asList(record1, record2), mock(ResultSummary.class));
    // when
    String actual = plainPrinter.format(result);
    // then
    assertThat(actual, is(String.join(NEWLINE, "col1, col2", "[\"val1_1\", \"val1_2\"], [\"val2_1\"]", "[\"val2_1\"]", "")));
}
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) Test(org.junit.Test)

Aggregations

ListBoltResult (org.neo4j.shell.state.ListBoltResult)26 Test (org.junit.Test)24 Value (org.neo4j.driver.Value)20 BoltResult (org.neo4j.shell.state.BoltResult)18 Record (org.neo4j.driver.Record)16 ResultSummary (org.neo4j.driver.summary.ResultSummary)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 StringContains.containsString (org.hamcrest.core.StringContains.containsString)12 DurationValue (org.neo4j.driver.internal.value.DurationValue)8 NodeValue (org.neo4j.driver.internal.value.NodeValue)8 PathValue (org.neo4j.driver.internal.value.PathValue)8 PointValue (org.neo4j.driver.internal.value.PointValue)8 RelationshipValue (org.neo4j.driver.internal.value.RelationshipValue)8 HashMap (java.util.HashMap)7 InternalRecord (org.neo4j.driver.internal.InternalRecord)7 Node (org.neo4j.driver.types.Node)6 Relationship (org.neo4j.driver.types.Relationship)6 Matchers.anyObject (org.mockito.Matchers.anyObject)4 Result (org.neo4j.driver.Result)4 ProfiledPlan (org.neo4j.driver.summary.ProfiledPlan)4