-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bbc36ef
commit f0d772b
Showing
7 changed files
with
168 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package apoc.label; | ||
|
||
import org.neo4j.graphdb.*; | ||
import org.neo4j.procedure.Context; | ||
import org.neo4j.procedure.Description; | ||
import org.neo4j.procedure.Name; | ||
import org.neo4j.procedure.UserFunction; | ||
|
||
public class Label { | ||
|
||
@Context public GraphDatabaseService db; | ||
|
||
@UserFunction("apoc.label.exists") | ||
@Description("apoc.label.exists(element, label) - returns true or false related to label existance") | ||
public boolean exists(@Name("node") Object element, @Name("label") String label) { | ||
|
||
return element instanceof Node ? ((Node) element).hasLabel(org.neo4j.graphdb.Label.label(label)) : | ||
element instanceof Relationship ? ((Relationship) element).isType(RelationshipType.withName(label)) : false; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package apoc.label; | ||
|
||
import apoc.util.TestUtil; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.test.TestGraphDatabaseFactory; | ||
|
||
import static apoc.util.TestUtil.testCall; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class LabelTest { | ||
|
||
private static GraphDatabaseService db; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
db = new TestGraphDatabaseFactory().newImpermanentDatabase(); | ||
TestUtil.registerProcedure(db, Label.class); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
db.shutdown(); | ||
} | ||
|
||
@Test | ||
public void testVerifyNodeLabelExistance() throws Exception { | ||
|
||
db.execute("create (a:Person{name:'Foo'})"); | ||
|
||
testCall(db, "MATCH (a) RETURN apoc.label.exists(a, 'Person') as value", | ||
(row) -> { | ||
assertEquals(true, row.get("value")); | ||
}); | ||
testCall(db, "MATCH (a) RETURN apoc.label.exists(a, 'Dog') as value", | ||
(row) -> { | ||
assertEquals(false, row.get("value")); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testVerifyRelTypeExistance() throws Exception { | ||
|
||
|
||
db.execute("create (a:Person{name:'Foo'}), (b:Person{name:'Bar'}), (a)-[:LOVE{since:2010}]->(b)"); | ||
|
||
testCall(db, "MATCH ()-[a]->() RETURN apoc.label.exists(a, 'LOVE') as value", | ||
(row) -> { | ||
assertEquals(true, row.get("value")); | ||
}); | ||
testCall(db, "MATCH ()-[a]->() RETURN apoc.label.exists(a, 'LIVES_IN') as value", | ||
(row) -> { | ||
assertEquals(false, row.get("value")); | ||
}); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters