Search in sources :

Example 1 with MetaTest

use of org.projectnessie.cel.types.jackson.types.MetaTest in project cel-java by projectnessie.

the class JacksonScriptHostTest method simple.

@Test
void simple() throws Exception {
    ScriptHost scriptHost = ScriptHost.newBuilder().registry(JacksonRegistry.newRegistry()).build();
    Script script = scriptHost.buildScript("param.author == 'foo@bar.baz'").withDeclarations(Decls.newVar("param", Decls.newObjectType(MetaTest.class.getName()))).withTypes(MetaTest.class).build();
    MetaTest cmMatch = MetaTest.builder().author("foo@bar.baz").build();
    MetaTest cmNoMatch = MetaTest.builder().author("foo@foo.foo").build();
    assertThat(script.execute(Boolean.class, singletonMap("param", cmMatch))).isTrue();
    assertThat(script.execute(Boolean.class, singletonMap("param", cmNoMatch))).isFalse();
}
Also used : Script(org.projectnessie.cel.tools.Script) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) ScriptHost(org.projectnessie.cel.tools.ScriptHost) Test(org.junit.jupiter.api.Test) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest)

Example 2 with MetaTest

use of org.projectnessie.cel.types.jackson.types.MetaTest in project cel-java by projectnessie.

the class JacksonRegistryTest method nessieCommitMetaPart.

@Test
void nessieCommitMetaPart() {
    TypeRegistry reg = JacksonRegistry.newRegistry();
    Instant now = Instant.now();
    MetaTest cm = MetaTest.builder().commitTime(now).committer("committer@projectnessie.org").hash("beeffeed123412341234123412341234").message("Feed of beef").build();
    Val cmVal = reg.nativeToValue(cm);
    assertThat(cmVal).isInstanceOf(ObjectT.class);
    assertThat(cmVal.type().typeEnum()).isSameAs(TypeEnum.Object);
    assertThat(cmVal.type().typeName()).isEqualTo(cm.getClass().getName());
    assertThat(cmVal.type().typeEnum()).isSameAs(TypeEnum.Object);
    ObjectT cmObj = (ObjectT) cmVal;
    assertThat(cmObj.isSet(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
    assertThat(cmObj.isSet(stringOf("commitTime"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("authorTime"))).isEqualTo(False);
    assertThat(cmObj.isSet(stringOf("committer"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("author"))).isEqualTo(False);
    assertThat(cmObj.isSet(stringOf("hash"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("message"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("signedOffBy"))).isEqualTo(False);
    // just empty
    assertThat(cmObj.isSet(stringOf("properties"))).isEqualTo(True);
    assertThat(cmObj.get(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
    assertThat(cmObj.get(stringOf("commitTime"))).isEqualTo(timestampOf(now));
    assertThat(cmObj.get(stringOf("authorTime"))).isEqualTo(NullValue);
    assertThat(cmObj.get(stringOf("committer"))).isEqualTo(stringOf("committer@projectnessie.org"));
    assertThat(cmObj.get(stringOf("author"))).isEqualTo(NullValue);
    assertThat(cmObj.get(stringOf("hash"))).isEqualTo(stringOf("beeffeed123412341234123412341234"));
    assertThat(cmObj.get(stringOf("message"))).isEqualTo(stringOf("Feed of beef"));
    assertThat(cmObj.get(stringOf("signedOffBy"))).isEqualTo(NullValue);
    assertThat(cmObj.get(stringOf("properties"))).isEqualTo(newMaybeWrappedMap(reg, emptyMap()));
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) Instant(java.time.Instant) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) ObjectT(org.projectnessie.cel.common.types.ObjectT) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) Test(org.junit.jupiter.api.Test)

Example 3 with MetaTest

use of org.projectnessie.cel.types.jackson.types.MetaTest in project cel-java by projectnessie.

the class JacksonRegistryTest method nessieCommitMetaFull.

@Test
void nessieCommitMetaFull() {
    TypeRegistry reg = JacksonRegistry.newRegistry();
    Instant now = Instant.now();
    Instant nowMinus5 = now.minus(5, ChronoUnit.MINUTES);
    MetaTest cm = MetaTest.builder().commitTime(now).authorTime(nowMinus5).committer("committer@projectnessie.org").author("author@projectnessie.org").hash("beeffeed123412341234123412341234").message("Feed of beef").signedOffBy("signed-off@projectnessie.org").putProperties("prop-1", "value-1").putProperties("prop-2", "value-2").build();
    Val cmVal = reg.nativeToValue(cm);
    assertThat(cmVal).isInstanceOf(ObjectT.class);
    assertThat(cmVal.type().typeEnum()).isSameAs(TypeEnum.Object);
    assertThat(cmVal.type().typeName()).isEqualTo(cm.getClass().getName());
    assertThat(cmVal.type().typeEnum()).isSameAs(TypeEnum.Object);
    ObjectT cmObj = (ObjectT) cmVal;
    assertThat(cmObj.isSet(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
    assertThat(cmObj.isSet(stringOf("commitTime"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("authorTime"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("committer"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("author"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("hash"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("message"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("signedOffBy"))).isEqualTo(True);
    assertThat(cmObj.isSet(stringOf("properties"))).isEqualTo(True);
    Map<String, String> expectMap = new HashMap<>();
    expectMap.put("prop-1", "value-1");
    expectMap.put("prop-2", "value-2");
    assertThat(cmObj.get(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
    assertThat(cmObj.get(stringOf("commitTime"))).isEqualTo(timestampOf(now));
    assertThat(cmObj.get(stringOf("authorTime"))).isEqualTo(timestampOf(nowMinus5));
    assertThat(cmObj.get(stringOf("committer"))).isEqualTo(stringOf("committer@projectnessie.org"));
    assertThat(cmObj.get(stringOf("author"))).isEqualTo(stringOf("author@projectnessie.org"));
    assertThat(cmObj.get(stringOf("hash"))).isEqualTo(stringOf("beeffeed123412341234123412341234"));
    assertThat(cmObj.get(stringOf("message"))).isEqualTo(stringOf("Feed of beef"));
    assertThat(cmObj.get(stringOf("signedOffBy"))).isEqualTo(stringOf("signed-off@projectnessie.org"));
    assertThat(cmObj.get(stringOf("properties"))).isEqualTo(newMaybeWrappedMap(reg, expectMap));
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) HashMap(java.util.HashMap) Instant(java.time.Instant) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) ObjectT(org.projectnessie.cel.common.types.ObjectT) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) MetaTest(org.projectnessie.cel.types.jackson.types.MetaTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 MetaTest (org.projectnessie.cel.types.jackson.types.MetaTest)3 Instant (java.time.Instant)2 ObjectT (org.projectnessie.cel.common.types.ObjectT)2 TypeRegistry (org.projectnessie.cel.common.types.ref.TypeRegistry)2 Val (org.projectnessie.cel.common.types.ref.Val)2 HashMap (java.util.HashMap)1 Script (org.projectnessie.cel.tools.Script)1 ScriptHost (org.projectnessie.cel.tools.ScriptHost)1