use of org.neo4j.graphdb.Node 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.Node in project neo4j by neo4j.
the class TestRelationship method createRelationshipAfterClearedCache.
@Test
public void createRelationshipAfterClearedCache() {
// Assumes relationship grab size 100
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
int expectedCount = 0;
for (int i = 0; i < 150; i++) {
node1.createRelationshipTo(node2, TEST);
expectedCount++;
}
newTransaction();
for (int i = 0; i < 50; i++) {
node1.createRelationshipTo(node2, TEST);
expectedCount++;
}
assertEquals(expectedCount, Iterables.count(node1.getRelationships()));
newTransaction();
assertEquals(expectedCount, Iterables.count(node1.getRelationships()));
}
use of org.neo4j.graphdb.Node 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.Node 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.Node in project neo4j by neo4j.
the class TestRelationshipCount method testGetRelationshipTypesOnDenseNode.
@Test
public void testGetRelationshipTypesOnDenseNode() throws Exception {
Node node = getGraphDb().createNode();
Node otherNode = getGraphDb().createNode();
for (int i = 0; i < 300; i++) {
node.createRelationshipTo(otherNode, RelType.INITIAL);
}
testGetRelationshipTypes(node, new HashSet<>(asList(RelType.INITIAL.name())));
}
Aggregations