@@ -277,6 +277,8 @@ public void testF_DefaultMetadata() {
277277 "{\" number\" : 4}" ).withFormat (Format .JSON );
278278 StringHandle doc5 = new StringHandle (
279279 "{\" number\" : 5}" ).withFormat (Format .JSON );
280+ StringHandle doc6 = new StringHandle (
281+ "{\" number\" : 6}" ).withFormat (Format .JSON );
280282
281283 // Synthesize input metadata
282284 DocumentMetadataHandle defaultMetadata1 =
@@ -285,6 +287,7 @@ public void testF_DefaultMetadata() {
285287 new DocumentMetadataHandle ().withQuality (2 );
286288 DocumentMetadataHandle docSpecificMetadata =
287289 new DocumentMetadataHandle ().withCollections ("myCollection" );
290+ DocumentMetadataHandle blankDefaultMetadata = new DocumentMetadataHandle ();
288291
289292 // Create and build up the batch
290293 JSONDocumentManager jdm = Common .client .newJSONDocumentManager ();
@@ -303,6 +306,10 @@ public void testF_DefaultMetadata() {
303306 batch .addDefault (defaultMetadata2 );
304307 batch .add ("doc5.json" , doc5 ); // batch default
305308
309+ // replace default metadata with blank metadata (back to system defaults)
310+ batch .addDefault (blankDefaultMetadata );
311+ batch .add ("doc6.json" , doc6 ); // system default metadata
312+
306313 // Execute the write operation
307314 jdm .write (batch );
308315
@@ -323,29 +330,41 @@ public void testF_DefaultMetadata() {
323330 assertEquals ("Doc3 should be in the collection \" myCollection\" , from the document-specific metadata." ,
324331 "myCollection" , collections .iterator ().next ());
325332
326- //
327- assertEquals ("Doc4 should also use the 1st batch default metadata, with quality 1" , defaultMetadata1 .getQuality (),
328- jdm .readMetadata ("doc4.json" , new DocumentMetadataHandle ()).getQuality ());
329- assertEquals ("Doc5 should use the 2nd batch default metadata, with quality 2" , defaultMetadata2 .getQuality (),
330- jdm .readMetadata ("doc5.json" , new DocumentMetadataHandle ()).getQuality ());
331-
332- // let's check getting just quality metadata with content in bulk read
333+ // let's check getting content with just quality in the metadata
333334 jdm .setMetadataCategories (Metadata .QUALITY );
334- DocumentPage documents = jdm .read ("doc1 .json" , "doc2 .json" , "doc3 .json" );
335+ DocumentPage documents = jdm .read ("doc4 .json" , "doc5 .json" , "doc6 .json" );
335336
336337 for ( DocumentRecord doc : documents ) {
337338 DocumentMetadataHandle metadata = doc .getMetadata (new DocumentMetadataHandle ());
338339 StringHandle content = doc .getContent (new StringHandle ());
339- if ( "doc1.json" .equals (doc .getUri ()) ) {
340- assertEquals ("Doc 1 should have the system default quality of 0" , 0 , metadata .getQuality ());
341- assertTrue ("Doc 1 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?1\\ }" ));
342- } else if ( "doc2.json" .equals (doc .getUri ()) ) {
343- assertEquals ("Doc 2 should use the first batch default metadata, with quality 1" , 1 , metadata .getQuality ());
344- assertTrue ("Doc 2 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?2\\ }" ));
345- } else if ( "doc3.json" .equals (doc .getUri ()) ) {
346- assertEquals ("Doc 3 should have the system default document quality (0) because quality " +
347- "was not included in the document-specific metadata." , 0 , metadata .getQuality ());
348- assertTrue ("Doc 3 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?3\\ }" ));
340+ if ( "doc4.json" .equals (doc .getUri ()) ) {
341+ assertEquals ("Doc4 should also use the 1st batch default metadata, with quality 1" , 1 ,
342+ metadata .getQuality ());
343+ assertTrue ("Doc 4 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?4\\ }" ));
344+ } else if ( "doc5.json" .equals (doc .getUri ()) ) {
345+ assertEquals ("Doc5 should use the 2nd batch default metadata, with quality 2" , 2 ,
346+ metadata .getQuality ());
347+ assertTrue ("Doc 5 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?5\\ }" ));
348+ } else if ( "doc6.json" .equals (doc .getUri ()) ) {
349+ assertEquals ("Doc 6 should have the system default quality of 0" , 0 ,
350+ metadata .getQuality ());
351+ assertTrue ("Doc 6 contents are wrong" , content .get ().matches ("\\ {\" number\" : ?6\\ }" ));
352+ }
353+ }
354+
355+ // now try with just metadata
356+ documents = jdm .readMetadata ("doc4.json" , "doc5.json" , "doc6.json" );
357+ for ( DocumentRecord doc : documents ) {
358+ DocumentMetadataHandle metadata = doc .getMetadata (new DocumentMetadataHandle ());
359+ if ( "doc4.json" .equals (doc .getUri ()) ) {
360+ assertEquals ("Doc4 should also use the 1st batch default metadata, with quality 1" , 1 ,
361+ metadata .getQuality ());
362+ } else if ( "doc5.json" .equals (doc .getUri ()) ) {
363+ assertEquals ("Doc5 should use the 2nd batch default metadata, with quality 2" , 2 ,
364+ metadata .getQuality ());
365+ } else if ( "doc6.json" .equals (doc .getUri ()) ) {
366+ assertEquals ("Doc 6 should have the system default quality of 0" , 0 ,
367+ metadata .getQuality ());
349368 }
350369 }
351370 }
0 commit comments