private Object toRelationship(Object value, boolean virtual, Map<Long, Object> nodesCache) { Value internalValue = ((InternalEntity) value).asValue(); Relationship relationship = internalValue.asRelationship(); if (virtual) { VirtualNode start = (VirtualNode) nodesCache.getOrDefault(relationship.startNodeId(), new VirtualNode(relationship.startNodeId(), db)); VirtualNode end = (VirtualNode) nodesCache.getOrDefault(relationship.endNodeId(), new VirtualNode(relationship.endNodeId(), db)); VirtualRelationship virtualRelationship = new VirtualRelationship(relationship.id(), start, end, RelationshipType.withName(relationship.type()), relationship.asMap()); return virtualRelationship; } else return Util.map("entityType", internalValue.type().name(), "type", relationship.type(), "id", relationship.id(), "start", relationship.startNodeId(), "end", relationship.endNodeId(), "properties", relationship.asMap()); }
@Nonnull default String relationshipAsString(@Nonnull Relationship relationship) { List<String> relationshipAsString = new ArrayList<>(); relationshipAsString.add(COLON + escape(relationship.type())); relationshipAsString.add(mapAsStringWithEmpty(relationship.asMap(this::formatValue))); return "[" + joinWithSpace(relationshipAsString) + "]"; }
public Neo4jBoltRelationship(Relationship rel) { this.id = String.valueOf(rel.id()); this.types = Collections.singletonList(rel.type()); this.propertyContainer = new Neo4jBoltPropertyContainer(rel.asMap()); this.startNodeId = String.valueOf(rel.startNodeId()); this.endNodeId = String.valueOf(rel.endNodeId()); }
@Test public void prettyPrintRelationships() throws Exception { // given BoltResult result = mock(BoltResult.class); Record record = mock(Record.class); Value value = mock(Value.class); Relationship relationship = mock(Relationship.class); HashMap<String, Object> propertiesAsMap = new HashMap<>(); propertiesAsMap.put("prop1", "prop1_value"); propertiesAsMap.put("prop2", "prop2_value"); when(value.type()).thenReturn(InternalTypeSystem.TYPE_SYSTEM.RELATIONSHIP()); when(value.asRelationship()).thenReturn(relationship); when(relationship.type()).thenReturn("RELATIONSHIP_TYPE"); when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(propertiesAsMap)); when(record.keys()).thenReturn(asList("rel")); when(record.values()).thenReturn(asList(value)); when(result.getRecords()).thenReturn(asList(record)); when(result.getSummary()).thenReturn(mock(ResultSummary.class)); // when String actual = plainPrinter.format(result); // then assertThat(actual, is("rel\n[:RELATIONSHIP_TYPE {prop2: prop2_value, prop1: prop1_value}]")); }
when(relationship.asMap(anyObject())).thenReturn(unmodifiableMap(relProp));