Пример #1
0
  private void assertTestRelationship(Relationship relationship) {
    assertEquals("relationship", relationship.getId());
    assertNotNull(relationship.getSources());
    assertEquals(1, relationship.getSources().size());
    assertEquals(
        URI.create("urn:sourceDescription1"), relationship.getSources().get(0).getDescriptionRef());

    assertEquals(RelationshipType.Couple, relationship.getKnownType());

    assertEquals(URI.create("urn:person1"), relationship.getPerson1().getResource());
    assertEquals(URI.create("urn:person2"), relationship.getPerson2().getResource());

    assertNotNull(relationship.getFacts());
    assertEquals(2, relationship.getFacts().size());
    assertEquals("fact", relationship.getFacts().get(0).getId());
    assertEquals("event", relationship.getFacts().get(1).getId());

    assertNotNull(relationship.getIdentifiers());
    assertEquals(1, relationship.getIdentifiers().size());
    assertEquals(URI.create("urn:identifierType"), relationship.getIdentifiers().get(0).getType());
    assertEquals(
        URI.create("urn:identifierValue"), relationship.getIdentifiers().get(0).getValue());

    assertEquals("explanation", relationship.getAttribution().getChangeMessage());
  }
  @Test
  public void testCreateRelationshipToNodeOutsideofBatch() throws Exception {
    final Node node1 = restAPI.createNode(map());
    final Transaction tx = restAPI.beginTx();

    Node node2 = restAPI.createNode(map());
    final Relationship relationship =
        node1.createRelationshipTo(node2, DynamicRelationshipType.withName("foo"));

    tx.success();
    tx.finish();
    assertEquals("foo", relationship.getType().name());
    assertEquals(
        "foo", getGraphDatabase().getRelationshipById(relationship.getId()).getType().name());
  }
Пример #3
0
    private Object toJsonCompatible(Object value) {
      if (value instanceof Node) {
        final Node node = (Node) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) node);
        result.put("_id", node.getId());

        final List<String> labelNames = SubGraph.getLabelNames(node);
        if (!labelNames.isEmpty()) result.put("_labels", labelNames);
        return result;
      }
      if (value instanceof Relationship) {
        final Relationship relationship = (Relationship) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) relationship);
        result.put("_id", relationship.getId());
        result.put("_start", relationship.getStartNode().getId());
        result.put("_end", relationship.getEndNode().getId());
        result.put("_type", relationship.getType().name());
        return result;
      }
      if (value instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) value;
        final Map<String, Object> result = new LinkedHashMap<>(map.size());
        for (Map.Entry<String, Object> entry : map.entrySet()) {
          result.put(entry.getKey(), toJsonCompatible(entry.getValue()));
        }
        return result;
      }
      if (value instanceof Iterable) {
        final List<Object> result = new ArrayList<>();
        for (Object inner : (Iterable) value) {
          result.add(toJsonCompatible(inner));
        }
        return result;
      }
      return value;
    }
 @Test
 @Transactional
 public void testGetRelationship() throws Exception {
   Relationship lookedUpRelationship = neo4jTemplate.getRelationship(relationship1.getId());
   assertThat(lookedUpRelationship, is(relationship1));
 }