@Test public void shouldCompileFunction() throws Throwable { // When List<CallableUserFunction> function = compile( SingleReadOnlyFunction.class ); // Then assertEquals( 1, function.size() ); assertThat( function.get( 0 ).signature(), Matchers.equalTo( functionSignature( "org", "neo4j", "kernel", "impl", "proc", "listCoolPeople" ) .out( Neo4jTypes.NTList( Neo4jTypes.NTAny ) ) .build() ) ); }
@Test public void shouldCompileAggregationFunction() throws Throwable { // When List<CallableUserAggregationFunction> function = compile( SingleAggregationFunction.class ); // Then assertEquals( 1, function.size() ); assertThat( function.get( 0 ).signature(), Matchers.equalTo( functionSignature( "org", "neo4j", "kernel", "impl", "proc", "collectCool" ) .in( "name", Neo4jTypes.NTString ) .out( Neo4jTypes.NTList( Neo4jTypes.NTAny ) ) .build() ) ); }
@Test public void shouldGetRegisteredAggregationFunctions() throws Throwable { // When procs.register( function( functionSignature( "org", "myfunc1" ).out(Neo4jTypes.NTAny).build() ) ); procs.register( function( functionSignature( "org", "myfunc2" ).out(Neo4jTypes.NTAny).build() ) ); procs.register( aggregationFunction( functionSignature( "org", "myaggrfunc1" ).out(Neo4jTypes.NTAny).build() ) ); // Then List<UserFunctionSignature> signatures = Iterables.asList( procs.getAllFunctions() ); assertThat( signatures, containsInAnyOrder( functionSignature( "org", "myfunc1" ).out(Neo4jTypes.NTAny).build(), functionSignature( "org", "myfunc2" ).out(Neo4jTypes.NTAny).build(), functionSignature( "org", "myaggrfunc1" ).out(Neo4jTypes.NTAny).build() ) ); }
public static QualifiedName procedureName( String... namespaceAndName ) { return functionSignature( namespaceAndName ).build().name(); } }
@Test public void shouldGetAllRegisteredFunctions() throws Throwable { // When procs.register( function( functionSignature( "org", "myproc1" ).out(Neo4jTypes.NTAny).build() ) ); procs.register( function( functionSignature( "org", "myproc2" ).out(Neo4jTypes.NTAny).build() ) ); procs.register( function( functionSignature( "org", "myproc3" ).out(Neo4jTypes.NTAny).build() ) ); // Then List<UserFunctionSignature> signatures = Iterables.asList( procs.getAllFunctions() ); assertThat( signatures, containsInAnyOrder( functionSignature( "org", "myproc1" ).out(Neo4jTypes.NTAny).build(), functionSignature( "org", "myproc2" ).out(Neo4jTypes.NTAny).build(), functionSignature( "org", "myproc3" ).out(Neo4jTypes.NTAny).build() ) ); }
@Test public void toStringShouldMatchCypherSyntax() { // When String toStr = functionSignature( "org", "myProcedure" ) .in( "in", Neo4jTypes.NTList( Neo4jTypes.NTString ) ) .out( Neo4jTypes.NTNumber ) .build() .toString(); // Then assertEquals( "org.myProcedure(in :: LIST? OF STRING?) :: (NUMBER?)", toStr ); } }
public static QualifiedName procedureName( String... namespaceAndName ) { return functionSignature( namespaceAndName ).build().name(); } }