use of org.projectnessie.cel.types.jackson.types.ClassWithEnum in project cel-java by projectnessie.
the class JacksonScriptHostTest method complexInput.
@Test
void complexInput() throws Exception {
ScriptHost scriptHost = ScriptHost.newBuilder().registry(JacksonRegistry.newRegistry()).build();
Script script = scriptHost.buildScript("param.entries[0].type == org.projectnessie.cel.types.jackson.types.ClassWithEnum.ClassEnum.VAL_2").withDeclarations(Decls.newVar("param", Decls.newObjectType(ObjectListEnum.class.getName()))).withTypes(ObjectListEnum.class).build();
ObjectListEnum val = ObjectListEnum.builder().addEntries(ObjectListEnum.Entry.builder().type(ClassEnum.VAL_2).holder(new ClassWithEnum("foo")).build()).build();
assertThat(script.execute(Boolean.class, singletonMap("param", val))).isTrue();
// same as above, but use the 'container'
script = scriptHost.buildScript("param.entries[0].type == ClassWithEnum.ClassEnum.VAL_2").withDeclarations(Decls.newVar("param", Decls.newObjectType(ObjectListEnum.class.getName()))).withContainer("org.projectnessie.cel.types.jackson.types").withTypes(ObjectListEnum.class).build();
assertThat(script.execute(Boolean.class, singletonMap("param", val))).isTrue();
// return the enum
script = scriptHost.buildScript("param.entries[0].type").withDeclarations(Decls.newVar("param", Decls.newObjectType(ObjectListEnum.class.getName()))).withContainer("org.projectnessie.cel.types.jackson.types").withTypes(ObjectListEnum.class).build();
assertThat(script.execute(Integer.class, singletonMap("param", val))).isEqualTo(ClassEnum.VAL_2.ordinal());
}
Aggregations