Skip to content

Commit 516ad8e

Browse files
georgeajitgeorgeajit
authored andcommitted
Added sanity checks for exists with transaction
1 parent 6bb71fd commit 516ad8e

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDocumentFormat.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import javax.xml.parsers.ParserConfigurationException;
2828

29+
import com.marklogic.client.Transaction;
2930
import org.custommonkey.xmlunit.exceptions.XpathException;
3031
import org.junit.AfterClass;
3132
import org.junit.BeforeClass;
@@ -51,8 +52,9 @@ public class TestDocumentFormat extends BasicJavaClientREST {
5152
public static void setUp() throws Exception
5253
{
5354
System.out.println("In setup");
54-
5555
configureRESTServer(dbName, fNames);
56+
// Create a user with minimal privs and test doc exists in a transaction.
57+
createRESTUser("userInTrans", "x", "rest-writer");
5658
}
5759

5860
@Test
@@ -692,10 +694,57 @@ public void testNegativeJSONFormatWithDOMHandle() throws KeyManagementException,
692694
client.release();
693695
}
694696

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+
695742
@AfterClass
696743
public static void tearDown() throws Exception
697744
{
698745
System.out.println("In tear down");
746+
//Delete user userInTrans
747+
deleteRESTUser("userInTrans");
699748
cleanupRESTServer(dbName, fNames);
700749
}
701750
}

0 commit comments

Comments
 (0)