use of com.google.protobuf.util.JsonTestProto.TestAllTypes in project curiostack by curioswitch.
the class MessageMarshallerTest method parserAcceptsStringForNumericField.
@Test
public void parserAcceptsStringForNumericField() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
mergeFromJson("{\n" + " \"optionalInt32\": \"1234\",\n" + " \"optionalUint32\": \"5678\",\n" + " \"optionalSint32\": \"9012\",\n" + " \"optionalFixed32\": \"3456\",\n" + " \"optionalSfixed32\": \"7890\",\n" + " \"optionalFloat\": \"1.5\",\n" + " \"optionalDouble\": \"1.25\",\n" + " \"optionalBool\": \"true\"\n" + "}", builder);
TestAllTypes message = builder.build();
assertEquals(1234, message.getOptionalInt32());
assertEquals(5678, message.getOptionalUint32());
assertEquals(9012, message.getOptionalSint32());
assertEquals(3456, message.getOptionalFixed32());
assertEquals(7890, message.getOptionalSfixed32());
assertEquals(1.5f, message.getOptionalFloat(), 0.000001);
assertEquals(1.25, message.getOptionalDouble(), 0.000001);
assertEquals(true, message.getOptionalBool());
}
use of com.google.protobuf.util.JsonTestProto.TestAllTypes in project curiostack by curioswitch.
the class MessageMarshallerTest method defaultDoesNotHtmlExcape.
@Test
public void defaultDoesNotHtmlExcape() throws Exception {
TestAllTypes message = TestAllTypes.newBuilder().setOptionalString("=").build();
assertMatchesUpstream(message);
}
use of com.google.protobuf.util.JsonTestProto.TestAllTypes in project curiostack by curioswitch.
the class MessageMarshallerTest method omittingInsignificantWhitespace.
@Test
public void omittingInsignificantWhitespace() throws Exception {
TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
assertMatchesUpstream(message, false, false, true);
TestAllTypes message1 = TestAllTypes.getDefaultInstance();
assertMatchesUpstream(message1, false, false, true);
TestAllTypes message2 = JsonTestUtil.testAllTypesAllFields();
assertMatchesUpstream(message2, false, false, true);
}
use of com.google.protobuf.util.JsonTestProto.TestAllTypes in project curiostack by curioswitch.
the class MessageMarshallerTest method parserAcceptsNull.
@Test
public void parserAcceptsNull() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
mergeFromJson("{\n" + " \"optionalInt32\": null,\n" + " \"optionalInt64\": null,\n" + " \"optionalUint32\": null,\n" + " \"optionalUint64\": null,\n" + " \"optionalSint32\": null,\n" + " \"optionalSint64\": null,\n" + " \"optionalFixed32\": null,\n" + " \"optionalFixed64\": null,\n" + " \"optionalSfixed32\": null,\n" + " \"optionalSfixed64\": null,\n" + " \"optionalFloat\": null,\n" + " \"optionalDouble\": null,\n" + " \"optionalBool\": null,\n" + " \"optionalString\": null,\n" + " \"optionalBytes\": null,\n" + " \"optionalNestedMessage\": null,\n" + " \"optionalNestedEnum\": null,\n" + " \"repeatedInt32\": null,\n" + " \"repeatedInt64\": null,\n" + " \"repeatedUint32\": null,\n" + " \"repeatedUint64\": null,\n" + " \"repeatedSint32\": null,\n" + " \"repeatedSint64\": null,\n" + " \"repeatedFixed32\": null,\n" + " \"repeatedFixed64\": null,\n" + " \"repeatedSfixed32\": null,\n" + " \"repeatedSfixed64\": null,\n" + " \"repeatedFloat\": null,\n" + " \"repeatedDouble\": null,\n" + " \"repeatedBool\": null,\n" + " \"repeatedString\": null,\n" + " \"repeatedBytes\": null,\n" + " \"repeatedNestedMessage\": null,\n" + " \"repeatedNestedEnum\": null\n" + "}", builder);
TestAllTypes message = builder.build();
assertEquals(TestAllTypes.getDefaultInstance(), message);
// Repeated field elements cannot be null.
TestAllTypes.Builder builder2 = TestAllTypes.newBuilder();
assertThatThrownBy(() -> mergeFromJson("{\n" + " \"repeatedInt32\": [null, null],\n" + "}", builder2)).isInstanceOf(IOException.class);
TestAllTypes.Builder builder3 = TestAllTypes.newBuilder();
assertThatThrownBy(() -> mergeFromJson("{\n" + " \"repeatedNestedMessage\": [null, null],\n" + "}", builder3)).isInstanceOf(IOException.class);
}
use of com.google.protobuf.util.JsonTestProto.TestAllTypes in project curiostack by curioswitch.
the class MessageMarshallerTest method unknownEnumValue.
@Test
public void unknownEnumValue() throws Exception {
TestAllTypes message = TestAllTypes.newBuilder().setOptionalNestedEnumValue(12345).addRepeatedNestedEnumValue(12345).addRepeatedNestedEnumValue(0).build();
assertMatchesUpstream(message);
// FIXME: https://github.com/google/protobuf/issues/2936
// We use the singular put methods in generated code to avoid unnecessary creation of
// intermediate maps. However, the singular put methods strangely do not allow unknown enum
// values. As unknown enum values are quite rare in practice, and only maps are affected, we'll
// skip support for now and revisit if this is an issue for people and upstream does not change
// their API.
/*
TestMap.Builder mapBuilder = TestMap.newBuilder();
mapBuilder.putInt32ToEnumMapValue(1, 0);
Map<Integer, Integer> mapWithInvalidValues = new HashMap<Integer, Integer>();
mapWithInvalidValues.put(2, 12345);
mapBuilder.putAllInt32ToEnumMapValue(mapWithInvalidValues);
TestMap mapMessage = mapBuilder.buildAndAdd();
assertMatchesUpstream(mapMessage);
*/
}
Aggregations