use of org.neo4j.shell.state.BoltResult 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));
}
use of org.neo4j.shell.state.BoltResult 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"));
}
use of org.neo4j.shell.state.BoltResult in project neo4j by neo4j.
the class CypherShellTest method executeShouldPrintResult.
@Test
public void executeShouldPrintResult() throws CommandException {
Driver mockedDriver = mock(Driver.class);
Session session = mock(Session.class);
BoltResult result = mock(ListBoltResult.class);
BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
when(boltStateHandler.isConnected()).thenReturn(true);
when(boltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(result));
doAnswer(a -> {
((LinePrinter) a.getArguments()[1]).printOut("999");
return null;
}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
when(mockedDriver.session()).thenReturn(session);
OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);
shell.execute("RETURN 999");
verify(logger).printOut(contains("999"));
}
use of org.neo4j.shell.state.BoltResult in project neo4j by neo4j.
the class CypherShellTest method setParamShouldAddParam.
@Test
public void setParamShouldAddParam() throws ParameterException, CommandException {
Value value = mock(Value.class);
Record recordMock = mock(Record.class);
BoltResult boltResult = mock(ListBoltResult.class);
when(mockedBoltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(boltResult));
when(boltResult.getRecords()).thenReturn(asList(recordMock));
when(recordMock.get("bob")).thenReturn(value);
when(value.asObject()).thenReturn("99");
assertTrue(offlineTestShell.getParameterMap().allParameterValues().isEmpty());
Object result = offlineTestShell.getParameterMap().setParameter("`bob`", "99");
assertEquals(99L, result);
assertEquals(99L, offlineTestShell.getParameterMap().allParameterValues().get("bob"));
}
use of org.neo4j.shell.state.BoltResult 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));
}
Aggregations