コード例 #1
0
 @Test
 public void shouldAllowCreateRelationshipWithSameStartAsEndNode() throws Exception {
   long nodeId = graphdbHelper.createNode();
   Map<String, Object> properties = Collections.<String, Object>emptyMap();
   RelationshipRepresentation rel =
       actions.createRelationship(nodeId, nodeId, "Loves", properties);
   assertNotNull(rel);
 }
コード例 #2
0
 @Test
 public void shouldNotCreateRelationshipBetweenNonExistentNodes() throws Exception {
   long nodeId = graphdbHelper.createNode();
   Map<String, Object> properties = Collections.<String, Object>emptyMap();
   try {
     actions.createRelationship(nodeId, nodeId * 1000, "Loves", properties);
     fail();
   } catch (EndNodeNotFoundException e) {
     // ok
   }
   try {
     actions.createRelationship(nodeId * 1000, nodeId, "Loves", properties);
     fail();
   } catch (StartNodeNotFoundException e) {
     // ok
   }
 }
コード例 #3
0
 @Test
 public void shouldStoreRelationshipsBetweenTwoExistingNodes() throws Exception {
   int relationshipCount = graphdbHelper.getNumberOfRelationships();
   actions.createRelationship(
       graphdbHelper.createNode(),
       graphdbHelper.createNode(),
       "LOVES",
       Collections.<String, Object>emptyMap());
   assertEquals(relationshipCount + 1, graphdbHelper.getNumberOfRelationships());
 }
コード例 #4
0
  @Test
  public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("string", "value");
    properties.put("integer", 17);
    long relId =
        actions
            .createRelationship(
                graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES", properties)
            .getId();

    Transaction tx = database.getGraph().beginTx();
    try {
      Relationship rel = database.getGraph().getRelationshipById(relId);
      for (String key : rel.getPropertyKeys()) {
        assertTrue("extra property stored", properties.containsKey(key));
      }
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        assertEquals(entry.getValue(), rel.getProperty(entry.getKey()));
      }
    } finally {
      tx.finish();
    }
  }