3535import com .fasterxml .jackson .databind .JsonNode ;
3636import com .fasterxml .jackson .databind .ObjectMapper ;
3737import com .fasterxml .jackson .databind .node .ArrayNode ;
38+ import com .fasterxml .jackson .databind .node .BooleanNode ;
3839import com .fasterxml .jackson .databind .node .ObjectNode ;
3940import com .marklogic .client .document .DocumentManager .Metadata ;
4041import com .marklogic .client .document .DocumentMetadataPatchBuilder .Cardinality ;
@@ -153,6 +154,9 @@ public void testJsonPathPatch() throws IOException {
153154 fragment = mapper .writeValueAsString (fragmentNode );
154155 patchBldr .insertFragment ("$.[\" arrayKey\" ]" , Position .LAST_CHILD ,
155156 Cardinality .ZERO_OR_ONE , fragment );
157+ patchBldr .replaceValue ("$.booleanKey" , true );
158+ patchBldr .replaceValue ("$.numberKey2" , 2 );
159+ patchBldr .replaceValue ("$.nullKey" , null );
156160
157161 DocumentPatchHandle patchHandle = patchBldr .pathLanguage (
158162 PathLanguage .JSONPATH ).build ();
@@ -179,6 +183,10 @@ public void testJsonPathPatch() throws IOException {
179183 childNode .put ("appendedKey" , "appended item" );
180184 childArray .add (childNode );
181185 expectedNode .set ("arrayKey" , childArray );
186+ expectedNode .put ("booleanKey" , true );
187+ expectedNode .put ("numberKey2" , 2 );
188+ expectedNode .putNull ("nullKey" );
189+
182190
183191 String docText = docMgr .read (docId , new StringHandle ()).get ();
184192 assertNotNull ("Read null string for patched JSON content" , docText );
@@ -272,6 +280,9 @@ public void testXPathPatch() throws IOException {
272280 fragment = mapper .writeValueAsString (fragmentNode );
273281 patchBldr .insertFragment ("/array-node('arrayKey')" , Position .BEFORE ,
274282 fragment );
283+ patchBldr .replaceValue ("/booleanKey" , true );
284+ patchBldr .replaceValue ("/numberKey2" , 2 );
285+ patchBldr .replaceValue ("/nullKey" , null );
275286
276287 //patchBldr.replaceApply("/node()/arrayKey/node()[string(.) eq '3']",
277288 // patchBldr.call().add(2));
@@ -306,18 +317,19 @@ public void testXPathPatch() throws IOException {
306317 childNode .put ("appendedKey" , "appended item" );
307318 childArray .add (childNode );
308319 expectedNode .set ("arrayKey" , childArray );
320+ expectedNode .put ("booleanKey" , true );
321+ expectedNode .put ("numberKey2" , 2 );
322+ expectedNode .putNull ("nullKey" );
309323
310324 String docText = docMgr .read (docId , new StringHandle ()).get ();
311-
325+
312326 assertNotNull ("Read null string for patched JSON content" , docText );
313327 JsonNode readNode = mapper .readTree (docText );
314-
315328
316329 logger .debug ("Before3:" + content );
317330 logger .debug ("After3:" +docText );
318331 logger .debug ("Expected3:" + mapper .writeValueAsString (expectedNode ));
319-
320-
332+
321333 assertTrue ("Patched JSON document without expected result" ,
322334 expectedNode .equals (readNode ));
323335
@@ -400,6 +412,9 @@ private ObjectNode makeContent(ObjectMapper mapper) throws IOException {
400412 childNode .put ("itemObjectKey" , "item object value" );
401413 childArray .add (childNode );
402414 sourceNode .set ("arrayKey" , childArray );
415+ sourceNode .put ("booleanKey" , false );
416+ sourceNode .put ("numberKey2" , 1 );
417+ sourceNode .put ("nullKey" , 0 );
403418
404419 return sourceNode ;
405420 }
0 commit comments