use of org.neo4j.driver.Value in project neo4j by neo4j.
the class SnapshotExecutionTest method testCollectionVirtualTypes.
// As hard as it might be to believe, we actually had a bug in this area.
// Since most tests work with primitives (storable values), this is a smoke test that
// collection virtual types work as result of Snapshot EE
@Test
void testCollectionVirtualTypes() {
var query = "RETURN { key: 'Hello', listKey: [{ inner: 'Map1' }, { inner: 'Map2' }]} AS m";
Value m = driver.session().run(query).stream().map(r -> r.get("m")).findFirst().get();
var expected = Values.value(Map.of("key", "Hello", "listKey", List.of(Map.of("inner", "Map1"), Map.of("inner", "Map2"))));
assertEquals(expected, m);
}
use of org.neo4j.driver.Value 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.driver.Value in project neo4j by neo4j.
the class TablePlanFormatterTest method multiLineDetails.
@Test
public void multiLineDetails() {
Plan argumentPlan = mock(Plan.class);
when(argumentPlan.arguments()).thenReturn(Collections.emptyMap());
when(argumentPlan.operatorType()).thenReturn("Argument");
Plan childPlan = mock(Plan.class);
Map<String, Value> args = Collections.singletonMap("Details", new StringValue(stringOfLength(TablePlanFormatter.MAX_DETAILS_COLUMN_WIDTH + 5)));
when(childPlan.arguments()).thenReturn(args);
when(childPlan.operatorType()).thenReturn("Expand");
doReturn(new ArrayList<Plan>() {
{
add(argumentPlan);
add(argumentPlan);
}
}).when(childPlan).children();
Plan plan = mock(Plan.class);
String details = stringOfLength(TablePlanFormatter.MAX_DETAILS_COLUMN_WIDTH + 1);
args = Collections.singletonMap("Details", new StringValue(details));
when(plan.arguments()).thenReturn(args);
when(plan.operatorType()).thenReturn("Projection");
doReturn(new ArrayList<Plan>() {
{
add(childPlan);
add(childPlan);
}
}).when(plan).children();
assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+---------------+------------------------------------------------------------------------------------------------------+", "| Operator | Details |", "+---------------+------------------------------------------------------------------------------------------------------+", "| +Projection | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |", "| | | a |", "| |\\ +------------------------------------------------------------------------------------------------------+", "| | +Expand | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |", "| | | | aaaaa |", "| | |\\ +------------------------------------------------------------------------------------------------------+", "| | | +Argument | |", "| | | +------------------------------------------------------------------------------------------------------+", "| | +Argument | |", "| | +------------------------------------------------------------------------------------------------------+", "| +Expand | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |", "| | | aaaaa |", "| |\\ +------------------------------------------------------------------------------------------------------+", "| | +Argument | |", "| | +------------------------------------------------------------------------------------------------------+", "| +Argument | |", "+---------------+------------------------------------------------------------------------------------------------------+", "")));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class TablePlanFormatterTest method withNoDetails.
@Test
public void withNoDetails() {
Plan plan = mock(Plan.class);
Map<String, Value> args = Collections.singletonMap("EstimatedRows", new FloatValue(55));
when(plan.arguments()).thenReturn(args);
when(plan.operatorType()).thenReturn("Projection");
assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+-------------+----------------+", "| Operator | Estimated Rows |", "+-------------+----------------+", "| +Projection | 55 |", "+-------------+----------------+", "")));
}
use of org.neo4j.driver.Value in project neo4j by neo4j.
the class BoltStateHandlerTest method shouldRunCypherQuery.
@Test
public void shouldRunCypherQuery() throws CommandException {
Session sessionMock = mock(Session.class);
Result resultMock = mock(Result.class);
Record recordMock = mock(Record.class);
Value valueMock = mock(Value.class);
Driver driverMock = stubResultSummaryInAnOpenSession(resultMock, sessionMock, "neo4j-version");
when(resultMock.list()).thenReturn(singletonList(recordMock));
when(valueMock.toString()).thenReturn("999");
when(recordMock.get(0)).thenReturn(valueMock);
when(sessionMock.run(any(Query.class))).thenReturn(resultMock);
OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
boltStateHandler.connect();
BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get();
verify(sessionMock).run(any(Query.class));
assertEquals("999", boltResult.getRecords().get(0).get(0).toString());
}
Aggregations