Search in sources :

Example 16 with Value

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);
}
Also used : Value(org.neo4j.driver.Value) Test(org.junit.jupiter.api.Test)

Example 17 with Value

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"));
}
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 18 with Value

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     |                                                                                                      |", "+---------------+------------------------------------------------------------------------------------------------------+", "")));
}
Also used : StringValue(org.neo4j.driver.internal.value.StringValue) Value(org.neo4j.driver.Value) FloatValue(org.neo4j.driver.internal.value.FloatValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Plan(org.neo4j.driver.summary.Plan) StringValue(org.neo4j.driver.internal.value.StringValue) Test(org.junit.Test)

Example 19 with Value

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 |", "+-------------+----------------+", "")));
}
Also used : StringValue(org.neo4j.driver.internal.value.StringValue) Value(org.neo4j.driver.Value) FloatValue(org.neo4j.driver.internal.value.FloatValue) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FloatValue(org.neo4j.driver.internal.value.FloatValue) Plan(org.neo4j.driver.summary.Plan) Test(org.junit.Test)

Example 20 with Value

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());
}
Also used : Query(org.neo4j.driver.Query) HashMap(java.util.HashMap) Value(org.neo4j.driver.Value) Driver(org.neo4j.driver.Driver) FakeDriver(org.neo4j.shell.test.bolt.FakeDriver) Record(org.neo4j.driver.Record) Session(org.neo4j.driver.Session) FakeSession(org.neo4j.shell.test.bolt.FakeSession) 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