Index: test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
===================================================================
--- test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java	(revision 5343)
+++ test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java	(revision 5344)
@@ -94,9 +94,9 @@
 	public static Test suite() 
 	{
 		TestSuite suite = new TestSuite();
-		suite.addTest(new CrudServiceTest("initialize"));
+		/*suite.addTest(new CrudServiceTest("initialize"));
 		suite.addTest(new CrudServiceTest("testSingletonAccessor"));
-		suite.addTest(new CrudServiceTest("testCreateAndGet"));
+		suite.addTest(new CrudServiceTest("testCreateAndGet"));*/
 		suite.addTest(new CrudServiceTest("testGetSystemMetadata"));
 		//suite.addTest(new CrudServiceTest(""));
 		//suite.addTest(new CrudServiceTest(""));
@@ -111,7 +111,23 @@
 	 */
 	public void testGetSystemMetadata()
 	{
-	    
+	    printTestHeader("testGetSystemMetadata");
+	    try
+	    {
+            CrudService cs = CrudService.getInstance();
+            AuthToken token = getToken();
+            //run create
+            Identifier id = createDoc(token, getTestDoc());
+            //get the systemMetadata and make sure it is the correct object for this testDoc
+            SystemMetadata sm = getSystemMetadata(token, id);
+            assertTrue(sm.getIdentifier().getValue().equals(id.getValue()));
+            assertTrue(sm.getChecksum().getValue().equals(checksum(getTestDoc())));
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+            fail("Error testing system metadata: " + e.getMessage());
+        }
 	}
 	
 	/**
@@ -125,6 +141,7 @@
 	 */
 	public void testCreateAndGet()
 	{
+	    printTestHeader("testCreateAndGet");
 	    try
 	    {
 	        CrudService cs = CrudService.getInstance();
@@ -149,6 +166,7 @@
 	 */
 	public void testSingletonAccessor()
 	{
+	    printTestHeader("testSingletonAccessor");
 	    CrudService cs = CrudService.getInstance();
 	    assertNotNull(cs);
 	}
@@ -159,15 +177,28 @@
 	 */
 	public void initialize() 
 	{
+	    printTestHeader("initialize");
 		assertTrue(1 == 1);
 	}
 	
 	/**
+	 * return the systemMetadata object for id
+	 */
+	private SystemMetadata getSystemMetadata(AuthToken token, Identifier id)
+	  throws Exception
+	{
+	    System.out.println("getting system metadata for id: " + id.getValue());
+	    CrudService cs = CrudService.getInstance();
+	    return cs.getSystemMetadata(token, id);
+	}
+	
+	/**
 	 * get a doc from metacat using CrudService.get()
 	 */
 	private String getDoc(AuthToken token, Identifier id)
 	  throws Exception
 	{
+	    System.out.println("getting doc for id " + id.getValue());
 	    CrudService cs = CrudService.getInstance();
 	    //try to get the same doc then compare them
         InputStream gotDocStream = cs.get(token, id);
@@ -179,7 +210,7 @@
             sb.append(new String(b, 0, numread));
             numread = gotDocStream.read(b, 0, 1024);
         }
-        
+        System.out.println("returning doc for id " + id.getValue());
         return sb.toString();
 	}
 	
@@ -225,11 +256,13 @@
         id = new Identifier();
         String docid = generateDocumentId();
         id.setValue(docid);
-                    
+        System.out.println("creating doc with id " + id.getValue());            
+        
         //create the system metadata then run the create method
         StringBufferInputStream sbis = new StringBufferInputStream(testDoc);
         SystemMetadata sm = new SystemMetadata();
         //set the id
+        System.out.println("creating system metadata object for document with id " + id.getValue());
         sm.setIdentifier(id);
         System.out.println("sm id is " + id.getValue());
         sm.setObjectFormat(ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0"));
@@ -258,8 +291,18 @@
         sm.setAuthoritativeMemberNode(nr);
         //create the doc
         cs.create(token, id, sbis, sm);
+        System.out.println("document with id " + id.getValue() + " created.");
         return id;
 	}
+	
+	/**
+	 * print a header to start each test
+	 */
+	private void printTestHeader(String testName)
+	{
+	    System.out.println();
+	    System.out.println("********************************** " + testName + " **********************************");
+	}
   
 	/**
 	 * produce an md5 checksum for item
Index: src/edu/ucsb/nceas/metacat/dataone/CrudService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/dataone/CrudService.java	(revision 5343)
+++ src/edu/ucsb/nceas/metacat/dataone/CrudService.java	(revision 5344)
@@ -265,7 +265,7 @@
                 public String produce(final OutputStream dataSink) throws Exception {
 
                     try {
-                        handler.readFromMetacat(/*request.getRemoteAddr()*/metacatUrl, null, 
+                        handler.readFromMetacat(metacatUrl, null, 
                                 dataSink, localId, "xml",
                                 sessionData.getUserName(), 
                                 sessionData.getGroupNames(), true, params);
@@ -327,12 +327,9 @@
                 
         try {
             IdentifierManager im = IdentifierManager.getInstance();
-            // This is a test id of an existing sysmeta document -- for temporary testing
-            String testGuid = "autogen.20101192441566.1";
-            // TODO: Look up ID of system metadata based on guid
-            // TODO: Initially from document, later from entry in table?
-//            String localId = im.getLocalId(guid.getValue());
-            final String localId = im.getLocalId(testGuid);
+            System.out.println("looking up systemmetadata id for guid " + guid.getValue());
+            final String localId = im.getSystemMetadataId(guid.getValue());
+            System.out.println("localId: " + localId);
             
             // Read system metadata from metacat's db
             final InputStreamFromOutputStream<String> objectStream = 
@@ -341,7 +338,7 @@
                 @Override
                 public String produce(final OutputStream dataSink) throws Exception {
                     try {
-                        handler.readFromMetacat(/*request.getRemoteAddr()*/metacatUrl, null, 
+                        handler.readFromMetacat(metacatUrl, null, 
                                 dataSink, localId, "xml",
                                 sessionData.getUserName(), 
                                 sessionData.getGroupNames(), true, params);
@@ -370,6 +367,7 @@
             return sysmeta;
             
         } catch (McdbDocNotFoundException e) {
+            e.printStackTrace();
             throw new NotFound(1000, e.getMessage());
         }                
     }
@@ -484,7 +482,7 @@
                     }
     
                     logMetacat.debug("Logging the creation event.");
-                    EventLog.getInstance().log(/*request.getRemoteAddr()*/metacatUrl,
+                    EventLog.getInstance().log(metacatUrl,
                             username, localId, "create");
     
                     // Schedule replication for this data file
@@ -546,7 +544,8 @@
         String localId = insertDocument(xml, sysMetaGuid, sessionData);
         //insert the system metadata doc id into the identifiers table to 
         //link it to the data or metadata document
-        IdentifierManager.getInstance().createSystemMetadataMapping(sysMetaGuid.getValue(), localId);
+        System.out.println("mapping systemmetadata id to docid in im.insertSystemMetadata");
+        IdentifierManager.getInstance().createSystemMetadataMapping(sysmeta.getIdentifier().getValue(), sysMetaGuid.getValue());
     }
     
     /**
@@ -578,7 +577,7 @@
         // generate the right exceptions
         //ByteArrayOutputStream output = new ByteArrayOutputStream();
         //PrintWriter pw = new PrintWriter(output);
-        String result = handler.handleInsertOrUpdateAction(/*request.getRemoteAddr()*/metacatUrl, null, 
+        String result = handler.handleInsertOrUpdateAction(metacatUrl, null, 
                             null, params, sessionData.getUserName(), sessionData.getGroupNames());
         //String outputS = new String(output.toByteArray());
         logMetacat.debug("CrudService.insertDocument - Metacat returned: " + result);
Index: src/edu/ucsb/nceas/metacat/IdentifierManager.java
===================================================================
--- src/edu/ucsb/nceas/metacat/IdentifierManager.java	(revision 5343)
+++ src/edu/ucsb/nceas/metacat/IdentifierManager.java	(revision 5344)
@@ -254,6 +254,7 @@
       int rev = 0;
       
       String query = "select guid, docid, rev from " + type + " where guid = ?";
+      System.out.println("query: " + query + " for params: (" + guid + ")");
       
       DBConnection dbConn = null;
       int serialNumber = -1;
@@ -301,7 +302,11 @@
             // Parse the localId into scope and rev parts
             AccessionNumber acc = new AccessionNumber(localId, "NOACTION");
             String docid = acc.getDocid();
-            int rev = (new Integer(acc.getRev()).intValue());
+            int rev = 1;
+            if(acc.getRev() != null)
+            {
+              rev = (new Integer(acc.getRev()).intValue());
+            }
 
             // Get a database connection from the pool
             dbConn = 
@@ -309,7 +314,8 @@
             serialNumber = dbConn.getCheckOutSerialNumber();
 
             // Execute the insert statement
-            String query = "insert into " + type + " (guid, docid, rev) values (?, ?, ?)";            
+            String query = "insert into " + type + " (guid, docid, rev) values (?, ?, ?)";
+            System.out.println("query: " + query + " for params: (" + guid + ", " + docid + ", " + rev + ")");
             PreparedStatement stmt = dbConn.prepareStatement(query);
             stmt.setString(1, guid);
             stmt.setString(2, docid);
@@ -318,12 +324,15 @@
 
             stmt.close();
         } catch (SQLException e) {
+            e.printStackTrace();
             logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " 
                     + e.getMessage());
         } catch (NumberFormatException e) {
+            e.printStackTrace();
             logMetacat.error("NumberFormat error while creating a mapping to the system metadata identifier: " 
                     + e.getMessage());
         } catch (AccessionNumberException e) {
+            e.printStackTrace();
             logMetacat.error("AccessionNumber error while creating a mapping to the system metadata identifier: " 
                     + e.getMessage());
         } finally {
