Search in sources :

Example 76 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class PECListingIT method canListRelationshipPropertyExistenceConstraints.

@Test
public void canListRelationshipPropertyExistenceConstraints() throws Exception {
    // GIVEN
    RelationshipType relType = RelationshipType.withName("KNOWS");
    SchemaHelper.createRelPropertyExistenceConstraint(db, relType, "since");
    // WHEN / THEN
    executeCommand("schema ls", "ON \\(\\)-\\[knows:KNOWS\\]-\\(\\) ASSERT exists\\(knows.since\\)");
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 77 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class PECListingIT method canListBothNodeAndRelationshipPropertyExistenceConstraintsByLabelAndType.

@Test
public void canListBothNodeAndRelationshipPropertyExistenceConstraintsByLabelAndType() throws Exception {
    // GIVEN
    Label label = label("Person");
    RelationshipType relType = RelationshipType.withName("KNOWS");
    // WHEN
    SchemaHelper.createNodePropertyExistenceConstraint(db, label, "name");
    SchemaHelper.createRelPropertyExistenceConstraint(db, relType, "since");
    // THEN
    executeCommand("schema ls -l :Person -r :KNOWS", "ON \\(person:Person\\) ASSERT exists\\(person.name\\)", "ON \\(\\)-\\[knows:KNOWS\\]-\\(\\) ASSERT exists\\(knows.since\\)");
}
Also used : Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 78 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class PECListingIT method canListBothNodeAndRelationshipPropertyExistenceConstraints.

@Test
public void canListBothNodeAndRelationshipPropertyExistenceConstraints() throws Exception {
    // GIVEN
    Label label = label("Person");
    RelationshipType relType = RelationshipType.withName("KNOWS");
    // WHEN
    SchemaHelper.createNodePropertyExistenceConstraint(db, label, "name");
    SchemaHelper.createRelPropertyExistenceConstraint(db, relType, "since");
    // THEN
    executeCommand("schema ls", "ON \\(person:Person\\) ASSERT exists\\(person.name\\)", "ON \\(\\)-\\[knows:KNOWS\\]-\\(\\) ASSERT exists\\(knows.since\\)");
}
Also used : Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 79 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class PECListingIT method shouldHaveCorrectIndentationsInSchemaListing.

@Test
public void shouldHaveCorrectIndentationsInSchemaListing() throws Exception {
    // GIVEN
    Label label = label("Person");
    RelationshipType relType = RelationshipType.withName("KNOWS");
    // WHEN
    SchemaHelper.createUniquenessConstraint(db, label, "name");
    SchemaHelper.createNodePropertyExistenceConstraint(db, label, "name");
    SchemaHelper.createRelPropertyExistenceConstraint(db, relType, "since");
    SchemaHelper.awaitIndexes(db);
    // THEN
    executeCommand("schema", "Indexes", "  ON :Person\\(name\\) ONLINE \\(for uniqueness constraint\\)", "Constraints", "  ON \\(person:Person\\) ASSERT person.name IS UNIQUE", "  ON \\(person:Person\\) ASSERT exists\\(person.name\\)", "  ON \\(\\)-\\[knows:KNOWS\\]-\\(\\) ASSERT exists\\(knows.since\\)");
}
Also used : Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 80 with RelationshipType

use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.

the class CircularGraphTest method testCircularBug.

@Test
public void testCircularBug() {
    final long timestamp = 3;
    try (Transaction tx = beginTx()) {
        getNodeWithName("2").setProperty("timestamp", 1L);
        getNodeWithName("3").setProperty("timestamp", 2L);
        tx.success();
    }
    try (Transaction tx2 = beginTx()) {
        final RelationshipType type = RelationshipType.withName("TO");
        Iterator<Node> nodes = getGraphDb().traversalDescription().depthFirst().relationships(type, Direction.OUTGOING).evaluator(path -> {
            Relationship rel = path.lastRelationship();
            boolean relIsOfType = rel != null && rel.isType(type);
            boolean prune = relIsOfType && (Long) path.endNode().getProperty("timestamp") >= timestamp;
            return Evaluation.of(relIsOfType, !prune);
        }).traverse(node("1")).nodes().iterator();
        assertEquals("2", nodes.next().getProperty("name"));
        assertEquals("3", nodes.next().getProperty("name"));
        assertFalse(nodes.hasNext());
    }
}
Also used : Evaluator(org.neo4j.graphdb.traversal.Evaluator) Iterator(java.util.Iterator) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test) Node(org.neo4j.graphdb.Node) Evaluation(org.neo4j.graphdb.traversal.Evaluation) Path(org.neo4j.graphdb.Path) Relationship(org.neo4j.graphdb.Relationship) Assert.assertFalse(org.junit.Assert.assertFalse) RelationshipType(org.neo4j.graphdb.RelationshipType) Transaction(org.neo4j.graphdb.Transaction) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)97 Node (org.neo4j.graphdb.Node)53 Test (org.junit.Test)45 Relationship (org.neo4j.graphdb.Relationship)38 Transaction (org.neo4j.graphdb.Transaction)18 Direction (org.neo4j.graphdb.Direction)15 Traverser (org.neo4j.graphdb.Traverser)10 NotFoundException (org.neo4j.graphdb.NotFoundException)9 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)7 Label (org.neo4j.graphdb.Label)7 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 Path (org.neo4j.graphdb.Path)6 StopEvaluator (org.neo4j.graphdb.StopEvaluator)6 TraversalPosition (org.neo4j.graphdb.TraversalPosition)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4