Search in sources :

Example 41 with Node

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")));
}
Also used : Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 42 with Node

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));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyEntry(org.neo4j.graphdb.event.PropertyEntry) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 43 with Node

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));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyEntry(org.neo4j.graphdb.event.PropertyEntry) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 44 with Node

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);
    }
}
Also used : Node(org.neo4j.graphdb.Node)

Example 45 with Node

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();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) NotFoundException(org.neo4j.graphdb.NotFoundException) Test(org.junit.Test)

Aggregations

Node (org.neo4j.graphdb.Node)1281 Test (org.junit.Test)781 Transaction (org.neo4j.graphdb.Transaction)540 Relationship (org.neo4j.graphdb.Relationship)375 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)146 NotFoundException (org.neo4j.graphdb.NotFoundException)78 File (java.io.File)65 LinkedList (java.util.LinkedList)60 RelationshipType (org.neo4j.graphdb.RelationshipType)58 HashMap (java.util.HashMap)57 Label (org.neo4j.graphdb.Label)57 Path (org.neo4j.graphdb.Path)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 HashSet (java.util.HashSet)45 Map (java.util.Map)45 WeightedPath (org.neo4j.graphalgo.WeightedPath)37 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)35 ArrayList (java.util.ArrayList)30 List (java.util.List)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26