@@ -504,4 +504,76 @@ public void testOperationSubClassMethodsAreBuilderStyle() {
504504
505505 BuilderStyleTest .assertClassesAreBuilderStyle (classes );
506506 }
507+
508+ /**
509+ * Test the client Get Operations' JSON encoding to ensure that produced JSON is parseable and
510+ * that the details are present and not corrupted.
511+ * @throws IOException if the JSON conversion fails
512+ */
513+ @ Test
514+ public void testGetOperationToJSON () throws IOException {
515+ // produce a Scan Operation
516+ Get get = new Get (ROW );
517+ get .addColumn (FAMILY , QUALIFIER );
518+ get .readVersions (5 );
519+ get .setMaxResultsPerColumnFamily (3 );
520+ get .setRowOffsetPerColumnFamily (8 );
521+ get .setCacheBlocks (true );
522+ get .setMaxResultsPerColumnFamily (5 );
523+ get .setRowOffsetPerColumnFamily (9 );
524+ get .setCheckExistenceOnly (true );
525+ get .setTimeRange (1000 , 2000 );
526+ get .setFilter (SCV_FILTER );
527+ get .setReplicaId (1 );
528+ get .setConsistency (Consistency .STRONG );
529+ get .setLoadColumnFamiliesOnDemand (true );
530+ get .setColumnFamilyTimeRange (FAMILY , 2000 , 3000 );
531+ get .setPriority (10 );
532+
533+ // get its JSON representation, and parse it
534+ String json = get .toJSON ();
535+ Type typeOfHashMap = new TypeToken <Map <String , Object >>() {
536+ }.getType ();
537+ Gson gson = new GsonBuilder ().setLongSerializationPolicy (LongSerializationPolicy .STRING )
538+ .setObjectToNumberStrategy (ToNumberPolicy .LONG_OR_DOUBLE ).create ();
539+ Map <String , Object > parsedJSON = gson .fromJson (json , typeOfHashMap );
540+ // check for the row
541+ assertEquals ("row incorrect in Get.toJSON()" , Bytes .toStringBinary (ROW ), parsedJSON .get ("row" ));
542+ // check for the family and the qualifier.
543+ List familyInfo = (List ) ((Map ) parsedJSON .get ("families" )).get (Bytes .toStringBinary (FAMILY ));
544+ assertNotNull ("Family absent in Get.toJSON()" , familyInfo );
545+ assertEquals ("Qualifier absent in Get.toJSON()" , 1 , familyInfo .size ());
546+ assertEquals ("Qualifier incorrect in Get.toJSON()" , Bytes .toStringBinary (QUALIFIER ),
547+ familyInfo .get (0 ));
548+
549+ assertEquals ("maxVersions incorrect in Get.toJSON()" , 5L , parsedJSON .get ("maxVersions" ));
550+
551+ assertEquals ("storeLimit incorrect in Get.toJSON()" , 5L , parsedJSON .get ("storeLimit" ));
552+ assertEquals ("storeOffset incorrect in Get.toJSON()" , 9L , parsedJSON .get ("storeOffset" ));
553+
554+ assertEquals ("cacheBlocks incorrect in Get.toJSON()" , true , parsedJSON .get ("cacheBlocks" ));
555+
556+ List trList = (List ) parsedJSON .get ("timeRange" );
557+ assertEquals ("timeRange incorrect in Get.toJSON()" , 2 , trList .size ());
558+ assertEquals ("timeRange incorrect in Get.toJSON()" , "1000" , trList .get (0 ));
559+ assertEquals ("timeRange incorrect in Get.toJSON()" , "2000" , trList .get (1 ));
560+
561+ Map colFamTimeRange = (Map ) parsedJSON .get ("colFamTimeRangeMap" );
562+ assertEquals ("colFamTimeRangeMap incorrect in Get.toJSON()" , 1L , colFamTimeRange .size ());
563+ List testFamily = (List ) colFamTimeRange .get ("testFamily" );
564+ assertEquals ("colFamTimeRangeMap incorrect in Get.toJSON()" , 2L , testFamily .size ());
565+ assertEquals ("colFamTimeRangeMap incorrect in Get.toJSON()" , "2000" , testFamily .get (0 ));
566+ assertEquals ("colFamTimeRangeMap incorrect in Get.toJSON()" , "3000" , testFamily .get (1 ));
567+
568+ assertEquals ("targetReplicaId incorrect in Get.toJSON()" , 1L ,
569+ parsedJSON .get ("targetReplicaId" ));
570+ assertEquals ("consistency incorrect in Get.toJSON()" , "STRONG" , parsedJSON .get ("consistency" ));
571+ assertEquals ("loadColumnFamiliesOnDemand incorrect in Get.toJSON()" , true ,
572+ parsedJSON .get ("loadColumnFamiliesOnDemand" ));
573+
574+ assertEquals ("priority incorrect in Get.toJSON()" , 10L , parsedJSON .get ("priority" ));
575+ assertEquals ("checkExistenceOnly incorrect in Get.toJSON()" , true ,
576+ parsedJSON .get ("checkExistenceOnly" ));
577+
578+ }
507579}
0 commit comments