55import static org .junit .Assert .assertTrue ;
66
77import java .util .Calendar ;
8+ import java .util .HashMap ;
9+ import java .util .Map ;
810
911import org .junit .After ;
1012import org .junit .AfterClass ;
1618import com .marklogic .client .DatabaseClientFactory ;
1719import com .marklogic .client .DatabaseClientFactory .Authentication ;
1820import com .marklogic .client .document .DocumentManager .Metadata ;
21+ import com .marklogic .client .document .DocumentPage ;
1922import com .marklogic .client .document .DocumentRecord ;
2023import com .marklogic .client .document .DocumentWriteSet ;
2124import com .marklogic .client .document .JSONDocumentManager ;
2629import com .marklogic .client .io .DocumentMetadataHandle .DocumentProperties ;
2730import com .marklogic .client .io .Format ;
2831import com .marklogic .client .io .JacksonDatabindHandle ;
32+ import com .marklogic .client .io .JacksonHandle ;
2933import com .marklogic .client .io .marker .ContentHandleFactory ;
3034
3135/*
3539
3640public class TestBulkReadWriteWithJacksonDataBind extends
3741 BasicJavaClientREST {
38- private static final String DIRECTORY = "/bulkread/ " ;
42+ private static final String DIRECTORY = "/" ;
3943 private static String dbName = "TestBulkJacksonDataBindDB" ;
4044 private static String [] fNames = { "TestBulkJacksonDataBindDB-1" };
4145 private static String restServerName = "REST-Java-Client-API-Server" ;
4246 private static int restPort = 8011 ;
4347 private DatabaseClient client ;
48+
49+ public static class ContentCheck
50+ {
51+ String content ;
52+
53+ public String getContent () {
54+ return content ;
55+ }
56+
57+ public void setContent (String content ) {
58+ this .content = content ;
59+ }
60+ }
4461
4562 @ BeforeClass
4663 public static void setUp () throws Exception {
@@ -261,7 +278,7 @@ public void testWriteMultipleJSONDocsFromStrings() throws Exception {
261278 docMgr .readMetadata (docId [2 ], mhRead );
262279 validateMetadata (mhRead );
263280 }
264-
281+
265282 /*
266283 * Purpose: To test newFactory method with custom Pojo instances.
267284 */
@@ -351,21 +368,145 @@ public void testJacksonDataBindHandleFromFactory() throws Exception {
351368 docMgr .readMetadata (docId [2 ], mhRead );
352369 validateMetadata (mhRead );
353370 }
371+
372+ /*
373+ * Purpose: To test Git Issue # 89.
374+ * Issue Description: If you read more than 100 JSON objects, the Client API stops reading them.
375+ *
376+ * Use one Jackson Handles instance.
377+ */
378+ @ Test
379+ public void testSingleJacksonHandlerHundredJsonDocs () throws Exception {
380+
381+ JacksonHandle jh = new JacksonHandle ();
382+ jh .withFormat (Format .JSON );
383+ JSONDocumentManager docMgr = client .newJSONDocumentManager ();
384+ docMgr .setMetadataCategories (Metadata .ALL );
385+ docMgr .setNonDocumentFormat (Format .JSON );
386+ DocumentWriteSet writeset = docMgr .newWriteSet ();
387+ // put meta-data
388+ DocumentMetadataHandle mh = setMetadata ();
389+ writeset .addDefault (mh );
390+
391+ JacksonDatabindHandle <String > handle1 = new JacksonDatabindHandle <String >(String .class );
392+
393+ Map <String , String > jsonMap = new HashMap <String , String >();
394+ String [] uris = new String [150 ];
395+
396+ String dir = new String ("/" );
397+ String mapDocId = null ;
398+ StringBuffer mapDocContent = new StringBuffer ();
399+ for (int i =0 ;i <102 ;i ++)
400+ {
401+ mapDocId = dir + Integer .toString (i );
402+ mapDocContent .append ("{\" content\" :\" " );
403+ mapDocContent .append (Integer .toString (i ));
404+ mapDocContent .append ("\" }" );
405+
406+ jsonMap .put (mapDocId , mapDocContent .toString ());
407+
408+ handle1 .set (mapDocContent .toString ());
409+ writeset .add (mapDocId , handle1 );
410+
411+ uris [i ] = mapDocId ;
412+
413+ mapDocContent .setLength (0 );
414+ mapDocId = null ;
415+ docMgr .write (writeset );
416+ writeset .clear ();
417+ }
418+
419+ int count =0 ;
420+
421+ DocumentPage page = docMgr .read (uris );
422+ DocumentRecord rec ;
423+
424+ while (page .hasNext ()){
425+ rec = page .next ();
426+
427+ assertNotNull ("DocumentRecord should never be null" , rec );
428+ assertNotNull ("Document uri should never be null" , rec .getUri ());
429+ assertTrue ("Document uri should start with " + DIRECTORY , rec .getUri ().startsWith (DIRECTORY ));
430+
431+ rec .getContent (jh );
432+ //Verify the contents: comparing Map with JacksonHandle's.
433+ assertEquals ("Comparing the content :" ,jsonMap .get (rec .getUri ()),jh .get ().toString ());
434+ count ++;
435+ }
436+ assertEquals ("document count" , 102 ,count );
437+
438+ }
439+ /*
440+ * Purpose: To test Git Issue # 89.
441+ * Issue Description: If you read more than 100 JSON objects, the Client API stops reading them.
442+ *
443+ * Use multiple Jackson Handle instances.
444+ */
445+ @ Test
446+ public void testMultipleJacksonHandleHundredJsonDocs1 () throws Exception {
447+
448+ JSONDocumentManager docMgr = client .newJSONDocumentManager ();
449+ docMgr .setMetadataCategories (Metadata .ALL );
450+ docMgr .setNonDocumentFormat (Format .JSON );
451+ DocumentWriteSet writeset = docMgr .newWriteSet ();
452+ // put meta-data
453+ DocumentMetadataHandle mh = setMetadata ();
454+ writeset .addDefault (mh );
455+
456+ JacksonDatabindHandle <String > handle1 = new JacksonDatabindHandle <String >(String .class );
457+
458+ Map <String , String > jsonMap = new HashMap <String , String >();
459+ String [] uris = new String [150 ];
460+
461+ String dir = new String ("/" );
462+ String mapDocId = null ;
463+ StringBuffer mapDocContent = new StringBuffer ();
464+ for (int i =0 ;i <102 ;i ++)
465+ {
466+ mapDocId = dir + Integer .toString (i );
467+ mapDocContent .append ("{\" content\" :\" " );
468+ mapDocContent .append (Integer .toString (i ));
469+ mapDocContent .append ("\" }" );
470+
471+ jsonMap .put (mapDocId , mapDocContent .toString ());
472+
473+ handle1 .set (mapDocContent .toString ());
474+ writeset .add (mapDocId , handle1 );
475+
476+ uris [i ] = mapDocId ;
477+
478+ mapDocContent .setLength (0 );
479+ mapDocId = null ;
480+ docMgr .write (writeset );
481+ writeset .clear ();
482+ }
483+
484+ int count =0 ;
485+
486+ DocumentPage page = docMgr .read (uris );
487+ DocumentRecord rec ;
488+
489+ JacksonHandle jh = new JacksonHandle ();
490+ jh .withFormat (Format .JSON );
491+ while (page .hasNext ()){
492+ rec = page .next ();
493+
494+ assertNotNull ("DocumentRecord should never be null" , rec );
495+ assertNotNull ("Document uri should never be null" , rec .getUri ());
496+ assertTrue ("Document uri should start with " + DIRECTORY , rec .getUri ().startsWith (DIRECTORY ));
497+
498+ rec .getContent (jh );
499+ //Verify the contents: comparing Map with JacksonHandle's.
500+ assertEquals ("Comparing the content :" ,jsonMap .get (rec .getUri ()),jh .get ().toString ());
501+ count ++;
502+ }
503+ assertEquals ("document count" , 102 ,count );
504+
505+ }
354506
355507 @ AfterClass
356508 public static void tearDown () throws Exception {
357509 System .out .println ("In tear down" );
358510 tearDownJavaRESTServer (dbName , fNames , restServerName );
359511 }
360-
361- public void validateRecord (DocumentRecord record , Format type ) {
362-
363- assertNotNull ("DocumentRecord should never be null" , record );
364- assertNotNull ("Document uri should never be null" , record .getUri ());
365- assertTrue ("Document uri should start with " + DIRECTORY , record
366- .getUri ().startsWith (DIRECTORY ));
367- assertEquals ("All records are expected to be in same format" , type ,
368- record .getFormat ());
369-
370- }
371512}
0 commit comments