Search in sources :

Example 6 with TestAllTypes

use of com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.

the class ProviderTest method typeRegistryNewValue_WrapperFields.

@Test
void typeRegistryNewValue_WrapperFields() {
    TypeRegistry reg = newRegistry(TestAllTypes.getDefaultInstance());
    Val exp = reg.newValue("google.api.expr.test.v1.proto3.TestAllTypes", mapOf("single_int32_wrapper", intOf(123)));
    assertThat(exp).matches(v -> !Err.isError(v));
    TestAllTypes ce = exp.convertToNative(TestAllTypes.class);
    assertThat(ce).extracting(TestAllTypes::getSingleInt32Wrapper).extracting(Int32Value::getValue).isEqualTo(123);
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) TestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes) TypeRegistry(org.projectnessie.cel.common.types.ref.TypeRegistry) ProtoTypeRegistry(org.projectnessie.cel.common.types.pb.ProtoTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 7 with TestAllTypes

use of com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes in project cel-java by projectnessie.

the class FieldDescriptionTest method getFrom.

@ParameterizedTest
@MethodSource("getFromTestCases")
void getFrom(GetFromTestCase tc) {
    Db pbdb = newDb();
    TestAllTypes msg = TestAllTypes.newBuilder().setSingleUint64(12).setSingleDuration(Duration.newBuilder().setSeconds(1234)).setSingleTimestamp(Timestamp.newBuilder().setSeconds(12345).setNanos(0)).setSingleBoolWrapper(BoolValue.of(false)).setSingleInt32Wrapper(Int32Value.of(42)).setStandaloneEnum(NestedEnum.BAR).setSingleNestedMessage(NestedMessage.newBuilder().setBb(123)).setSingleValue(Value.newBuilder().setStringValue("hello world")).setSingleStruct(Struct.newBuilder().putFields("null", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build())).build();
    String msgName = msg.getDescriptorForType().getFullName();
    pbdb.registerMessage(msg);
    PbTypeDescription td = pbdb.describeType(msgName);
    assertThat(td).isNotNull();
    FieldDescription f = td.fieldByName(tc.field);
    assertThat(f).isNotNull();
    Object got = f.getFrom(pbdb, msg);
    assertThat(got).isEqualTo(tc.want);
}
Also used : TestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes) NestedTestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes) Db.newDb(org.projectnessie.cel.common.types.pb.Db.newDb) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 TestAllTypes (com.google.api.expr.test.v1.proto3.TestAllTypesProto.TestAllTypes)5 Test (org.junit.jupiter.api.Test)5 NestedTestAllTypes (com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes)4 Db.newDb (org.projectnessie.cel.common.types.pb.Db.newDb)4 Type (com.google.api.expr.v1alpha1.Type)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 TypeRegistry (org.projectnessie.cel.common.types.ref.TypeRegistry)3 ByteString (com.google.protobuf.ByteString)2 Val (org.projectnessie.cel.common.types.ref.Val)2 Activation.emptyActivation (org.projectnessie.cel.interpreter.Activation.emptyActivation)2 Activation.newActivation (org.projectnessie.cel.interpreter.Activation.newActivation)2 Activation.newPartialActivation (org.projectnessie.cel.interpreter.Activation.newPartialActivation)2 AttributeFactory.newAttributeFactory (org.projectnessie.cel.interpreter.AttributeFactory.newAttributeFactory)2 AttributePattern.newPartialAttributeFactory (org.projectnessie.cel.interpreter.AttributePattern.newPartialAttributeFactory)2 TestAllTypes (com.google.api.expr.test.v1.proto2.TestAllTypesProto.TestAllTypes)1 CheckResult (org.projectnessie.cel.checker.Checker.CheckResult)1 CheckerEnv (org.projectnessie.cel.checker.CheckerEnv)1 CheckerEnv.newStandardCheckerEnv (org.projectnessie.cel.checker.CheckerEnv.newStandardCheckerEnv)1 Source (org.projectnessie.cel.common.Source)1