コード例 #1
0
  @Test
  public void testCreateRelationship() {
    Node n1 = restAPI.createNode(map("name", "newnode1"));
    final Transaction tx = restAPI.beginTx();

    Node n2 = restAPI.createNode(map("name", "newnode2"));
    RestRelationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
    Iterable<Relationship> allRelationships = n1.getRelationships();

    tx.success();
    tx.finish();
    Relationship foundRelationship =
        TestHelper.firstRelationshipBetween(
            n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
    Assert.assertNotNull("found relationship", foundRelationship);
    assertEquals("same relationship", rel, foundRelationship);
    assertEquals("rel", rel.getProperty("name"));

    assertThat(
        n1.getRelationships(Type.TEST, Direction.OUTGOING),
        new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.OUTGOING), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.BOTH), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Type.TEST), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(allRelationships, new IsRelationshipToNodeMatcher(n1, n2));
  }
コード例 #2
0
 @Test
 public void testDeleteRelationship() {
   Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "newnode1"));
   Node n2 = restAPI.createNode(map("name", "newnode2"));
   Relationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
   rel.delete();
   tx.success();
   tx.finish();
   Relationship foundRelationship =
       TestHelper.firstRelationshipBetween(
           n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
   Assert.assertNull("found relationship", foundRelationship);
 }