use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.
@Test
public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
// Given
List<CallableUserAggregationFunction> compiled = compile(MultiFunction.class);
CallableUserAggregationFunction f1 = compiled.get(0);
CallableUserAggregationFunction f2 = compiled.get(1);
// When
CallableUserAggregationFunction.Aggregator f1Aggregator = f1.create(new BasicContext());
f1Aggregator.update(new Object[] { "Bonnie" });
f1Aggregator.update(new Object[] { "Clyde" });
CallableUserAggregationFunction.Aggregator f2Aggregator = f2.create(new BasicContext());
f2Aggregator.update(new Object[] { "Bonnie", 1337L });
f2Aggregator.update(new Object[] { "Bonnie", 42L });
// Then
assertThat(f1Aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
assertThat(((Map) f2Aggregator.result()).get("Bonnie"), equalTo(1337L));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldSupportFunctionDeprecation.
@Test
public void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserAggregationFunction> funcs = procedureCompiler.compileAggregationFunction(FunctionWithDeprecation.class);
// Then
verify(log).warn("Use of @UserAggregationFunction(deprecatedBy) without @Deprecated in org.neo4j.kernel.impl.proc.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserAggregationFunction func : funcs) {
String name = func.signature().name().name();
func.create(new BasicContext());
switch(name) {
case "newFunc":
assertFalse("Should not be deprecated", func.signature().deprecated().isPresent());
break;
case "oldFunc":
case "badFunc":
assertTrue("Should be deprecated", func.signature().deprecated().isPresent());
assertThat(func.signature().deprecated().get(), equalTo("newFunc"));
break;
default:
fail("Unexpected function: " + name);
}
}
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldRunAggregationFunction.
@Test
public void shouldRunAggregationFunction() throws Throwable {
// Given
CallableUserAggregationFunction func = compile(SingleAggregationFunction.class).get(0);
// When
CallableUserAggregationFunction.Aggregator aggregator = func.create(new BasicContext());
aggregator.update(new Object[] { "Harry" });
aggregator.update(new Object[] { "Bonnie" });
aggregator.update(new Object[] { "Sally" });
aggregator.update(new Object[] { "Clyde" });
// Then
assertThat(aggregator.result(), equalTo(Arrays.asList("Bonnie", "Clyde")));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserAggregationFunctionTest method shouldGiveHelpfulErrorOnNullMessageException.
@Test
public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
// Given
CallableUserAggregationFunction method = compile(FunctionThatThrowsNullMsgExceptionAtInvocation.class).get(0);
// Expect
exception.expect(ProcedureException.class);
exception.expectMessage("Failed to invoke function `org.neo4j.kernel.impl.proc.test`: " + "Caused by: java.lang.IndexOutOfBoundsException");
// When
method.create(new BasicContext()).update(new Object[] {});
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldLoadWhiteListedFunction.
@Test
public void shouldLoadWhiteListedFunction() throws Throwable {
// Given
procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), NullLog.getInstance(), new ProcedureConfig(Config.defaults().with(MapUtil.stringMap(GraphDatabaseSettings.procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople"))));
CallableUserFunction method = compile(SingleReadOnlyFunction.class).get(0);
// Expect
Object out = method.apply(new BasicContext(), new Object[0]);
assertThat(out, equalTo(Arrays.asList("Bonnie", "Clyde")));
}
Aggregations