Search in sources :

Example 6 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class BoltResponseMessageTest method shouldSerializeRelationship.

@Test
void shouldSerializeRelationship() throws Throwable {
    RelationshipValue rel = relationshipValue(12L, nodeValue(1L, stringArray(), VirtualValues.EMPTY_MAP), nodeValue(2L, stringArray(), VirtualValues.EMPTY_MAP), stringValue("KNOWS"), VirtualValues.map(new String[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) }));
    assertThat(serialized(rel)).isEqualTo("B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E");
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test)

Example 7 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class DefaultValueMapperTest method shouldMapDirectRelationship.

@Test
void shouldMapDirectRelationship() {
    // Given
    Node start, end;
    Relationship relationship;
    try (Transaction tx = db.beginTx()) {
        start = tx.createNode();
        end = tx.createNode();
        relationship = start.createRelationshipTo(end, RelationshipType.withName("R"));
        tx.commit();
    }
    RelationshipValue relationshipValue = VirtualValues.relationshipValue(relationship.getId(), nodeValue(start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), nodeValue(start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), stringValue("R"), EMPTY_MAP);
    // Then
    try (Transaction tx = db.beginTx()) {
        var mapper = new DefaultValueMapper((InternalTransaction) tx);
        Relationship coreAPIRelationship = mapper.mapRelationship(relationshipValue);
        assertThat(coreAPIRelationship.getId()).isEqualTo(relationship.getId());
        assertThat(coreAPIRelationship.getStartNode()).isEqualTo(start);
        assertThat(coreAPIRelationship.getEndNode()).isEqualTo(end);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test)

Example 8 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathWrappingPathValue method relationships.

@Override
public RelationshipValue[] relationships() {
    int length = path.length();
    RelationshipValue[] values = new RelationshipValue[length];
    int i = 0;
    for (Relationship relationship : path.relationships()) {
        values[i++] = ValueUtils.fromRelationshipEntity(relationship);
    }
    return values;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipValue(org.neo4j.values.virtual.RelationshipValue)

Example 9 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilderTest method shouldHandleNoValueInMultiRel.

@Test
void shouldHandleNoValueInMultiRel() {
    // Given  (n1)<--(n2)-->(n3)
    NodeValue node1 = node(42);
    NodeValue node2 = node(43);
    NodeValue node3 = node(44);
    RelationshipValue relationship1 = relationship(1337, node2, node1);
    RelationshipValue relationship2 = relationship(1338, node2, node3);
    PathValueBuilder builder = builder(node1, node2, node3, relationship1, relationship2);
    // When (n1)<--(n2)--(n3)
    builder.addNode(node1);
    builder.addMultipleUndirected(list(relationship1, relationship2, NO_VALUE));
    // Then
    assertEquals(NO_VALUE, builder.build());
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test)

Example 10 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilderTest method shouldHandleLongerPath.

@Test
void shouldHandleLongerPath() {
    // Given  (n1)<--(n2)-->(n3)
    NodeValue n1 = node(42);
    NodeValue n2 = node(43);
    NodeValue n3 = node(44);
    RelationshipValue r1 = relationship(1337, n2, n1);
    RelationshipValue r2 = relationship(1338, n2, n3);
    PathValueBuilder builder = builder(n1, n2, n3, r1, r2);
    // When (n1)<--(n2)--(n3)
    builder.addNode(n1);
    builder.addIncoming(r1);
    builder.addUndirected(r2);
    // Then
    assertEquals(path(n1, r1, n2, r2, n3), builder.build());
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipValue (org.neo4j.values.virtual.RelationshipValue)24 Test (org.junit.jupiter.api.Test)15 NodeValue (org.neo4j.values.virtual.NodeValue)13 AnyValue (org.neo4j.values.AnyValue)11 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)6 ListValue (org.neo4j.values.virtual.ListValue)3 PathValue (org.neo4j.values.virtual.PathValue)3 Relationship (org.neo4j.graphdb.Relationship)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 MapValue (org.neo4j.values.virtual.MapValue)2 VirtualNodeValue (org.neo4j.values.virtual.VirtualNodeValue)2 VirtualRelationshipValue (org.neo4j.values.virtual.VirtualRelationshipValue)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 Mockito (org.mockito.Mockito)1 Mockito.mock (org.mockito.Mockito.mock)1