use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestShortStringProperties method canAddMultipleShortStringsToTheSameNode.
@Test
public void canAddMultipleShortStringsToTheSameNode() throws Exception {
long recordCount = dynamicRecordsInUse();
Node node = graphdb.getGraphDatabaseAPI().createNode();
node.setProperty("key", "value");
node.setProperty("reverse", "esrever");
commit();
assertEquals(recordCount, dynamicRecordsInUse());
assertThat(node, inTx(graphdb.getGraphDatabaseAPI(), hasProperty("key").withValue("value")));
assertThat(node, inTx(graphdb.getGraphDatabaseAPI(), hasProperty("reverse").withValue("esrever")));
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method shouldListAddedNodePropertiesProperties.
@Test
public void shouldListAddedNodePropertiesProperties() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty prevProp = stringProperty(propertyKeyId, "prevValue");
state.nodeDoChangeProperty(1L, prevProp, stringProperty(propertyKeyId, "newValue"));
when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
long propertyId = 20L;
when(storeStatement.acquireSingleNodeCursor(1L)).thenReturn(asNodeCursor(1L, propertyId, labels()));
when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevProp));
// When
Iterable<PropertyEntry<Node>> propertyEntries = snapshot().assignedNodeProperties();
// Then
PropertyEntry<Node> entry = single(propertyEntries);
assertThat(entry.key(), equalTo("theKey"));
assertThat(entry.value(), equalTo((Object) "newValue"));
assertThat(entry.previouslyCommitedValue(), equalTo((Object) "prevValue"));
assertThat(entry.entity().getId(), equalTo(1L));
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method shouldListRemovedNodeProperties.
@Test
public void shouldListRemovedNodeProperties() throws Exception {
// Given
int propertyKeyId = 1;
DefinedProperty prevProp = stringProperty(propertyKeyId, "prevValue");
state.nodeDoRemoveProperty(1L, prevProp);
when(ops.propertyKeyGetName(propertyKeyId)).thenReturn("theKey");
long propertyId = 20L;
when(storeStatement.acquireSingleNodeCursor(1L)).thenReturn(asNodeCursor(1L, propertyId, labels()));
when(storeStatement.acquireSinglePropertyCursor(propertyId, propertyKeyId, NO_LOCK)).thenReturn(asPropertyCursor(prevProp));
// When
Iterable<PropertyEntry<Node>> propertyEntries = snapshot().removedNodeProperties();
// Then
PropertyEntry<Node> entry = single(propertyEntries);
assertThat(entry.key(), equalTo("theKey"));
assertThat(entry.previouslyCommitedValue(), equalTo("prevValue"));
assertThat(entry.entity().getId(), equalTo(1L));
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestTransactionEvents method createTree.
private void createTree(Node parent, int maxDepth, int width, int currentDepth) {
if (currentDepth > maxDepth) {
return;
}
for (int i = 0; i < width; i++) {
Node child = dbRule.createNode(TestLabels.LABEL_TWO);
parent.createRelationshipTo(child, MyRelTypes.TEST);
createTree(child, maxDepth, width, currentDepth + 1);
}
}
use of org.neo4j.graphdb.Node 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();
}
Aggregations