1818import com .marklogic .client .DatabaseClient ;
1919import com .marklogic .client .DatabaseClientFactory ;
2020import com .marklogic .client .DatabaseClientFactory .Authentication ;
21+ import com .marklogic .client .FailedRequestException ;
2122import com .marklogic .client .Transaction ;
2223import com .marklogic .client .admin .ExtensionLibrariesManager ;
2324import com .marklogic .client .document .DocumentDescriptor ;
@@ -96,6 +97,28 @@ public void testPartialUpdateXML() throws IOException
9697 // release client
9798 client .release ();
9899 }
100+
101+ /* Used to test Git issue # 94 along with uber-app server. use a bad user to authenticate client.
102+ * Should be throwing FailedRequestException Exception.
103+ * Message : Local message: write failed: Unauthorized. Server Message: Unauthorized
104+ */
105+ @ Test (expected =FailedRequestException .class )
106+ public void testJSONParserException () throws IOException
107+ {
108+ System .out .println ("Running testPartialUpdateJSON" );
109+
110+ String [] filenames = {"json-original.json" };
111+
112+ DatabaseClient client = DatabaseClientFactory .newClient ("localhost" , uberPort , dbName , "bad-eval-user" , "x" , Authentication .DIGEST );
113+
114+ // write docs
115+ for (String filename : filenames )
116+ {
117+ writeDocumentUsingInputStreamHandle (client , filename , "/partial-update/" , "JSON" );
118+ }
119+ // release client
120+ client .release ();
121+ }
99122
100123 @ Test
101124 public void testPartialUpdateJSON () throws IOException
@@ -122,8 +145,9 @@ public void testPartialUpdateJSON() throws IOException
122145 fragmentNode = mapper .createObjectNode ();
123146 fragmentNode .put ("insertedKey" , 9 );
124147 String fragment = mapper .writeValueAsString (fragmentNode );
125-
126- patchBldr .insertFragment ("$.employees" , Position .LAST_CHILD , fragment );
148+
149+ String jsonpath = new String ("$.employees[2]" );
150+ patchBldr .insertFragment (jsonpath , Position .AFTER , fragment );
127151 DocumentPatchHandle patchHandle = patchBldr .build ();
128152 docMgr .patch (docId , patchHandle );
129153
@@ -532,10 +556,14 @@ public void testPartialUpdateCombinationTranscRevert() throws Exception{
532556
533557 }
534558
559+ /* We have Git issue #199 that tracks multiple patch on same JSONPath index.
560+ * This test uses different path index. This test was modified to account for the
561+ * correct path index elements.
562+ */
535563 @ Test
536564 public void testPartialUpdateCombinationJSON () throws Exception {
537565 System .out .println ("Running testPartialUpdateCombinationJSON" );
538- DatabaseClient client = DatabaseClientFactory .newClient ("localhost" , uberPort , dbName , "eval-user " , "x" , Authentication .DIGEST );
566+ DatabaseClient client = DatabaseClientFactory .newClient ("localhost" , 8011 , "rest-writer " , "x" , Authentication .DIGEST );
539567
540568 // write docs
541569 String [] filenames = {"json-original.json" };
@@ -557,23 +585,24 @@ public void testPartialUpdateCombinationJSON() throws Exception{
557585 fragmentNode = mapper .createObjectNode ();
558586 fragmentNode .put ("insertedKey" , 9 );
559587 String fragment = mapper .writeValueAsString (fragmentNode );
560- patchBldr .insertFragment ("$.employees" , Position .LAST_CHILD , fragment ).delete ("$.employees[2]" ).replaceApply ("$.employees[1].firstName" , patchBldr .call ().concatenateAfter ("Hi" ));
588+ // Original - patchBldr.insertFragment("$.employees", Position.LAST_CHILD, fragment).delete("$.employees[2]").replaceApply("$.employees[1].firstName", patchBldr.call().concatenateAfter("Hi"));
589+ patchBldr .insertFragment ("$.employees[0]" , Position .AFTER , fragment ).delete ("$.employees[2]" ).replaceApply ("$.employees[1].firstName" , patchBldr .call ().concatenateAfter ("Hi" ));
561590 DocumentPatchHandle patchHandle = patchBldr .build ();
562591 docMgr .patch (docId , patchHandle );
563592
564593 String content = docMgr .read (docId , new StringHandle ()).get ();
565594
566595 System .out .println ("After" + content );
567596
568- assertTrue ("fragment is not inserted" , content .contains ("{\" insertedKey\" :9}] " ));
597+ assertTrue ("fragment is not inserted" , content .contains ("{\" insertedKey\" :9}" ));
569598 assertTrue ("fragment is not inserted" , content .contains ("{\" firstName\" :\" AnnHi\" , \" lastName\" :\" Smith\" }" ));
570599 assertFalse ("fragment is not deleted" ,content .contains ("{\" firstName\" :\" Bob\" , \" lastName\" :\" Foo\" }" ));
571600
572601 // release client
573602 client .release ();
574603
575604 }
576-
605+
577606 @ Test
578607 public void testPartialUpdateMetadata () throws Exception {
579608 System .out .println ("Running testPartialUpdateMetadata" );
@@ -711,7 +740,7 @@ public void testPartialUpdateJSONDescriptor() throws IOException
711740 fragmentNode .put ("insertedKey" , 9 );
712741 String fragment = mapper .writeValueAsString (fragmentNode );
713742
714- patchBldr .insertFragment ("$.employees" , Position .LAST_CHILD , fragment );
743+ patchBldr .insertFragment ("$.employees[2] " , Position .AFTER , fragment );
715744 DocumentPatchHandle patchHandle = patchBldr .build ();
716745
717746 docMgr .patch (desc , patchHandle );
@@ -795,7 +824,7 @@ public void testPartialUpdateJSONDescriptorTranc() throws IOException
795824 fragmentNode .put ("insertedKey" , 9 );
796825 String fragment = mapper .writeValueAsString (fragmentNode );
797826 patchBldr .pathLanguage (PathLanguage .JSONPATH );
798- patchBldr .insertFragment ("$.employees" , Position .LAST_CHILD , fragment );
827+ patchBldr .insertFragment ("$.employees[2] " , Position .AFTER , fragment );
799828 DocumentPatchHandle patchHandle = patchBldr .build ();
800829 // Transaction t = client.openTransaction("Tranc");
801830 docMgr .patch (desc , patchHandle );//,t);
0 commit comments