@@ -109,7 +109,40 @@ public void testPartialUpdateXML() throws IOException
109109 System .out .println (content );
110110
111111 assertTrue ("fragment is not inserted" , content .contains ("<modified>2013-03-21</modified></root>" ));
112+
113+ // Check boolean replaces with XML documents.
114+ String xmlDocId = "/replaceBoolXml" ;
115+
116+ String xmlStr1 = new String ("<?xml version=\" 1.0\" encoding=\" utf-8\" ?>" );
117+ String xmlStr2 = new String ("<resources><screen name=\" screen_small\" >true</screen><screen name=\" adjust_view_bounds\" >false</screen></resources>" );
118+ StringBuffer xmlStrbuf = new StringBuffer ().append (xmlStr1 ).append (xmlStr2 );
119+
120+ StringHandle contentHandle = new StringHandle ();
121+ contentHandle .set (xmlStrbuf .toString ());
112122
123+ // write the document content
124+ docMgr .write (xmlDocId , contentHandle );
125+
126+ // Read it back to make sure the write worked.
127+ String contentXml = docMgr .read (xmlDocId , new StringHandle ()).get ();
128+
129+ assertTrue ("XML Replace fragment is not inserted" , contentXml .contains (xmlStr2 ));
130+
131+ DocumentPatchBuilder patchBldrBool = docMgr .newPatchBuilder ();
132+ patchBldrBool .pathLanguage (PathLanguage .XPATH );
133+
134+ // Flip the boolean values for both screen types
135+ patchBldrBool .replaceValue ("/resources/screen[@name=\" screen_small\" ]" , false );
136+ patchBldrBool .replaceValue ("/resources/screen[@name=\" adjust_view_bounds\" ]" , new Boolean (true ));
137+
138+ DocumentPatchHandle patchHandleBool = patchBldrBool .build ();
139+ docMgr .patch (xmlDocId , patchHandleBool );
140+
141+ String content1 = docMgr .read (xmlDocId , new StringHandle ()).get ();
142+ System .out .println (content1 );
143+ String xmlStr2Mod = new String ("<resources><screen name=\" screen_small\" >false</screen><screen name=\" adjust_view_bounds\" >true</screen></resources>" );
144+
145+ assertTrue ("XML fragment is not replaced" , content1 .contains (xmlStr2Mod ));
113146 // release client
114147 client .release ();
115148 }
@@ -157,22 +190,53 @@ public void testPartialUpdateJSON() throws IOException
157190 JSONDocumentManager docMgr = client .newJSONDocumentManager ();
158191 DocumentPatchBuilder patchBldr = docMgr .newPatchBuilder ();
159192 patchBldr .pathLanguage (PathLanguage .JSONPATH );
193+
160194 ObjectNode fragmentNode = mapper .createObjectNode ();
161- fragmentNode = mapper .createObjectNode ();
195+ ObjectNode fragmentNode1 = mapper .createObjectNode ();
196+ ObjectNode fragmentNode2 = mapper .createObjectNode ();
197+
162198 fragmentNode .put ("insertedKey" , 9 );
199+ fragmentNode1 .put ("original" , true );
200+ fragmentNode2 .put ("modified" , false );
201+
163202 String fragment = mapper .writeValueAsString (fragmentNode );
203+ String fragment1 = mapper .writeValueAsString (fragmentNode1 );
204+ String fragment2 = mapper .writeValueAsString (fragmentNode2 );
164205
165206 String jsonpath = new String ("$.employees[2]" );
166207 patchBldr .insertFragment (jsonpath , Position .AFTER , fragment );
208+ patchBldr .insertFragment ("$.employees[2]" , Position .AFTER , fragment1 );
209+ patchBldr .insertFragment ("$.employees[0]" , Position .AFTER , fragment2 );
210+
167211 DocumentPatchHandle patchHandle = patchBldr .build ();
168212 docMgr .patch (docId , patchHandle );
169213
170214 String content = docMgr .read (docId , new StringHandle ()).get ();
171215
172216 System .out .println (content );
173217
174- assertTrue ("fragment is not inserted" , content .contains ("{\" insertedKey\" :9}]" ));
218+ assertTrue ("fragment is not inserted" , content .contains ("{\" insertedKey\" :9}" ));
219+ assertTrue ("Original fragment is not inserted or incorrect" , content .contains ("{\" original\" :true}" ));
220+ assertTrue ("Modified fragment is not inserted or incorrect" , content .contains ("{\" modified\" :false}" ));
221+
222+ // Test for replaceValue with booleans.
223+ DocumentPatchBuilder patchBldrBool = docMgr .newPatchBuilder ();
224+ patchBldrBool .pathLanguage (PathLanguage .JSONPATH );
225+
226+ //Replace original to false and modified to true.
227+ patchBldrBool .replaceValue ("$.employees[5].original" , false );
228+ patchBldrBool .replaceValue ("$.employees[1].modified" , new Boolean (true ));
229+
230+ DocumentPatchHandle patchHandleBool = patchBldrBool .build ();
231+ docMgr .patch (docId , patchHandleBool );
175232
233+ String content1 = docMgr .read (docId , new StringHandle ()).get ();
234+
235+ System .out .println (content1 );
236+ // Make sure the inserted content is present.
237+ assertTrue ("Original fragment is not replaced" , content1 .contains ("{\" original\" :false}" ));
238+ assertTrue ("Modified fragment is not replaced" , content1 .contains ("{\" modified\" :true}" ));
239+
176240 // release client
177241 client .release ();
178242 }
0 commit comments