use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testDirectedRelationship.
@Test
public void testDirectedRelationship() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel2 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship rel3 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
Node[] nodes = rel2.getNodes();
assertEquals(2, nodes.length);
assertTrue(nodes[0].equals(node1) && nodes[1].equals(node2));
nodes = rel3.getNodes();
assertEquals(2, nodes.length);
assertTrue(nodes[0].equals(node2) && nodes[1].equals(node1));
assertEquals(node1, rel2.getStartNode());
assertEquals(node2, rel2.getEndNode());
assertEquals(node2, rel3.getStartNode());
assertEquals(node1, rel3.getEndNode());
Relationship[] relArray = getRelationshipArray(node1.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
assertEquals(1, relArray.length);
assertEquals(rel2, relArray[0]);
relArray = getRelationshipArray(node1.getRelationships(MyRelTypes.TEST, Direction.INCOMING));
assertEquals(1, relArray.length);
assertEquals(rel3, relArray[0]);
relArray = getRelationshipArray(node2.getRelationships(MyRelTypes.TEST, Direction.OUTGOING));
assertEquals(1, relArray.length);
assertEquals(rel3, relArray[0]);
relArray = getRelationshipArray(node2.getRelationships(MyRelTypes.TEST, Direction.INCOMING));
assertEquals(1, relArray.length);
assertEquals(rel2, relArray[0]);
rel2.delete();
rel3.delete();
node1.delete();
node2.delete();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testRelGetProperties.
@Test
public void testRelGetProperties() {
Integer int1 = new Integer(1);
Integer int2 = new Integer(2);
String string = new String("3");
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
try {
rel1.getProperty(key1);
fail("get non existing property din't throw exception");
} catch (NotFoundException e) {
// OK
}
try {
rel1.getProperty(null);
fail("get of null key din't throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertTrue(!rel1.hasProperty(key1));
assertTrue(!rel1.hasProperty(null));
rel1.setProperty(key1, int1);
rel1.setProperty(key2, int2);
rel1.setProperty(key3, string);
assertTrue(rel1.hasProperty(key1));
assertTrue(rel1.hasProperty(key2));
assertTrue(rel1.hasProperty(key3));
Map<String, Object> properties = rel1.getAllProperties();
assertTrue(properties.get(key1).equals(int1));
assertTrue(properties.get(key2).equals(int2));
assertTrue(properties.get(key3).equals(string));
properties = rel1.getProperties(key1, key2);
assertTrue(properties.get(key1).equals(int1));
assertTrue(properties.get(key2).equals(int2));
assertFalse(properties.containsKey(key3));
properties = node1.getProperties();
assertTrue(properties.isEmpty());
try {
String[] names = null;
node1.getProperties(names);
fail();
} catch (NullPointerException e) {
// Ok
}
try {
String[] names = new String[] { null };
node1.getProperties(names);
fail();
} catch (NullPointerException e) {
// Ok
}
try {
rel1.removeProperty(key3);
} catch (NotFoundException e) {
fail("Remove of property failed.");
}
assertTrue(!rel1.hasProperty(key3));
assertTrue(!rel1.hasProperty(null));
rel1.delete();
node2.delete();
node1.delete();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testAddPropertyThenDelete.
@Test
public void testAddPropertyThenDelete() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
rel.setProperty("test", "test");
newTransaction();
rel.setProperty("test2", "test2");
rel.delete();
node1.delete();
node2.delete();
newTransaction();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testRelationshipIsType.
@Test
public void testRelationshipIsType() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel = node1.createRelationshipTo(node2, MyRelTypes.TEST);
assertTrue(rel.isType(MyRelTypes.TEST));
assertTrue(rel.isType(new RelationshipType() {
@Override
public String name() {
return MyRelTypes.TEST.name();
}
}));
assertFalse(rel.isType(MyRelTypes.TEST_TRAVERSAL));
rel.delete();
node1.delete();
node2.delete();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationshipCount method deleteOneRelationship.
private void deleteOneRelationship(Node node, RelType type, Direction direction, int which) {
Relationship last = null;
int counter = 0;
for (Relationship rel : node.getRelationships(type, direction)) {
if (isLoop(rel) == (direction == Direction.BOTH)) {
last = rel;
if (counter++ == which) {
rel.delete();
return;
}
}
}
if (which == Integer.MAX_VALUE && last != null) {
last.delete();
return;
}
fail("Couldn't find " + (direction == Direction.BOTH ? "loop" : "non-loop") + " relationship " + type.name() + " " + direction + " to delete");
}
Aggregations