From: Aron Roberts Date: Fri, 1 Oct 2010 23:05:28 +0000 (+0000) Subject: CSPACE-2969: refObjs tests to retrieve records that reference a specific term now... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=131180c01ae1b0d7254ffd52a88979a63663e464;p=tmp%2Fjakarta-migration.git CSPACE-2969: refObjs tests to retrieve records that reference a specific term now do more than just check status codes in responses. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java index 89e163f85..7a54b2e5b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameUtils.java @@ -59,7 +59,7 @@ public class RefNameUtils { private static final int INSTANCE_DISPLAYNAME_TOKEN = 2;// optional displayName suffix private static final int INSTANCE_TOKENS_MIN = 2; private static final int INSTANCE_TOKENS_MAX = 3; - private static final String SEPARATOR = ":"; + public static final String SEPARATOR = ":"; public static class AuthorityInfo { private final Logger logger = LoggerFactory.getLogger(AuthorityInfo.class); @@ -209,6 +209,37 @@ public class RefNameUtils { return sb.toString(); } } + + /* + * Returns the name / shortIdentifier value of an authority item in a refName + */ + public static String getItemShortId(String refName) { + String name = ""; + try { + String [] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR); + AuthorityTermInfo authTermInfo = new AuthorityTermInfo(refNameTokens); + name = authTermInfo.name; + } catch(Exception e) { + // do nothing + } + return name; + } + + /** + * Creates a refName in the name / shortIdentifier form. + * + * @param shortId a shortIdentifier for an authority or one of its terms + * @return a refName for that authority or term, in the name / shortIdentifier form. + * If the provided shortIdentifier is null or empty, returns + * the empty string. + */ + public static String createShortIdRefName(String shortId) { + if (shortId == null || shortId.trim().isEmpty()) { + return ""; + } else { + return "urn:cspace:name("+shortId+")"; + } + } } diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java index e3cd24446..5c7b636c0 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java @@ -71,6 +71,7 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { private List intakeIdsCreated = new ArrayList(); private List personIdsCreated = new ArrayList(); 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 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 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 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 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 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 // ---------------------------------------------------------------