Skip to content

Commit a53a73f

Browse files
Ajit GeorgeAjit George
authored andcommitted
Test cases for Git #94 and regression fix to Jsonpath in patch combination test method
1 parent 9085529 commit a53a73f

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

test-complete/src/test/java/com/marklogic/javaclient/TestPartialUpdate.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.marklogic.client.DatabaseClient;
1919
import com.marklogic.client.DatabaseClientFactory;
2020
import com.marklogic.client.DatabaseClientFactory.Authentication;
21+
import com.marklogic.client.FailedRequestException;
2122
import com.marklogic.client.Transaction;
2223
import com.marklogic.client.admin.ExtensionLibrariesManager;
2324
import 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
@@ -533,6 +556,10 @@ public void testPartialUpdateCombinationTranscRevert() throws Exception{
533556

534557
}
535558

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+
*/
536563
@Test
537564
public void testPartialUpdateCombinationJSON() throws Exception{
538565
System.out.println("Running testPartialUpdateCombinationJSON");
@@ -558,15 +585,16 @@ public void testPartialUpdateCombinationJSON() throws Exception{
558585
fragmentNode = mapper.createObjectNode();
559586
fragmentNode.put("insertedKey", 9);
560587
String fragment = mapper.writeValueAsString(fragmentNode);
561-
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"));
562590
DocumentPatchHandle patchHandle = patchBldr.build();
563591
docMgr.patch(docId, patchHandle);
564592

565593
String content = docMgr.read(docId, new StringHandle()).get();
566594

567595
System.out.println("After" + content);
568596

569-
assertTrue("fragment is not inserted", content.contains("{\"insertedKey\":9}]"));
597+
assertTrue("fragment is not inserted", content.contains("{\"insertedKey\":9}"));
570598
assertTrue("fragment is not inserted", content.contains("{\"firstName\":\"AnnHi\", \"lastName\":\"Smith\"}"));
571599
assertFalse("fragment is not deleted",content.contains("{\"firstName\":\"Bob\", \"lastName\":\"Foo\"}"));
572600

0 commit comments

Comments
 (0)