LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
// Instance variables specific to this test.
- /** The SERVIC e_ pat h_ component. */
+ /** The service path component. */
final String SERVICE_PATH_COMPONENT = "personauthorities";
- /** The ITE m_ servic e_ pat h_ component. */
+ /** The item service path component. */
final String ITEM_SERVICE_PATH_COMPONENT = "items";
- /** The CONTAC t_ servic e_ pat h_ component. */
+ /** The contact service path component. */
final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
- /** The TES t_ for e_ name. */
+ /** The test forename. */
final String TEST_FORE_NAME = "John";
- /** The TES t_ middl e_ name. */
+ /** The test middle name. */
final String TEST_MIDDLE_NAME = null;
- /** The TES t_ su r_ name. */
+ /** The test surname. */
final String TEST_SUR_NAME = "Wayne";
- /** The TES t_ birt h_ date. */
+ /** The test birthdate. */
final String TEST_BIRTH_DATE = "May 26, 1907";
- /** The TES t_ deat h_ date. */
+ /** The test death date. */
final String TEST_DEATH_DATE = "June 11, 1979";
+
+ // Test name for partial term matching: Lech Walensa
+ final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
+ // Contains two non-USASCII range Unicode UTF-8 characters
+ final String TEST_PARTIAL_TERM_SUR_NAME = "Wa" + "\u0142" + "\u0119" + "sa";
+ final String TEST_PARTIAL_TERM_DISPLAY_NAME =
+ TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME;
/** The known resource id. */
private String knownResourceId = null;
/** The known item resource id. */
private String knownItemResourceId = null;
+
+ // The resource ID of an item resource used for partial term matching tests.
+ private String knownItemPartialTermResourceId = null;
/** The known contact resource id. */
private String knownContactResourceId = null;
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- String identifier = createIdentifier();
String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
Map<String, String> johnWayneMap = new HashMap<String,String>();
//
return newID;
}
+
+ /**
+ * Creates an item in the authority, used for partial term matching tests.
+ *
+ * @param vcsid the vcsid
+ * @param authRefName the auth ref name
+ * @return the string
+ */
+ private String createItemInAuthorityForPartialTermMatch(String vcsid, String authRefName) {
+
+ final String testName = "createItemInAuthorityForPartialTermMatch";
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ":...");
+ }
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ PersonAuthorityClient client = new PersonAuthorityClient();
+ String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName,
+ TEST_PARTIAL_TERM_DISPLAY_NAME, true);
+ Map<String, String> partialTermPersonMap = new HashMap<String,String>();
+ //
+ // Fill the property map
+ //
+ partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
+ partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
+ partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
+ partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
+ partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
+ MultipartOutput multipart =
+ PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, partialTermPersonMap,
+ client.getItemCommonPartName() );
+
+ String newID = null;
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ newID = PersonAuthorityClientUtils.extractId(res);
+ } finally {
+ res.releaseConnection();
+ }
+
+ // Store the ID returned from the first item resource created
+ // for additional tests below.
+ if (knownItemResourceId == null){
+ knownItemResourceId = newID;
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
+ }
+ }
+
+ // Store the IDs from any item resources created
+ // by tests, along with the IDs of their parents, so these items
+ // can be deleted after all tests have been run.
+ allItemResourceIdsCreated.put(newID, vcsid);
+
+ return newID;
+ }
/**
* Creates the contact.
}
// Failure outcomes
- // None at present.
+
+ // There are no failure outcome tests at present.
+
+ // ---------------------------------------------------------------
+ // CRUD tests : READ_LIST tests by partial term match.
+ // ---------------------------------------------------------------
+
+ // Success outcomes
+
+ /**
+ * Read item list by partial term.
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByPartialTerm"}, dependsOnGroups = {"readList"})
+ public void readItemListByPartialTerm(String testName) {
+ int numMatchesFound = 0;
+ final String PARTIAL_TERM = TEST_PARTIAL_TERM_FORE_NAME;
+ // setupCreate(testName);
+ String newID = createItemInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
+ numMatchesFound =
+ readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM);
+ final int NUM_MATCHES_EXPECTED = 1;
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+ }
+
+ /**
+ * Read item list by partial term, where the case of at
+ * least one character of the partial term doesn't match that
+ * of the full term expected to be matched.
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+ public void readItemListByPartialTermNonMatchingCase(String testName) {
+
+ setupReadList(testName);
+ int numMatchesFound = 0;
+ final int NUM_MATCHES_EXPECTED = 1;
+
+ final String PARTIAL_TERM_LOWERCASE = TEST_PARTIAL_TERM_FORE_NAME.toLowerCase();
+ numMatchesFound =
+ readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_LOWERCASE);
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+ final String PARTIAL_TERM_UPPERCASE = TEST_PARTIAL_TERM_FORE_NAME.toUpperCase();
+ numMatchesFound =
+ readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UPPERCASE);
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+ }
+
+ /**
+ * Read item list by partial term, with at least one Unicode UTF-8 character
+ * (outside the USASCII range) in the partial term.
+ */
+ // FIXME: Test currently fails with a true UTF-8 String - need to investigate why.
+ // Will be commented out for now until we get this working ...
+/*
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+ public void readItemListByPartialTermUTF8(String testName) {
+ int numMatchesFound = 0;
+ final String PARTIAL_TERM_UTF8 = TEST_PARTIAL_TERM_SUR_NAME;
+ if (logger.isDebugEnabled()) {
+ logger.debug("Attempting match on partial term '" + PARTIAL_TERM_UTF8 + "' ...");
+ }
+ numMatchesFound =
+ readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UTF8);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found " + numMatchesFound + " match(es).");
+ }
+ final int NUM_MATCHES_EXPECTED = 1;
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+ }
+*/
+
+ // Failure outcomes
+
+ /**
+ * Read item list by partial term, where the partial term is not
+ * expected to be matched by any term in any resource.
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+ public void readItemListByNonexistentPartialTerm(String testName) {
+ int numMatchesFound = 0;
+ final String NON_EXISTENT_PARTIAL_TERM = "jlmbsoq";
+ numMatchesFound =
+ readItemListByPartialTerm(testName, knownResourceId, NON_EXISTENT_PARTIAL_TERM);
+ final int NUM_MATCHES_EXPECTED = 0;
+ Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+ }
+
+
+ /**
+ * Read item list by partial term.
+ *
+ * @param testName The name of the test which has invoked this method.
+ * @param vcsid The CSID of the authority within which partial term matching
+ * will be performed.
+ * @param partialTerm A partial term to match item resources.
+ * @return The number of item resources matched by the partial term.
+ */
+ private int readItemListByPartialTerm(String testName, String vcsid, String partialTerm) {
+
+ // Perform setup.
+ setupReadList(testName);
+
+ // Submit the request to the service and store the response.
+ PersonAuthorityClient client = new PersonAuthorityClient();
+ ClientResponse<PersonsCommonList> res = null;
+ if (vcsid != null) {
+ res = client.readItemList(vcsid, partialTerm);
+ } else {
+ Assert.fail("readItemListByPartialTerm passed null csid!");
+ }
+ PersonsCommonList list = null;
+ try {
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ list = res.getEntity();
+ } finally {
+ res.releaseConnection();
+ }
+
+ List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
+ int nItemsReturned = items.size();
+
+ return nItemsReturned;
+ }
// ---------------------------------------------------------------
// CRUD tests : UPDATE tests
*/
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"update"}, dependsOnGroups = {"read", "readList"})
+ groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
public void update(String testName) throws Exception {
// Perform setup.
* @throws Exception the exception
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
+ groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
public void deleteContact(String testName) throws Exception {
// Perform setup.