Ejemplo n.º 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);
 }
Ejemplo n.º 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
   }
 }
Ejemplo n.º 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());
 }
Ejemplo n.º 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();
    }
  }