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();
}
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()));
}
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));
}
Aggregations