@@ -49,14 +49,97 @@ public class TestDocumentFormat extends BasicJavaClientREST {
4949 private static String [] fNames = { "TestDocumentFormat-1" };
5050
5151 @ BeforeClass
52- public static void setUp () throws Exception
53- {
52+ public static void setUp () throws Exception {
5453 System .out .println ("In setup" );
5554 configureRESTServer (dbName , fNames );
5655 // Create a user with minimal privs and test doc exists in a transaction.
5756 createRESTUser ("userInTrans" , "x" , "rest-writer" );
5857 }
5958
59+ @ Test
60+ public void testExistsInTransMinPrivs () throws KeyManagementException , NoSuchAlgorithmException , IOException , ParserConfigurationException , SAXException , XpathException
61+ {
62+ System .out .println ("Running testExistsInTransMinPrivs" );
63+ DatabaseClient client1 = null ;
64+ try {
65+ String filename = "json-original.json" ;
66+ String uri1 = "/DocExistsInTransMinimalPriv/" ;
67+
68+ // user with minimal privs.
69+ client1 = getDatabaseClient ("userInTrans" , "x" , getConnType ());
70+
71+ // create doc manager
72+ DocumentManager docMgr1 = client1 .newDocumentManager ();
73+ Transaction t1 = client1 .openTransaction ();
74+
75+ File file = new File ("src/test/java/com/marklogic/client/functionaltest/data/" + filename );
76+
77+ // create a handle on the content
78+ FileHandle handle = new FileHandle (file );
79+ handle .set (file );
80+
81+ handle .setFormat (Format .JSON );
82+
83+ // create docIds
84+ String docId1 = uri1 + filename ;
85+ docMgr1 .write (docId1 , handle );
86+ String expectedUri1 = uri1 + filename ;
87+
88+ String docUri1 = docMgr1 .exists (expectedUri1 , t1 ).getUri ();
89+ assertEquals ("URI is not found" , expectedUri1 , docUri1 );
90+ t1 .rollback ();
91+ }
92+ catch (Exception ex ) {
93+ System .out .println (ex .getMessage ());
94+ } finally {
95+ // release the clients
96+ if (client1 != null )
97+ client1 .release ();
98+ }
99+ }
100+
101+ @ Test
102+ public void testExistsInTransWithPrivs () throws KeyManagementException , NoSuchAlgorithmException , IOException , ParserConfigurationException , SAXException , XpathException
103+ {
104+ System .out .println ("Running testExistsInTransWithPrivs" );
105+ DatabaseClient client2 = null ;
106+ try {
107+ String filename = "json-original.json" ;
108+ String uri2 = "/DocExistsTransWithPrivs/" ;
109+
110+ // user with privs.
111+ client2 = getDatabaseClient ("rest-writer" , "x" , getConnType ());
112+
113+ // create doc manager
114+ DocumentManager docMgr2 = client2 .newDocumentManager ();
115+ Transaction t2 = client2 .openTransaction ();
116+
117+ File file = new File ("src/test/java/com/marklogic/client/functionaltest/data/" + filename );
118+
119+ // create a handle on the content
120+ FileHandle handle = new FileHandle (file );
121+ handle .set (file );
122+
123+ handle .setFormat (Format .JSON );
124+
125+ // create docIds
126+ String docId2 = uri2 + filename ;
127+ docMgr2 .write (docId2 , handle );
128+
129+ String expectedUri2 = uri2 + filename ;
130+ String docUri2 = docMgr2 .exists (expectedUri2 , t2 ).getUri ();
131+ assertEquals ("URI is not found" , expectedUri2 , docUri2 );
132+ t2 .rollback ();
133+ }
134+ catch (Exception ex ) {
135+ System .out .println (ex .getMessage ());
136+ } finally {
137+ // release the clients
138+ if (client2 != null )
139+ client2 .release ();
140+ }
141+ }
142+
60143 @ Test
61144 public void testXMLFormatOnXML () throws KeyManagementException , NoSuchAlgorithmException , IOException , ParserConfigurationException , SAXException , XpathException
62145 {
@@ -120,8 +203,7 @@ public void testJSONFormatOnXML() throws KeyManagementException, NoSuchAlgorithm
120203 String exception = "" ;
121204 String expectedException = "" ;
122205
123- try
124- {
206+ try {
125207 docMgr .write (docId , handle );
126208 } catch (Exception e ) {
127209 exception = e .toString ();
@@ -407,13 +489,11 @@ public void testXMLFormatOnBinary() throws KeyManagementException, NoSuchAlgorit
407489 String exception = "" ;
408490 String expectedException = "" ;
409491
410- try
411- {
492+ try {
412493 docMgr .write (docId , handle );
413494 } catch (Exception e ) {
414495 exception = e .toString ();
415496 }
416-
417497 boolean isExceptionThrown = exception .contains (expectedException );
418498 assertTrue ("Exception is not thrown" , isExceptionThrown );
419499
@@ -449,8 +529,7 @@ public void testJSONFormatOnBinary() throws KeyManagementException, NoSuchAlgori
449529 String exception = "" ;
450530 String expectedException = "" ;
451531
452- try
453- {
532+ try {
454533 docMgr .write (docId , handle );
455534 } catch (Exception e ) {
456535 exception = e .toString ();
@@ -491,8 +570,7 @@ public void testTextFormatOnBinary() throws KeyManagementException, NoSuchAlgori
491570 String exception = "" ;
492571 String expectedException = "" ;
493572
494- try
495- {
573+ try {
496574 docMgr .write (docId , handle );
497575 } catch (Exception e ) {
498576 exception = e .toString ();
@@ -603,8 +681,7 @@ public void testJSONFormatOnText() throws KeyManagementException, NoSuchAlgorith
603681 String exception = "" ;
604682 String expectedException = "" ;
605683
606- try
607- {
684+ try {
608685 docMgr .write (docId , handle );
609686 } catch (Exception e ) {
610687 exception = e .toString ();
@@ -669,19 +746,14 @@ public void testNegativeJSONFormatWithDOMHandle() throws KeyManagementException,
669746
670747 Document readDoc = expectedXMLDocument (filename );
671748
672- // File file = new
673- // File("src/test/java/com/marklogic/client/functionaltest/data/" +
674- // filename);
675-
676749 // create a handle on the content
677750 DOMHandle handle = new DOMHandle ();
678751 handle .set (readDoc );
679752
680753 String exception = "" ;
681754 String expectedException = "java.lang.IllegalArgumentException: DOMHandle supports the XML format only" ;
682755
683- try
684- {
756+ try {
685757 handle .setFormat (Format .JSON );
686758 } catch (IllegalArgumentException e ) {
687759 exception = e .toString ();
@@ -694,55 +766,11 @@ public void testNegativeJSONFormatWithDOMHandle() throws KeyManagementException,
694766 client .release ();
695767 }
696768
697- @ Test
698- public void testDocExistsWithTransaction () throws KeyManagementException , NoSuchAlgorithmException , IOException , ParserConfigurationException , SAXException , XpathException
699- {
700- System .out .println ("Running testDocExistsWithTransaction" );
701-
702- String filename = "json-original.json" ;
703- String uri1 = "/DocExistsInTransMinimalPriv/" ;
704- String uri2 = "/DocExistsTransWithPrivs/" ;
705-
706- // user with minimal privs.
707- DatabaseClient client1 = getDatabaseClient ("userInTrans" , "x" , getConnType ());
708- // user with privs.
709- DatabaseClient client2 = getDatabaseClient ("rest-writer" , "x" , getConnType ());
710-
711- // create doc manager
712- DocumentManager docMgr1 = client1 .newDocumentManager ();
713- DocumentManager docMgr2 = client2 .newDocumentManager ();
714- Transaction t1 = client1 .openTransaction ();
715- Transaction t2 = client2 .openTransaction ();
716-
717- File file = new File ("src/test/java/com/marklogic/client/functionaltest/data/" + filename );
718-
719- // create a handle on the content
720- FileHandle handle = new FileHandle (file );
721- handle .set (file );
722-
723- handle .setFormat (Format .JSON );
724-
725- // create docIds
726- String docId1 = uri1 + filename ;
727- String docId2 = uri2 + filename ;
728- docMgr1 .write (docId1 , handle );
729- docMgr2 .write (docId2 , handle );
730-
731- String expectedUri1 = uri1 + filename ;
732- String expectedUri2 = uri2 + filename ;
733- String docUri1 = docMgr1 .exists (expectedUri1 , t1 ).getUri ();
734- String docUri2 = docMgr2 .exists (expectedUri2 , t2 ).getUri ();
735- assertEquals ("URI is not found" , expectedUri1 , docUri1 );
736- assertEquals ("URI is not found" , expectedUri2 , docUri2 );
737- // release the clients
738- client1 .release ();
739- client2 .release ();
740- }
741-
742769 @ AfterClass
743770 public static void tearDown () throws Exception
744771 {
745772 System .out .println ("In tear down" );
746773 cleanupRESTServer (dbName , fNames );
774+ deleteRESTUser ("userInTrans" );
747775 }
748776}
0 commit comments