use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestRelationship method testDeletedRelationship.
@Test
public void testDeletedRelationship() {
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship relationship = node1.createRelationshipTo(node2, MyRelTypes.TEST);
relationship.delete();
try {
relationship.setProperty("key1", new Integer(1));
fail("Adding property to deleted rel should throw exception.");
} catch (Exception e) {
// good
}
node1.delete();
node2.delete();
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
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) {
}
try {
rel1.getProperty(null);
fail("get of null key din't throw exception");
} catch (IllegalArgumentException e) {
}
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));
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 graphdb by neo4j-attic.
the class TestTransactionEvents method shouldGetCorrectTransactionDataUponCommit.
@Test
public void shouldGetCorrectTransactionDataUponCommit() {
makeSureRelationshipTypeIsCreated(RelTypes.TXEVENT);
// Create new data, nothing modified, just added/created
ExpectedTransactionData expectedData = new ExpectedTransactionData();
VerifyingTransactionEventHandler handler = new VerifyingTransactionEventHandler(expectedData);
getGraphDb().registerTransactionEventHandler(handler);
newTransaction();
Node node1 = null, node2 = null, node3 = null;
Relationship rel1 = null, rel2 = null;
try {
node1 = getGraphDb().createNode();
expectedData.expectedCreatedNodes.add(node1);
node2 = getGraphDb().createNode();
expectedData.expectedCreatedNodes.add(node2);
rel1 = node1.createRelationshipTo(node2, RelTypes.TXEVENT);
expectedData.expectedCreatedRelationships.add(rel1);
node1.setProperty("name", "Mattias");
expectedData.assignedProperty(node1, "name", "Mattias", null);
node1.setProperty("last name", "Persson");
expectedData.assignedProperty(node1, "last name", "Persson", null);
node1.setProperty("counter", 10);
expectedData.assignedProperty(node1, "counter", 10, null);
rel1.setProperty("description", "A description");
expectedData.assignedProperty(rel1, "description", "A description", null);
rel1.setProperty("number", 4.5D);
expectedData.assignedProperty(rel1, "number", 4.5D, null);
node3 = getGraphDb().createNode();
expectedData.expectedCreatedNodes.add(node3);
rel2 = node3.createRelationshipTo(node2, RelTypes.TXEVENT);
expectedData.expectedCreatedRelationships.add(rel2);
node3.setProperty("name", "Node 3");
expectedData.assignedProperty(node3, "name", "Node 3", null);
newTransaction();
assertTrue(handler.hasBeenCalled());
} finally {
getGraphDb().unregisterTransactionEventHandler(handler);
}
// Use the above data and modify it, change properties, delete stuff
expectedData = new ExpectedTransactionData();
handler = new VerifyingTransactionEventHandler(expectedData);
getGraphDb().registerTransactionEventHandler(handler);
newTransaction();
try {
Node tempNode = getGraphDb().createNode();
Relationship tempRel = tempNode.createRelationshipTo(node1, RelTypes.TXEVENT);
tempNode.setProperty("something", "Some value");
tempRel.setProperty("someproperty", 101010);
tempNode.removeProperty("nothing");
node3.setProperty("test", "hello");
node3.setProperty("name", "No name");
node3.delete();
expectedData.expectedDeletedNodes.add(node3);
expectedData.removedProperty(node3, "name", null, "Node 3");
node1.setProperty("new name", "A name");
node1.setProperty("new name", "A better name");
expectedData.assignedProperty(node1, "new name", "A better name", null);
node1.setProperty("name", "Nothing");
node1.setProperty("name", "Mattias Persson");
expectedData.assignedProperty(node1, "name", "Mattias Persson", "Mattias");
node1.removeProperty("counter");
expectedData.removedProperty(node1, "counter", null, 10);
node1.removeProperty("last name");
node1.setProperty("last name", "Hi");
expectedData.assignedProperty(node1, "last name", "Hi", "Persson");
rel2.delete();
expectedData.expectedDeletedRelationships.add(rel2);
rel1.removeProperty("number");
expectedData.removedProperty(rel1, "number", null, 4.5D);
rel1.setProperty("description", "Ignored");
rel1.setProperty("description", "New");
expectedData.assignedProperty(rel1, "description", "New", "A description");
tempRel.delete();
tempNode.delete();
newTransaction();
} finally {
getGraphDb().unregisterTransactionEventHandler(handler);
}
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
the class TestReadOnlyNeo4j method testReadOnlyOperationsAndNoTransaction.
@Test
public void testReadOnlyOperationsAndNoTransaction() {
GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
Transaction tx = db.beginTx();
Node node1 = db.createNode();
Node node2 = db.createNode();
Relationship rel = node1.createRelationshipTo(node2, withName("TEST"));
node1.setProperty("key1", "value1");
rel.setProperty("key1", "value1");
tx.success();
tx.finish();
// make sure write operations still throw exception
try {
db.createNode();
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.createRelationshipTo(node2, withName("TEST2"));
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
node1.setProperty("key1", "value2");
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
try {
rel.removeProperty("key1");
fail("Write operation and no transaction should throw exception");
} catch (NotInTransactionException e) {
// good
}
// clear caches and try reads
((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
assertEquals(node1, db.getNodeById(node1.getId()));
assertEquals(node2, db.getNodeById(node2.getId()));
assertEquals(rel, db.getRelationshipById(rel.getId()));
((AbstractGraphDatabase) db).getConfig().getGraphDbModule().getNodeManager().clearCache();
assertEquals("value1", node1.getProperty("key1"));
Relationship loadedRel = node1.getSingleRelationship(DynamicRelationshipType.withName("TEST"), Direction.OUTGOING);
assertEquals(rel, loadedRel);
assertEquals("value1", loadedRel.getProperty("key1"));
}
use of org.neo4j.graphdb.Relationship in project graphdb by neo4j-attic.
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) {
}
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();
}
Aggregations