Search in sources :

Example 1 with TestStruct

use of com.google.protobuf.util.JsonTestProto.TestStruct in project curiostack by curioswitch.

the class MessageMarshallerTest method struct.

@Test
public void struct() throws Exception {
    // Build a struct with all possible values.
    TestStruct.Builder builder = TestStruct.newBuilder();
    Struct.Builder structBuilder = builder.getStructValueBuilder();
    structBuilder.putFields("null_value", Value.newBuilder().setNullValueValue(0).build());
    structBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1.25).build());
    structBuilder.putFields("string_value", Value.newBuilder().setStringValue("hello").build());
    Struct.Builder subStructBuilder = Struct.newBuilder();
    subStructBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1234).build());
    structBuilder.putFields("struct_value", Value.newBuilder().setStructValue(subStructBuilder.build()).build());
    ListValue.Builder listBuilder = ListValue.newBuilder();
    listBuilder.addValues(Value.newBuilder().setNumberValue(1.125).build());
    listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
    structBuilder.putFields("list_value", Value.newBuilder().setListValue(listBuilder.build()).build());
    TestStruct message = builder.build();
    assertMatchesUpstream(message);
    builder = TestStruct.newBuilder();
    builder.setValue(Value.newBuilder().setNullValueValue(0).build());
    message = builder.build();
    assertMatchesUpstream(message);
    builder = TestStruct.newBuilder();
    listBuilder = builder.getListValueBuilder();
    listBuilder.addValues(Value.newBuilder().setNumberValue(31831.125).build());
    listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
    message = builder.build();
    assertMatchesUpstream(message);
}
Also used : ListValue(com.google.protobuf.ListValue) TestStruct(com.google.protobuf.util.JsonTestProto.TestStruct) Struct(com.google.protobuf.Struct) TestStruct(com.google.protobuf.util.JsonTestProto.TestStruct) Test(org.junit.Test)

Aggregations

ListValue (com.google.protobuf.ListValue)1 Struct (com.google.protobuf.Struct)1 TestStruct (com.google.protobuf.util.JsonTestProto.TestStruct)1 Test (org.junit.Test)1