Index: test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java
===================================================================
--- test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java	(nonexistent)
+++ test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java	(revision 7510)
@@ -0,0 +1,183 @@
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2010 Regents of the University of California and the
+ *              National Center for Ecological Analysis and Synthesis
+ *  Purpose: To test the Access Controls in metacat by JUnit
+ *
+ *   '$Author$'
+ *     '$Date$'
+ * '$Revision$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package edu.ucsb.nceas.metacat.dataone;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dataone.configuration.Settings;
+import org.dataone.service.types.v1.Identifier;
+import org.dataone.service.types.v1.Session;
+import org.dataone.service.types.v1.SystemMetadata;
+import org.junit.After;
+import org.junit.Before;
+
+import edu.ucsb.nceas.ezid.EZIDService;
+import edu.ucsb.nceas.ezid.profile.DataCiteProfile;
+import edu.ucsb.nceas.metacat.properties.PropertyService;
+
+/**
+ * A JUnit test to exercise the DOI registration for content added
+ * via the DataONE MN API
+ * 
+ * @author leinfelder
+ *
+ */
+public class RegisterDOITest extends D1NodeServiceTest {
+
+  /**
+   * Set up the test fixtures
+   * 
+   * @throws Exception
+   */
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    // set up the configuration for d1client
+    Settings.getConfiguration().setProperty("D1Client.cnClassName", MockCNode.class.getName());
+  }
+
+  /**
+   * Remove the test fixtures
+   */
+  @After
+  public void tearDown() {
+  }
+  
+  /**
+   * Build the test suite
+   * @return
+   */
+  public static Test suite() {
+    
+    TestSuite suite = new TestSuite();
+    suite.addTest(new RegisterDOITest("initialize"));
+    
+    // DOI registration test
+    //suite.addTest(new RegisterDOITest("testCreateDOI"));
+    suite.addTest(new RegisterDOITest("testMintAndCreateDOI"));
+
+    return suite;
+    
+  }
+  
+  /**
+   * Constructor for the tests
+   * 
+   * @param name - the name of the test
+   */
+  public RegisterDOITest(String name) {
+    super(name);
+    
+  }
+
+  /**
+   * Initial blank test
+   */
+  public void initialize() {
+    assertTrue(1 == 1);
+    
+  }
+  
+  	/**
+	 * Test object creation
+	 */
+	public void testMintAndCreateDOI() {
+		printTestHeader("testMintAndCreateDOI");
+
+		try {
+			// get ezid config properties
+			String ezidUsername = PropertyService.getProperty("guid.ezid.username");
+			String ezidPassword = PropertyService.getProperty("guid.ezid.password");
+			String ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
+			
+			EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
+			ezid.login(ezidUsername, ezidPassword);
+			
+			// Mint a DOI
+			Session session = getTestSession();
+			Identifier guid = MNodeService.getInstance(request).generateIdentifier(session, "DOI", null);
+			
+			// check that EZID knows about it
+			HashMap<String, String> metadata = ezid.getMetadata(guid.getValue());
+			assertNotNull(metadata);
+
+			// add the actual object for the newly-minted DOI
+			InputStream object = new ByteArrayInputStream( "test".getBytes("UTF-8"));
+			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
+			Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
+			assertEquals(guid.getValue(), pid.getValue());
+
+			// check for the metadata for title element
+			metadata = ezid.getMetadata(pid.getValue());
+			assertNotNull(metadata);
+			assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail("Unexpected error: " + e.getMessage());
+		}
+	}
+	
+	/**
+	 * Test object creation
+	 */
+	public void testCreateDOI() {
+		printTestHeader("testCreateDOI");
+
+		try {
+			// get ezid config properties
+			String shoulder = PropertyService.getProperty("guid.ezid.doishoulder.1");
+			String ezidUsername = PropertyService.getProperty("guid.ezid.username");
+			String ezidPassword = PropertyService.getProperty("guid.ezid.password");
+			String ezidServiceBaseUrl = PropertyService.getProperty("guid.ezid.baseurl");
+			
+			Session session = getTestSession();
+			Identifier guid = new Identifier();
+			guid.setValue(shoulder + "/testCreateDOI." + System.currentTimeMillis());
+			InputStream object = new ByteArrayInputStream( "test".getBytes("UTF-8"));
+			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
+			Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
+			assertEquals(guid.getValue(), pid.getValue());
+
+			// check for the metadata explicitly, using ezid service
+			EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
+			ezid.login(ezidUsername, ezidPassword);
+			HashMap<String, String> metadata = ezid.getMetadata(pid.getValue());
+			assertNotNull(metadata);
+			assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail("Unexpected error: " + e.getMessage());
+		}
+	}
+}

