Search in sources :

Example 6 with Value

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

the class TableOutputFormatterTest method printRelationshipsAndNodesWithEscapingForSpecialCharacters.

@Test
public void printRelationshipsAndNodesWithEscapingForSpecialCharacters() {
    // given
    Record record = mock(Record.class);
    Map<String, Value> propertiesAsMap = new HashMap<>();
    propertiesAsMap.put("prop1", Values.value("prop1, value"));
    propertiesAsMap.put("prop2", Values.value(1));
    Value relVal = new RelationshipValue(new InternalRelationship(1, 1, 2, "RELATIONSHIP,TYPE", propertiesAsMap));
    List<String> labels = asList("label `1", "label2");
    Map<String, Value> nodeProperties = new HashMap<>();
    nodeProperties.put("prop1", Values.value("prop1:value"));
    String doubleQuotes = "\"\"";
    nodeProperties.put("1prop1", Values.value(doubleQuotes));
    nodeProperties.put("ä", Values.value("not-escaped"));
    Value nodeVal = new NodeValue(new InternalNode(1, labels, nodeProperties));
    Map<String, Value> recordMap = new LinkedHashMap<>();
    recordMap.put("rel", relVal);
    recordMap.put("node", nodeVal);
    List<String> keys = asList("rel", "node");
    when(record.keys()).thenReturn(keys);
    when(record.size()).thenReturn(2);
    when(record.get(0)).thenReturn(relVal);
    when(record.get(1)).thenReturn(nodeVal);
    when(record.<Value>asMap(anyObject())).thenReturn(recordMap);
    when(record.values()).thenReturn(asList(relVal, nodeVal));
    // when
    String actual = verbosePrinter.format(new ListBoltResult(asList(record), mock(ResultSummary.class)));
    // then
    assertThat(actual, containsString("| [:`RELATIONSHIP,TYPE` {prop2: 1, prop1: \"prop1, value\"}] |"));
    assertThat(actual, containsString("| (:`label ``1`:label2 {`1prop1`: \"\\\"\\\"\", " + "prop1: \"prop1:value\", ä: \"not-escaped\"}) |"));
}
Also used : NodeValue(org.neo4j.driver.internal.value.NodeValue) 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) InternalNode(org.neo4j.driver.internal.InternalNode) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with Value

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

the class TablePlanFormatterTest method withEmptyDetails.

@Test
public void withEmptyDetails() {
    Plan plan = mock(Plan.class);
    Map<String, Value> args = new HashMap<String, Value>(2) {

        {
            put("EstimatedRows", new FloatValue(55));
            put("Details", new StringValue(""));
        }
    };
    when(plan.arguments()).thenReturn(args);
    when(plan.operatorType()).thenReturn("Projection");
    assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+-------------+---------+----------------+", "| Operator    | Details | Estimated Rows |", "+-------------+---------+----------------+", "| +Projection |         |             55 |", "+-------------+---------+----------------+", "")));
}
Also used : HashMap(java.util.HashMap) 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) StringValue(org.neo4j.driver.internal.value.StringValue) Test(org.junit.Test)

Example 8 with Value

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

the class TablePlanFormatterTest method renderShortDetails.

@Test
public void renderShortDetails() {
    Plan plan = mock(Plan.class);
    Map<String, Value> args = Collections.singletonMap("Details", new StringValue("x.prop AS prop"));
    when(plan.arguments()).thenReturn(args);
    when(plan.operatorType()).thenReturn("Projection");
    assertThat(tablePlanFormatter.formatPlan(plan), is(String.join(NEWLINE, "+-------------+----------------+", "| Operator    | Details        |", "+-------------+----------------+", "| +Projection | x.prop AS prop |", "+-------------+----------------+", "")));
}
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 9 with Value

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

the class TablePlanFormatterTest method renderExactMaxLengthDetails.

@Test
public void renderExactMaxLengthDetails() {
    Plan plan = mock(Plan.class);
    String details = stringOfLength(TablePlanFormatter.MAX_DETAILS_COLUMN_WIDTH);
    Map<String, Value> args = Collections.singletonMap("Details", new StringValue(details));
    when(plan.arguments()).thenReturn(args);
    when(plan.operatorType()).thenReturn("Projection");
    assertThat(tablePlanFormatter.formatPlan(plan), containsString("| +Projection | " + details + " |"));
}
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 10 with Value

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

the class BoltStateHandlerTest method triesAgainOnSessionExpired.

@Test
public void triesAgainOnSessionExpired() throws Exception {
    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))).thenThrow(new SessionExpiredException("leaderswitch")).thenReturn(resultMock);
    OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock);
    boltStateHandler.connect();
    BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get();
    verify(driverMock, times(2)).session(any());
    verify(sessionMock, times(2)).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) SessionExpiredException(org.neo4j.driver.exceptions.SessionExpiredException) 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