]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2969: refObjs tests to retrieve records that reference a specific term now...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 1 Oct 2010 23:05:28 +0000 (23:05 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 1 Oct 2010 23:05:28 +0000 (23:05 +0000)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java

index 89e163f8536ebdf23928afd99533207c2cc139ac..7a54b2e5bf63a3c38f9ce53c65efc3113e9f8973 100644 (file)
@@ -59,7 +59,7 @@ public class RefNameUtils {
     private static final int INSTANCE_DISPLAYNAME_TOKEN = 2;// optional displayName suffix\r
     private static final int INSTANCE_TOKENS_MIN = 2;\r
     private static final int INSTANCE_TOKENS_MAX = 3;\r
-    private static final String SEPARATOR = ":";\r
+    public static final String SEPARATOR = ":";\r
 \r
     public static class AuthorityInfo {\r
         private final Logger logger = LoggerFactory.getLogger(AuthorityInfo.class);\r
@@ -209,6 +209,37 @@ public class RefNameUtils {
                return sb.toString();\r
        }\r
     }\r
+\r
+    /*\r
+     * Returns the name / shortIdentifier value of an authority item in a refName\r
+     */\r
+    public static String getItemShortId(String refName) {\r
+        String name = "";\r
+        try {\r
+            String [] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR);\r
+            AuthorityTermInfo authTermInfo = new AuthorityTermInfo(refNameTokens);\r
+            name = authTermInfo.name;\r
+        } catch(Exception e) {\r
+            // do nothing\r
+        }\r
+        return name;\r
+    }\r
+\r
+    /**\r
+     * Creates a refName in the name / shortIdentifier form.\r
+     *\r
+     * @param shortId a shortIdentifier for an authority or one of its terms\r
+     * @return a refName for that authority or term, in the name / shortIdentifier form.\r
+     *         If the provided shortIdentifier is null or empty, returns\r
+     *         the empty string.\r
+     */\r
+    public static String createShortIdRefName(String shortId) {\r
+        if (shortId == null || shortId.trim().isEmpty()) {\r
+            return "";\r
+        } else {\r
+            return "urn:cspace:name("+shortId+")";\r
+        }\r
+    }\r
     \r
 }\r
 \r
index e3cd24446a76f6ad0054e59de8a5f10d1cbcab4f..5c7b636c04e5770ff1417e8755e0e5884228a669 100644 (file)
@@ -71,6 +71,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
     private List<String> intakeIdsCreated = new ArrayList<String>();
     private List<String> personIdsCreated = new ArrayList<String>();
     private String personAuthCSID = null;
+    private String personShortId = PERSON_AUTHORITY_NAME;
     private String currentOwnerPersonCSID = null;
     private String depositorPersonCSID = null;
     private String insurerPersonCSID = null;
@@ -79,6 +80,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
     private String conditionCheckerAssessorRefName = null;
     private String insurerRefName = null;
     private String valuerRefName = null;
+    private String valuerShortId = null;
     private final int NUM_AUTH_REF_DOCS_EXPECTED = 1;
 
     /* (non-Javadoc)
@@ -207,6 +209,9 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         csid = createPerson("Vince", "Valuer", "vinceValuer", authRefName);
         Assert.assertNotNull(csid);
         valuerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+        if (logger.isDebugEnabled()) {
+            logger.debug("valuerShortId=" + valuerShortId);
+        }
         Assert.assertNotNull(valuerRefName);
         personIdsCreated.add(csid);
 
@@ -255,14 +260,17 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
         AuthorityRefDocList list = refDocListResp.getEntity();
+        List<AuthorityRefDocList.AuthorityRefDocItem> items =
+                list.getAuthorityRefDocItem();
+        Assert.assertTrue(items != null);
+        Assert.assertTrue(items.size() > 0);
 
         // Optionally output additional data about list members for debugging.
         boolean iterateThroughList = true;
         boolean fFoundIntake = false;
         if (iterateThroughList && logger.isDebugEnabled()) {
-            List<AuthorityRefDocList.AuthorityRefDocItem> items =
-                    list.getAuthorityRefDocItem();
             int i = 0;
             logger.debug(testName + ": Docs that use: " + currentOwnerRefName);
             for (AuthorityRefDocList.AuthorityRefDocItem item : items) {
@@ -292,14 +300,17 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-        list = refDocListResp.getEntity();
 
+        list = refDocListResp.getEntity();
+        items = list.getAuthorityRefDocItem();
+        Assert.assertTrue(items != null);
+        Assert.assertTrue(items.size() > 0);
+        Assert.assertTrue(items.get(0) != null);
+        
         // Optionally output additional data about list members for debugging.
         iterateThroughList = true;
         fFoundIntake = false;
         if (iterateThroughList && logger.isDebugEnabled()) {
-            List<AuthorityRefDocList.AuthorityRefDocItem> items =
-                    list.getAuthorityRefDocItem();
             int i = 0;
             logger.debug(testName + ": Docs that use: " + depositorRefName);
             for (AuthorityRefDocList.AuthorityRefDocItem item : items) {
@@ -347,14 +358,18 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
         AuthorityRefDocList list = refDocListResp.getEntity();
+        List<AuthorityRefDocList.AuthorityRefDocItem> items =
+                list.getAuthorityRefDocItem();
+        Assert.assertTrue(items != null);
+        Assert.assertTrue(items.size() > 0);
+        Assert.assertTrue(items.get(0) != null);
 
         // Optionally output additional data about list members for debugging.
         boolean iterateThroughList = true;
         boolean fFoundIntake = false;
         if (iterateThroughList && logger.isDebugEnabled()) {
-            List<AuthorityRefDocList.AuthorityRefDocItem> items =
-                    list.getAuthorityRefDocItem();
             int i = 0;
             logger.debug(testName + ": Docs that use: " + insurerRefName);
             for (AuthorityRefDocList.AuthorityRefDocItem item : items) {
@@ -373,6 +388,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest {
         }
     }
 
+
     // ---------------------------------------------------------------
     // Cleanup of resources created during testing
     // ---------------------------------------------------------------