Index: test/edu/ucsb/nceas/metacattest/client/MetacatClientTest.java
===================================================================
--- test/edu/ucsb/nceas/metacattest/client/MetacatClientTest.java	(revision 3211)
+++ test/edu/ucsb/nceas/metacattest/client/MetacatClientTest.java	(revision 3212)
@@ -27,9 +27,11 @@
 
 import java.io.File;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
@@ -74,6 +76,8 @@
     private Metacat m;
     private String spatialTestFile = "test/spatialEml.xml";
     private static final int TIME = 30;
+    private static final String DOCID = "docid";
+    private static final String DATAID = "dataid";
     
     /**
      * Constructor to build the test
@@ -227,7 +231,8 @@
     {
         try {
             m.login(username, password);
-            Reader r = m.read(newdocid+".1");
+            String docid = readIdFromFile(DOCID);
+            Reader r = m.read(docid+".1");
             String doc = IOUtil.getAsString(r, true);
             doc = doc +"\n";
             //System.err.println(doc);
@@ -248,7 +253,8 @@
     {
         try {
             m.login(anotheruser, anotherpassword);
-            Reader r = m.read(newdocid+".1");
+            String docid = readIdFromFile(DOCID);
+            Reader r = m.read(docid+".1");
             String doc = IOUtil.getAsString(r, true);
             assertTrue(doc.indexOf("<error>") != -1);
             //System.err.println(doc);
@@ -265,6 +271,8 @@
         } catch (DocumentNotFoundException ne) {
             fail("DocumentNotFound exception:\n" + ne.getMessage());
 
+        } catch(Exception e) {
+            fail("Exception:\n" + e.getMessage());
         }
     }
 
@@ -280,7 +288,8 @@
             //System.err.println("Starting query...");
             String result = IOUtil.getAsString(r, true);
             //System.err.println("Query result:\n" + result);
-            assertTrue(result.indexOf(newdocid+".1")!=-1);
+            String docid = readIdFromFile(DOCID);
+            assertTrue(result.indexOf(docid+".1")!=-1);
         } catch (MetacatAuthException mae) {
             fail("Authorization failed:\n" + mae.getMessage());
         } catch (MetacatInaccessibleException mie) {
@@ -297,6 +306,8 @@
     {
         try {
             String identifier = newdocid + ".1";
+            //write newdocid into file for persistance
+            writeIdToFile(DOCID, newdocid);
             m.login(username, password);
             String response = m.insert(identifier,
                     new StringReader(testdocument), null);
@@ -326,6 +337,7 @@
         try {
             newdocid = generateDocid();
             String identifier = newdocid + ".1";
+            writeIdToFile(DATAID, newdocid);
             m.login(username, password);
             String response = m.upload(identifier,
                                      new File(onlinetestdatafile));
@@ -388,7 +400,8 @@
     public void invalidUpdate()
     {
         try {
-            String identifier = newdocid + ".2";
+        	String docid = readIdFromFile(DOCID);
+            String identifier = docid + ".2";
             m.login(anotheruser, anotherpassword);
             String response = m.update(identifier,
                     new StringReader(testdocument), null);
@@ -413,7 +426,8 @@
     public void update()
     {
         try {
-            String identifier = newdocid + ".2";
+        	String docid = readIdFromFile(DOCID);
+            String identifier = docid + ".2";
             m.login(username, password);
             String response = m.update(identifier,
                     new StringReader(testdocument), null);
@@ -465,10 +479,15 @@
     public void delete()
     {
         try {
-            String identifier = newdocid + ".2";
+        	Thread.sleep(10000);
+        	String docid = readIdFromFile(DOCID);
+            String identifier = docid + ".2";
             m.login(username, password);
             String response = m.delete(identifier);
             assertTrue(response.indexOf("<success>") != -1);
+            // delete the docid persistence file.
+            deleteFile(DOCID);
+            deleteFile(DATAID);
             //System.err.println(response);
 
         } catch (MetacatAuthException mae) {
@@ -612,7 +631,9 @@
            }
            String lastId = m3.getLastDocid(prefix);
            System.err.println("Last Id: " + lastId);
-           assertTrue(lastId.equals(newdocid + ".1"));
+           //get docid from file
+           String docid = readIdFromFile(DOCID);
+           assertTrue(lastId.equals(docid + ".1"));
        } catch (MetacatException me) {
            fail("Metacat Error:\n" + me.getMessage());
        } catch (Exception e) {
@@ -637,8 +658,9 @@
                System.err.println("Metacat is: " + metacatUrl);
                fail("Metacat connection failed." + mie.getMessage());
            }
-          
-           int revision = m3.getNewestDocRevision(newdocid);
+           // get docid from file
+           String docid = readIdFromFile(DOCID);
+           int revision = m3.getNewestDocRevision(docid);
            //System.err.println("Newest revision number is: " + revision);
            assertTrue(revision == 1);
        } catch (MetacatException me) {
@@ -762,4 +784,51 @@
 	
 	return docid.toString();
     }
+    
+    /*
+     * Write id to a file for persistance
+     */
+    private void writeIdToFile(String fileName, String id) throws Exception
+    {
+    	File file = new File(fileName);
+    	StringReader reader = new StringReader(id);
+    	FileWriter writer = new FileWriter(file);
+    	char [] buffer = new char[1024];
+    	int c = reader.read(buffer);
+    	while (c != -1)
+    	{
+    		writer.write(buffer, 0, c);
+    		c = reader.read(buffer);
+    	}
+    	writer.close();
+    	reader.close();
+    }
+    
+    /*
+     * Read id from a given file
+     */
+    private String readIdFromFile(String fileName) throws Exception
+    {
+    	File file = new File(fileName);
+    	FileReader reader = new FileReader(file);
+    	StringWriter writer = new StringWriter();
+    	char [] buffer = new char[1024];
+    	int c = reader.read(buffer);
+    	while (c != -1)
+    	{
+    		writer.write(buffer, 0, c);
+    		c = reader.read(buffer);
+    	}
+    	reader.close();
+    	return writer.toString();
+    }
+    
+    /*
+     * Delete the given file
+     */
+    private void deleteFile(String fileName) throws Exception
+    {
+    	File file = new File(fileName);
+    	file.delete();
+    }
 }
