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