use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testRelationshipRemoveProperty.
@Test
public void testRelationshipRemoveProperty() {
Integer int1 = new Integer(1);
Integer int2 = new Integer(2);
String string1 = new String("1");
String string2 = new String("2");
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
// verify that we can rely on PL to reomve non existing properties
try {
if (rel1.removeProperty(key1) != null) {
fail("Remove of non existing property should return null");
}
} catch (NotFoundException e) {
// OK
}
try {
rel1.removeProperty(null);
fail("Remove null property should throw exception.");
} catch (IllegalArgumentException e) {
// OK
}
rel1.setProperty(key1, int1);
rel2.setProperty(key1, string1);
rel1.setProperty(key2, string2);
rel2.setProperty(key2, int2);
try {
rel1.removeProperty(null);
fail("Null argument should result in exception.");
} catch (IllegalArgumentException e) {
// OK
}
// test remove property
assertEquals(int1, rel1.removeProperty(key1));
assertEquals(string1, rel2.removeProperty(key1));
// test remove of non existing property
try {
if (rel2.removeProperty(key1) != null) {
fail("Remove of non existing property should return null");
}
} catch (NotFoundException e) {
// have to set rollback only here
getTransaction().failure();
}
rel1.delete();
rel2.delete();
node1.delete();
node2.delete();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testRelationshipAddProperty.
@Test
public void testRelationshipAddProperty() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
Relationship rel2 = node2.createRelationshipTo(node1, MyRelTypes.TEST);
try {
rel1.setProperty(null, null);
fail("Null argument should result in exception.");
} catch (IllegalArgumentException e) {
// OK
}
Integer int1 = new Integer(1);
Integer int2 = new Integer(2);
String string1 = new String("1");
String string2 = new String("2");
// add property
rel1.setProperty(key1, int1);
rel2.setProperty(key1, string1);
rel1.setProperty(key2, string2);
rel2.setProperty(key2, int2);
assertTrue(rel1.hasProperty(key1));
assertTrue(rel2.hasProperty(key1));
assertTrue(rel1.hasProperty(key2));
assertTrue(rel2.hasProperty(key2));
assertTrue(!rel1.hasProperty(key3));
assertTrue(!rel2.hasProperty(key3));
assertEquals(int1, rel1.getProperty(key1));
assertEquals(string1, rel2.getProperty(key1));
assertEquals(string2, rel1.getProperty(key2));
assertEquals(int2, rel2.getProperty(key2));
getTransaction().failure();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method getAllRelationships.
@Test
public void getAllRelationships() throws Exception {
Set<Relationship> existingRelationships = Iterables.addToCollection(getGraphDb().getAllRelationships(), new HashSet<>());
Set<Relationship> createdRelationships = new HashSet<>();
Node node = getGraphDb().createNode();
for (int i = 0; i < 100; i++) {
createdRelationships.add(node.createRelationshipTo(getGraphDb().createNode(), MyRelTypes.TEST));
}
newTransaction();
Set<Relationship> allRelationships = new HashSet<>();
allRelationships.addAll(existingRelationships);
allRelationships.addAll(createdRelationships);
int count = 0;
for (Relationship rel : getGraphDb().getAllRelationships()) {
assertTrue("Unexpected rel " + rel + ", expected one of " + allRelationships, allRelationships.contains(rel));
count++;
}
assertEquals(allRelationships.size(), count);
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method testCreateRelationshipWithCommitts.
@Test
public // throws NotFoundException
void testCreateRelationshipWithCommitts() {
Node n1 = getGraphDb().createNode();
newTransaction();
n1 = getGraphDb().getNodeById(n1.getId());
Node n2 = getGraphDb().createNode();
n1.createRelationshipTo(n2, MyRelTypes.TEST);
newTransaction();
Relationship[] relArray = getRelationshipArray(n1.getRelationships());
assertEquals(1, relArray.length);
relArray = getRelationshipArray(n1.getRelationships());
relArray[0].delete();
n1.delete();
n2.delete();
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestRelationship method deletionOfAlreadyDeletedRelationshipShouldThrow.
@Test(expected = NotFoundException.class)
public void deletionOfAlreadyDeletedRelationshipShouldThrow() {
// Given
GraphDatabaseService db = getGraphDb();
// transaction is opened by test
Node node1 = db.createNode();
Node node2 = db.createNode();
Relationship relationship = node1.createRelationshipTo(node2, TEST);
commit();
try (Transaction tx = db.beginTx()) {
relationship.delete();
tx.success();
}
// When
try (Transaction tx = db.beginTx()) {
relationship.delete();
tx.success();
}
}
Aggregations