Property changes on: test/edu/ucsb/nceas/metacat/dataone/RegisterDOITest.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: lib/ezid-0.9.0-SNAPSHOT.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
===================================================================
--- src/edu/ucsb/nceas/metacat/dataone/MNodeService.java	(revision 7509)
+++ src/edu/ucsb/nceas/metacat/dataone/MNodeService.java	(revision 7510)
@@ -28,6 +28,7 @@
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.security.NoSuchAlgorithmException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -96,11 +97,11 @@
 import org.dataone.service.types.v1_1.QueryEngineList;
 import org.dataone.service.types.v1_1.QueryField;
 import org.dataone.service.util.Constants;
-import org.dataone.service.util.DateTimeMarshaller;
 
 import edu.ucsb.nceas.ezid.EZIDException;
 import edu.ucsb.nceas.ezid.EZIDService;
 import edu.ucsb.nceas.ezid.profile.DataCiteProfile;
+import edu.ucsb.nceas.ezid.profile.ErcMissingValueCode;
 import edu.ucsb.nceas.ezid.profile.InternalProfile;
 import edu.ucsb.nceas.metacat.DBQuery;
 import edu.ucsb.nceas.metacat.EventLog;
@@ -413,7 +414,9 @@
         try {
 			registerDOI(sysmeta);
 		} catch (EZIDException e) {
-            throw new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
+			ServiceFailure sf = new ServiceFailure("1190", "Could not register DOI: " + e.getMessage());
+			sf.initCause(e);
+            throw sf;
 		}
         
         // return 
@@ -1268,8 +1271,12 @@
 				throw new InvalidRequest("2193", "DOI scheme is not enabled at this node.");
 			}
 			
-			// do not enter metadata about this identifier since we do not know anything about it
-			HashMap<String, String> metadata = null;
+			// add only the minimal metadata required for this DOI
+			HashMap<String, String> metadata = new HashMap<String, String>();
+			metadata.put(DataCiteProfile.TITLE.toString(), ErcMissingValueCode.UNKNOWN.toString());
+			metadata.put(DataCiteProfile.CREATOR.toString(), ErcMissingValueCode.UNKNOWN.toString());
+			metadata.put(DataCiteProfile.PUBLISHER.toString(), ErcMissingValueCode.UNKNOWN.toString());
+			metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), ErcMissingValueCode.UNKNOWN.toString());
 			try {
 				// call the EZID service
 				String ezidServiceBaseUrl = null;
@@ -1556,20 +1563,27 @@
 				
 				// check for existing metadata
 				boolean create = false;
-				metadata = ezid.getMetadata(identifier);
+				try {
+					metadata = ezid.getMetadata(identifier);
+				} catch (EZIDException e) {
+					// expected much of the time
+					logMetacat.warn("No metadata found for given identifier: " + e.getMessage());
+				}
 				if (metadata == null) {
 					create = true;
-					metadata = new HashMap<String, String>();
 				}
+				// confuses the API if we send the original metadata that it gave us, so start from scratch
+				metadata = new HashMap<String, String>();
 				
-				// TODO: set values in the metadata with better values
+				// TODO: set title and creator to better values
 				Node node = getCapabilities();
-				metadata.put(DataCiteProfile.TITLE.toString(), "TBD");
+				SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
+				String year = sdf .format(sysMeta.getDateUploaded());
+				metadata.put(DataCiteProfile.TITLE.toString(), ErcMissingValueCode.UNKNOWN.toString());
 				metadata.put(DataCiteProfile.CREATOR.toString(), sysMeta.getRightsHolder().getValue());
 				metadata.put(DataCiteProfile.PUBLISHER.toString(), node.getName());
-				metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), DateTimeMarshaller.serializeDateToUTC(sysMeta.getDateUploaded()));
+				metadata.put(DataCiteProfile.PUBLICATION_YEAR.toString(), year);
 				metadata.put(InternalProfile.TARGET.toString(), node.getBaseURL() + "/v1/object/" + identifier);
-				metadata.put(InternalProfile.PROFILE.toString(), "datacite");
 	
 				// set using the API
 				if (create) {
