@@ -76,7 +76,11 @@ public class JsonToProtoMessageTest {
7676 new Message [] {Int32Type .newBuilder ().setTestFieldType (Integer .MAX_VALUE ).build ()})
7777 .put (
7878 DoubleType .getDescriptor (),
79- new Message [] {DoubleType .newBuilder ().setTestFieldType (1.23 ).build ()})
79+ new Message [] {
80+ DoubleType .newBuilder ().setTestFieldType (Long .MAX_VALUE ).build (),
81+ DoubleType .newBuilder ().setTestFieldType (Integer .MAX_VALUE ).build (),
82+ DoubleType .newBuilder ().setTestFieldType (1.23 ).build ()
83+ })
8084 .put (
8185 StringType .getDescriptor (),
8286 new Message [] {StringType .newBuilder ().setTestFieldType ("test" ).build ()})
@@ -181,6 +185,26 @@ public class JsonToProtoMessageTest {
181185 .put (
182186 RepeatedDouble .getDescriptor (),
183187 new Message [] {
188+ RepeatedDouble .newBuilder ()
189+ .addTestRepeated (Long .MAX_VALUE )
190+ .addTestRepeated (Long .MIN_VALUE )
191+ .addTestRepeated (Integer .MAX_VALUE )
192+ .addTestRepeated (Integer .MIN_VALUE )
193+ .addTestRepeated (Short .MAX_VALUE )
194+ .addTestRepeated (Short .MIN_VALUE )
195+ .addTestRepeated (Byte .MAX_VALUE )
196+ .addTestRepeated (Byte .MIN_VALUE )
197+ .addTestRepeated (0 )
198+ .build (),
199+ RepeatedDouble .newBuilder ()
200+ .addTestRepeated (Integer .MAX_VALUE )
201+ .addTestRepeated (Integer .MIN_VALUE )
202+ .addTestRepeated (Short .MAX_VALUE )
203+ .addTestRepeated (Short .MIN_VALUE )
204+ .addTestRepeated (Byte .MAX_VALUE )
205+ .addTestRepeated (Byte .MIN_VALUE )
206+ .addTestRepeated (0 )
207+ .build (),
184208 RepeatedDouble .newBuilder ()
185209 .addTestRepeated (Double .MAX_VALUE )
186210 .addTestRepeated (Double .MIN_VALUE )
@@ -593,15 +617,43 @@ public void testBigNumericMismatch() throws Exception {
593617
594618 @ Test
595619 public void testDouble () throws Exception {
596- TestDouble expectedProto = TestDouble .newBuilder ().setDouble (1.2 ).setFloat (3.4f ).build ();
620+ TestDouble expectedProto =
621+ TestDouble .newBuilder ()
622+ .setDouble (1.2 )
623+ .setFloat (3.4f )
624+ .setByte (5 )
625+ .setShort (6 )
626+ .setInt (7 )
627+ .setLong (8 )
628+ .build ();
597629 JSONObject json = new JSONObject ();
598630 json .put ("double" , 1.2 );
599631 json .put ("float" , 3.4f );
632+ json .put ("byte" , new Byte ((byte ) 5 ));
633+ json .put ("short" , new Short ((short ) 6 ));
634+ json .put ("int" , 7 );
635+ json .put ("long" , 8L );
600636 DynamicMessage protoMsg =
601637 JsonToProtoMessage .convertJsonToProtoMessage (TestDouble .getDescriptor (), json );
602638 assertEquals (expectedProto , protoMsg );
603639 }
604640
641+ @ Test
642+ public void testDate () throws Exception {
643+ TableSchema tableSchema =
644+ TableSchema .newBuilder ()
645+ .addFields (TableFieldSchema .newBuilder (TEST_DATE ).setName ("test_string" ).build ())
646+ .addFields (TableFieldSchema .newBuilder (TEST_DATE ).setName ("test_long" ).build ())
647+ .build ();
648+ TestDate expectedProto = TestDate .newBuilder ().setTestString (18935 ).setTestLong (18935 ).build ();
649+ JSONObject json = new JSONObject ();
650+ json .put ("test_string" , "2021-11-04" );
651+ json .put ("test_long" , 18935L );
652+ DynamicMessage protoMsg =
653+ JsonToProtoMessage .convertJsonToProtoMessage (TestDate .getDescriptor (), tableSchema , json );
654+ assertEquals (expectedProto , protoMsg );
655+ }
656+
605657 @ Test
606658 public void testAllTypes () throws Exception {
607659 for (Map .Entry <Descriptor , String > entry : AllTypesToDebugMessageTest .entrySet ()) {
@@ -620,7 +672,9 @@ public void testAllTypes() throws Exception {
620672 e .getMessage ());
621673 }
622674 }
623- if (entry .getKey () == Int64Type .getDescriptor ()
675+ if (entry .getKey () == DoubleType .getDescriptor ()) {
676+ assertEquals (entry .getKey ().getFullName (), 3 , success );
677+ } else if (entry .getKey () == Int64Type .getDescriptor ()
624678 || entry .getKey () == BytesType .getDescriptor ()) {
625679 assertEquals (entry .getKey ().getFullName (), 2 , success );
626680 } else {
@@ -656,8 +710,9 @@ public void testAllRepeatedTypesWithLimits() throws Exception {
656710 .equals ("Error: root.test_repeated[0] could not be converted to byte[]." ));
657711 }
658712 }
659- if (entry .getKey () == RepeatedInt64 .getDescriptor ()
660- || entry .getKey () == RepeatedDouble .getDescriptor ()) {
713+ if (entry .getKey () == RepeatedDouble .getDescriptor ()) {
714+ assertEquals (entry .getKey ().getFullName (), 4 , success );
715+ } else if (entry .getKey () == RepeatedInt64 .getDescriptor ()) {
661716 assertEquals (entry .getKey ().getFullName (), 2 , success );
662717 } else {
663718 assertEquals (entry .getKey ().getFullName (), 1 , success );
0 commit comments