use of org.projectnessie.cel.common.types.ref.TypeRegistry 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.common.types.ref.TypeRegistry 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));
}
use of org.projectnessie.cel.common.types.ref.TypeRegistry in project cel-java by projectnessie.
the class JacksonRegistryTest method nessieBranch.
@Test
void nessieBranch() {
TypeRegistry reg = JacksonRegistry.newRegistry();
RefVariantB refVariantB = RefVariantB.of("main", "cafebabe123412341234123412341234");
Val branchVal = reg.nativeToValue(refVariantB);
assertThat(branchVal).isInstanceOf(ObjectT.class);
assertThat(branchVal.type().typeEnum()).isSameAs(TypeEnum.Object);
assertThat(branchVal.type().typeName()).isEqualTo(refVariantB.getClass().getName());
ObjectT branchObj = (ObjectT) branchVal;
assertThat(branchObj.isSet(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
assertThat(branchObj.isSet(stringOf("name"))).isEqualTo(True);
assertThat(branchObj.isSet(stringOf("hash"))).isEqualTo(True);
assertThat(branchObj.get(stringOf("foo"))).isInstanceOf(Err.class).asString().isEqualTo("no such field 'foo'");
assertThat(branchObj.get(stringOf("name"))).isEqualTo(stringOf("main"));
assertThat(branchObj.get(stringOf("hash"))).isEqualTo(stringOf("cafebabe123412341234123412341234"));
}
use of org.projectnessie.cel.common.types.ref.TypeRegistry in project cel-java by projectnessie.
the class PbObjectTest method protoObjectConvertToType.
@Test
void protoObjectConvertToType() {
TypeRegistry reg = newRegistry(Expr.getDefaultInstance());
ParsedExpr msg = ParsedExpr.newBuilder().setSourceInfo(SourceInfo.newBuilder().addAllLineOffsets(Arrays.asList(1, 2, 3)).build()).build();
Val obj = reg.nativeToValue(msg);
assertThat(obj).isInstanceOf(ObjectT.class);
ObjectT objVal = (ObjectT) obj;
Type tv = objVal.type();
assertThat(objVal.convertToType(TypeType).equal(tv)).isSameAs(True);
assertThat(objVal.convertToType(objVal.type())).isSameAs(objVal);
}
use of org.projectnessie.cel.common.types.ref.TypeRegistry in project cel-java by projectnessie.
the class PbObjectTest method protoObjectConvertToNative.
@Test
void protoObjectConvertToNative() throws Exception {
TypeRegistry reg = newRegistry(Expr.getDefaultInstance());
ParsedExpr msg = ParsedExpr.newBuilder().setSourceInfo(SourceInfo.newBuilder().addAllLineOffsets(Arrays.asList(1, 2, 3)).build()).build();
Val objVal = reg.nativeToValue(msg);
// Proto Message
ParsedExpr val = objVal.convertToNative(ParsedExpr.class);
assertThat(val).isEqualTo(msg);
// Dynamic protobuf
Val dynPB = reg.newValue(msg.getDescriptorForType().getFullName(), Collections.singletonMap("source_info", reg.nativeToValue(msg.getSourceInfo())));
Val dynVal = reg.nativeToValue(dynPB);
val = dynVal.convertToNative(msg.getClass());
assertThat(val).isEqualTo(msg);
// google.protobuf.Any
Any anyVal = objVal.convertToNative(Any.class);
Message unpackedAny = anyVal.unpack(ParsedExpr.class);
assertThat(unpackedAny).isEqualTo(objVal.value());
}
Aggregations