Search in sources :

Example 1 with NestedTestAllTypes

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

the class FieldDescriptionTest method fieldDescription.

@Test
void fieldDescription() {
    Db pbdb = newDb();
    NestedTestAllTypes msg = NestedTestAllTypes.getDefaultInstance();
    String msgName = msg.getDescriptorForType().getFullName();
    pbdb.registerMessage(msg);
    PbTypeDescription td = pbdb.describeType(msgName);
    assertThat(td).isNotNull();
    FieldDescription fd = td.fieldByName("payload");
    assertThat(fd).isNotNull();
    assertThat(fd).extracting(FieldDescription::name).isEqualTo("payload");
    assertThat(fd).extracting(FieldDescription::isOneof).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isMap).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isMessage).isEqualTo(true);
    assertThat(fd).extracting(FieldDescription::isEnum).isEqualTo(false);
    assertThat(fd).extracting(FieldDescription::isList).isEqualTo(false);
    // Access the field by its Go struct name and check to see that it's index
    // matches the one determined by the TypeDescription utils.
    Type got = fd.checkedType();
    Type wanted = Type.newBuilder().setMessageType("google.api.expr.test.v1.proto3.TestAllTypes").build();
    assertThat(got).isEqualTo(wanted);
}
Also used : Type(com.google.api.expr.v1alpha1.Type) Db.newDb(org.projectnessie.cel.common.types.pb.Db.newDb) NestedTestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with NestedTestAllTypes

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

the class PbTypeDescriptionTest method fieldMap.

@Test
void fieldMap() {
    Db pbdb = newDb();
    NestedTestAllTypes msg = NestedTestAllTypes.getDefaultInstance();
    pbdb.registerMessage(msg);
    PbTypeDescription td = pbdb.describeType(msg.getDescriptorForType().getFullName());
    assertThat(td).isNotNull();
    assertThat(td.fieldMap()).hasSize(2);
}
Also used : Db.newDb(org.projectnessie.cel.common.types.pb.Db.newDb) NestedTestAllTypes(com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NestedTestAllTypes (com.google.api.expr.test.v1.proto3.TestAllTypesProto.NestedTestAllTypes)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Db.newDb (org.projectnessie.cel.common.types.pb.Db.newDb)2 Type (com.google.api.expr.v1alpha1.Type)1