1 package org.collectionspace.services.client.test;
3 import java.util.HashMap;
7 import javax.ws.rs.core.Response;
9 import org.collectionspace.services.client.AbstractCommonListUtils;
10 import org.collectionspace.services.client.AuthorityClient;
11 import org.collectionspace.services.client.AuthorityClientImpl;
12 import org.collectionspace.services.client.AuthorityProxy;
13 import org.collectionspace.services.client.CollectionSpaceClient;
14 import org.collectionspace.services.client.PayloadInputPart;
15 import org.collectionspace.services.client.PayloadOutputPart;
16 import org.collectionspace.services.client.PoxPayloadIn;
17 import org.collectionspace.services.client.PoxPayloadOut;
18 import org.collectionspace.services.client.XmlTools;
19 import org.collectionspace.services.jaxb.AbstractCommonList;
20 import org.dom4j.Document;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
30 * @param <AUTHORITY_COMMON_TYPE>
31 * @param <AUTHORITY_ITEM_TYPE>
33 * All CRUD related authority test classes should extend this class.
36 public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE>
37 extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
39 private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
41 protected String knownResourceShortIdentifer = null;
42 protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems" + random.nextInt(1000);
43 protected String knownAuthorityWithItems = null;
44 protected String knownAuthorityWithItemsIdentifier = null;
46 protected static final String SAS_IDENTIFIER = "SAS";
47 protected String knownSASAuthorityResourceId = null;
48 protected String knownSASAuthorityResourceIdentifier = null;
49 protected String knownSASItemResourceId = null;
50 protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
52 protected String knownResourceRefName = null;
53 protected String knownItemResourceId = null;
54 protected String knownItemResourceShortIdentifer = null;
55 protected int nItemsToCreateInList = 5;
56 protected String TEST_SHORTID = "johnWayneActor";
59 * Abstract methods that subclasses must override/implement
66 public abstract void authorityTests(String testName);
74 abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);
79 * @param authorityItem
82 protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);
90 protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception;
95 * @param shortIdentifer
97 protected void setKnownItemResource(String id, String shortIdentifer ) {
98 knownItemResourceId = id;
99 knownItemResourceShortIdentifer = shortIdentifer;
105 * @param shortIdentifer
108 protected void setKnownResource(String id, String shortIdentifer,
110 knownResourceId = id;
111 knownResourceShortIdentifer = shortIdentifer;
112 knownResourceRefName = refName;
119 protected String getSASAuthorityIdentifier() {
120 // TODO Auto-generated method stub
121 return this.getKnowResourceIdentifier() + SAS_IDENTIFIER;
129 protected String getUrnIdentifier(String shortId) {
130 return String.format("urn:cspace:name(%s)", shortId);
134 * Sets up create tests.
136 protected void setupSync() {
137 testExpectedStatusCode = this.STATUS_OK;
138 testRequestType = ServiceRequestType.SYNC;
139 testSetup(testExpectedStatusCode, testRequestType);
143 * Gets a client to the SAS (Shared Authority Server)
147 protected AuthorityClient getSASClientInstance() {
148 return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
152 * Returns the root URL for a service.
154 * This URL consists of a base URL for all services, followed by
155 * a path component for the owning vocabulary, followed by the
156 * path component for the items.
158 * @return The root URL for a service.
160 protected String getItemServiceRootURL(String parentResourceIdentifier) {
161 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
165 * Returns the URL of a specific resource managed by a service, and
166 * designated by an identifier (such as a universally unique ID, or UUID).
168 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
170 * @return The URL of a specific resource managed by a service.
172 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
173 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
177 * For authorities we override this method so we can save the shortid.
180 protected String createWithIdentifier(String testName, String identifier) throws Exception {
181 String csid = createResource(testName, identifier);
182 // Store the ID returned from the first resource created
183 // for additional tests below.
184 if (getKnowResourceId() == null) {
185 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
186 if (logger.isDebugEnabled()) {
187 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
194 @Test(dependsOnMethods = {"readItem", "CRUDTests"})
195 public void testItemSubmitRequest() {
197 // Expected status code: 200 OK
198 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
200 // Submit the request to the service and store the response.
201 String method = ServiceRequestType.READ.httpMethodName();
202 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
203 int statusCode = submitRequest(method, url);
205 // Check the status code of the response: does it match
206 // the expected response(s)?
207 if (logger.isDebugEnabled()) {
208 logger.debug("testItemSubmitRequest: url=" + url
209 + " status=" + statusCode);
211 Assert.assertEquals(statusCode, EXPECTED_STATUS);
215 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
216 dependsOnMethods = {"readItem"})
217 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
221 // Submit the request to the service and store the response.
222 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
223 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
224 Response res = client.readItem(knownResourceId, knownItemResourceId);
225 AUTHORITY_ITEM_TYPE vitem = null;
227 int statusCode = res.getStatus();
229 // Check the status code of the response: does it match
230 // the expected response(s)?
231 if (logger.isDebugEnabled()) {
232 logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
233 + knownItemResourceId + " status = " + statusCode);
235 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
236 invalidStatusCodeMessage(testRequestType, statusCode));
237 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
239 vitem = extractItemCommonPartValue(res);
240 Assert.assertNotNull(vitem);
241 // Try to Update with new parent vocab (use self, for test).
242 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
243 "VocabularyItem inAuthority does not match knownResourceId.");
244 client.setInAuthority(vitem, knownItemResourceId);
250 // Submit the updated resource to the service and store the response.
251 PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
252 res = client.updateItem(knownResourceId, knownItemResourceId, output);
254 int statusCode = res.getStatus();
256 // Check the status code of the response: does it match the expected response(s)?
257 if (logger.isDebugEnabled()) {
258 logger.debug(testName + ": status = " + statusCode);
260 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
261 invalidStatusCodeMessage(testRequestType, statusCode));
262 Assert.assertEquals(statusCode, testExpectedStatusCode);
267 res = client.readItem(knownResourceId, knownItemResourceId);
269 // Retrieve the updated resource and verify that the parent did not change
270 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
271 Assert.assertNotNull(updatedVocabularyItem);
273 // Verify that the updated resource received the correct data.
274 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
276 "VocabularyItem allowed update to the parent (inAuthority).");
282 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
283 public void createItem(String testName) {
287 String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId());
289 // Store the ID returned from the first item resource created
290 // for additional tests below.
291 if (knownItemResourceId == null) {
292 knownItemResourceId = newID;
293 if (null != testName && logger.isDebugEnabled()) {
294 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
300 * Sync the local with the SAS
302 @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
303 public void syncWithSAS(String testName) {
305 // First check to see if the authority supports synchronization.
307 AuthorityClient client = (AuthorityClient) this.getClientInstance();
308 if (client.supportsSync() == false) {
309 return; // Exit the test since this authority doesn't support synchronization
313 // Create an empty instance of the authority, so we can sync items with it. We're
314 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
316 String localAuthorityId = null;
318 localAuthorityId = createResource(client, testName, knownSASAuthorityResourceIdentifier, false);
319 } catch (Exception e) {
320 Assert.assertNotNull(localAuthorityId);
324 // Now we can try to sync the SAS authority with the local one we just created.
327 Response response = client.syncByName(knownSASAuthorityResourceIdentifier); // Notice we're using the Short ID (short ID is the same on the local and SAS)
329 int statusCode = response.getStatus();
330 if (logger.isDebugEnabled()) {
331 logger.debug(testName + ": HTTP status = " + statusCode);
333 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
334 invalidStatusCodeMessage(testRequestType, statusCode));
335 Assert.assertEquals(statusCode, testExpectedStatusCode);
342 * SAS - Create a new authority on the SAS server.
345 @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
346 public void createSASAuthority(String testName) {
348 // First check to see if the authority supports synchronization.
350 AuthorityClient client = (AuthorityClient) this.getClientInstance();
351 if (client.supportsSync() == false) {
352 return; // Exit the test since this authority doesn't support synchronization
359 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier(), true);
360 knownSASAuthorityResourceId = newID;
361 knownSASAuthorityResourceIdentifier = getShortId(getSASClientInstance(), knownSASAuthorityResourceId);
362 if (logger.isDebugEnabled()) {
363 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
365 } catch (Exception e) {
366 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
371 * SAS - Create an item in the SAS authority on the SAS server.
374 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
375 public void createSASItem(String testName) {
377 // First check to see if the authority supports synchronization.
379 AuthorityClient client = (AuthorityClient) this.getClientInstance();
380 if (client.supportsSync() == false) {
381 return; // Exit the test since this authority doesn't support synchronization
387 String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
388 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
390 // Store the ID returned from the first item resource created
391 // for additional tests below.
392 if (knownSASItemResourceId == null) {
393 knownSASItemResourceId = newID;
394 if (null != testName && logger.isDebugEnabled()) {
395 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
399 // Keep track of the SAS authority items we create, so we can delete them from
400 // the *local* authority after we perform a sync operation. We need to keep track
401 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
403 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
406 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
407 dependsOnMethods = {"createItem"})
408 public void createItemList(String testName) throws Exception {
409 knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
410 knownAuthorityWithItemsIdentifier = getShortId(knownAuthorityWithItems);
411 for (int j = 0; j < nItemsToCreateInList; j++) {
412 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
416 private String getShortId(AuthorityClient client, String authorityCsid) throws Exception {
417 String result = null;
419 // Submit the request to the service and store the response.
420 Response res = client.read(authorityCsid);
422 int statusCode = res.getStatus();
423 result = this.extractAuthorityShortId(res);
431 private String getShortId(String authorityCsid) throws Exception {
432 AuthorityClient client = (AuthorityClient) getClientInstance();
433 return getShortId(client, authorityCsid);
439 * @param testName the test name
440 * @throws Exception the exception
442 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
443 dependsOnMethods = {"CRUDTests"})
444 public void readByName(String testName) throws Exception {
448 // Submit the request to the service and store the response.
449 AuthorityClient client = (AuthorityClient) this.getClientInstance();
450 Response res = client.readByName(getKnowResourceIdentifier());
452 int statusCode = res.getStatus();
454 // Check the status code of the response: does it match
455 // the expected response(s)?
456 if (logger.isDebugEnabled()) {
457 logger.debug(testName + ": status = " + statusCode);
459 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
460 invalidStatusCodeMessage(testRequestType, statusCode));
461 Assert.assertEquals(statusCode, testExpectedStatusCode);
463 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
464 Assert.assertNotNull(commonPart);
471 * Extracts the common part item from a service's item payload.
477 public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
478 AUTHORITY_ITEM_TYPE result = null;
480 AuthorityClient client = (AuthorityClient) getClientInstance();
481 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
482 if (payloadInputPart != null) {
483 result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
485 Assert.assertNotNull(result,
486 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
492 * Extracts the short ID from a service request payload
498 public String extractAuthorityShortId(Response res) throws Exception {
499 String result = null;
501 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
502 Document document = input.getDOMDocument();
503 result = XmlTools.getElementValue(document, "//" + AuthorityClient.SHORT_IDENTIFIER);
509 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
510 dependsOnMethods = {"readItem"})
511 public void readItemNonExistent(String testName) {
513 setupReadNonExistent();
515 // Submit the request to the service and store the response.
516 AuthorityClient client = (AuthorityClient) getClientInstance();
517 Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
519 int statusCode = res.getStatus();
521 // Check the status code of the response: does it match
522 // the expected response(s)?
523 if (logger.isDebugEnabled()) {
524 logger.debug(testName + ": status = " + statusCode);
526 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
527 invalidStatusCodeMessage(testRequestType, statusCode));
528 Assert.assertEquals(statusCode, testExpectedStatusCode);
534 @Test(dataProvider = "testName",
535 dependsOnMethods = {"createItem"})
536 public void readItem(String testName) throws Exception {
540 // Submit the request to the service and store the response.
541 AuthorityClient client = (AuthorityClient) getClientInstance();
542 Response res = client.readItem(knownResourceId, knownItemResourceId);
544 int statusCode = res.getStatus();
546 // Check the status code of the response: does it match
547 // the expected response(s)?
548 if (logger.isDebugEnabled()) {
549 logger.debug(testName + ": status = " + statusCode);
551 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
552 invalidStatusCodeMessage(testRequestType, statusCode));
553 Assert.assertEquals(statusCode, testExpectedStatusCode);
555 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
556 Assert.assertNotNull(itemCommonPart);
557 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
558 verifyReadItemInstance(itemCommonPart);
564 protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
566 @Test(dataProvider = "testName",
567 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})
568 public void deleteItem(String testName) throws Exception {
572 // Submit the request to the service and store the response.
573 AuthorityClient client = (AuthorityClient) getClientInstance();
574 Response res = client.deleteItem(knownResourceId, knownItemResourceId);
577 statusCode = res.getStatus();
582 // Check the status code of the response: does it match
583 // the expected response(s)?
584 if (logger.isDebugEnabled()) {
585 logger.debug("delete: status = " + statusCode);
587 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(testRequestType, statusCode));
589 Assert.assertEquals(statusCode, testExpectedStatusCode);
592 protected void readItemListInt(String vcsid, String shortId, String testName) {
596 // Submit the request to the service and store the response.
597 AuthorityClient client = (AuthorityClient) getClientInstance();
600 res = client.readItemList(vcsid, null, null);
601 } else if (shortId != null) {
602 res = client.readItemListForNamedAuthority(shortId, null, null);
604 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
607 int statusCode = res.getStatus();
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if (logger.isDebugEnabled()) {
612 logger.debug(" " + testName + ": status = " + statusCode);
614 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(testRequestType, statusCode));
616 Assert.assertEquals(statusCode, testExpectedStatusCode);
618 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
619 List<AbstractCommonList.ListItem> items = list.getListItem();
620 int nItemsReturned = items.size();
621 long nItemsTotal = list.getTotalItems();
622 if (logger.isDebugEnabled()) {
623 logger.debug(" " + testName + ": Expected "
624 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
626 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
628 for (AbstractCommonList.ListItem item : items) {
629 String refName = AbstractCommonListUtils.ListItemGetElementValue(
630 item, AuthorityClient.REF_NAME);
631 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
632 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
633 AuthorityClient.TERM_DISPLAY_NAME);
634 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
635 AuthorityClient.VOCAB_DISPLAY_NAME);
636 // One of these names needs to be set.
637 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
640 if(logger.isTraceEnabled()){
641 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
648 @Test(dataProvider = "testName", dependsOnMethods = {"createItemList"})
649 public void readItemList(String testName) {
650 readItemListInt(knownAuthorityWithItems, null, testName);
653 @Test(dataProvider = "testName", dependsOnMethods = {"readItemList"})
654 public void readItemListByName(String testName) {
655 readItemListInt(null, knownAuthorityWithItemsIdentifier, testName);
658 @Test(dataProvider = "testName",
659 dependsOnMethods = {"deleteItem"})
660 public void deleteNonExistentItem(String testName) {
662 setupDeleteNonExistent();
664 // Submit the request to the service and store the response.
665 AuthorityClient client = (AuthorityClient) getClientInstance();
666 Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
669 statusCode = res.getStatus();
674 // Check the status code of the response: does it match
675 // the expected response(s)?
676 if (logger.isDebugEnabled()) {
677 logger.debug(testName + ": status = " + statusCode);
679 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
680 invalidStatusCodeMessage(testRequestType, statusCode));
681 Assert.assertEquals(statusCode, testExpectedStatusCode);
684 protected String getServicePathItemsComponent() {
685 return AuthorityClient.ITEMS;
688 public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
689 PoxPayloadOut result = null;
691 AuthorityClient client = (AuthorityClient) getClientInstance();
692 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
693 PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
700 * Update an Authority item.
705 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
706 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
707 public void updateItem(String testName) throws Exception {
710 AUTHORITY_ITEM_TYPE theUpdate = null;
712 // Retrieve the contents of a resource to update.
713 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
714 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
715 Response res = client.readItem(knownResourceId, knownItemResourceId);
717 if (logger.isDebugEnabled()) {
718 logger.debug(testName + ": read status = " + res.getStatus());
720 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
722 if (logger.isDebugEnabled()) {
723 logger.debug("got Authority item to update with ID: "
724 + knownItemResourceId
725 + " in authority: " + knownResourceId);
727 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
728 Assert.assertNotNull(authorityItem);
730 // Update the contents of this resource.
731 theUpdate = updateItemInstance(authorityItem);
732 if (logger.isDebugEnabled()) {
733 logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n"
734 + objectAsXmlString(theUpdate));
740 // Submit the updated resource to the service and store the response.
741 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
742 res = client.updateItem(knownResourceId, knownItemResourceId, output);
744 int statusCode = res.getStatus();
746 // Check the status code of the response: does it match the expected response(s)?
747 if (logger.isDebugEnabled()) {
748 logger.debug("updateItem: status = " + statusCode);
750 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
751 invalidStatusCodeMessage(testRequestType, statusCode));
752 Assert.assertEquals(statusCode, testExpectedStatusCode);
754 // Retrieve the updated resource and verify that its contents exist.
755 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
756 Assert.assertNotNull(updatedVocabularyItem);
758 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
764 protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
767 * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
769 @Test(dataProvider = "testName",
770 dependsOnMethods = {"create", "update", "updateNonExistent"})
771 public void updateNonExistentItem(String testName) throws Exception {
773 setupUpdateNonExistent();
775 // Submit the request to the service and store the response.
776 // Note: The ID used in this 'create' call may be arbitrary.
777 // The only relevant ID may be the one used in update(), below.
778 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
779 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
780 PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
781 Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
783 int statusCode = res.getStatus();
785 // Check the status code of the response: does it match
786 // the expected response(s)?
787 if (logger.isDebugEnabled()) {
788 logger.debug(testName + ": status = " + statusCode);
790 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
791 invalidStatusCodeMessage(testRequestType, statusCode));
792 Assert.assertEquals(statusCode, testExpectedStatusCode);
799 // Methods to persuade TestNG to follow the correct test dependency path
802 @Test(dataProvider = "testName",
803 dependsOnMethods = {"createItem"})
804 public void baseAuthorityTests(String testName) {
805 // Do nothing. Here just to setup a test dependency chain.
809 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
810 * refer to this method in their @Test annotation declarations.
813 @Test(dataProvider = "testName",
815 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
816 public void CRUDTests(String testName) {
817 // TODO Auto-generated method stub
821 public void cleanUp() {
822 String noTest = System.getProperty("noTestCleanup");
823 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
824 if (logger.isDebugEnabled()) {
825 logger.debug("Skipping Cleanup phase ...");
830 AuthorityClient client = (AuthorityClient) this.getClientInstance();
831 String parentResourceId;
832 String itemResourceId;
834 // Clean up all authority item resources.
836 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
837 itemResourceId = entry.getKey();
838 parentResourceId = entry.getValue();
839 Response response = client.deleteItem(parentResourceId, itemResourceId);
841 int status = response.getStatus();
842 if (status != Response.Status.OK.getStatusCode()) {
843 logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
844 itemResourceId, parentResourceId));
851 // Clean up authority items that were the result of a sync with the SAS
852 // all the IDs are URN (not CSIDs). The URNs work for the local items as well
855 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
856 itemResourceId = entry.getKey();
857 parentResourceId = entry.getValue();
858 // Note: Any non-success responses from the delete operation
859 // below are ignored and not reported.
860 client.deleteItem(parentResourceId, itemResourceId).close();
863 // Clean up authority items on the SAS using the SAS client.
865 client = (AuthorityClient) this.getSASClientInstance();
866 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
867 itemResourceId = entry.getKey();
868 parentResourceId = entry.getValue();
869 client.deleteItem(parentResourceId, itemResourceId).close();
872 // Finally, call out superclass's cleanUp method to deleted the local authorities
876 // Call out superclass's cleanUp method to delete the SAS authorities
878 super.cleanUp(client);
881 protected String getTestAuthorityItemShortId() {
882 return getTestAuthorityItemShortId(false);
885 protected String getTestAuthorityItemShortId(boolean makeUnique) {
886 String result = TEST_SHORTID;
888 if (makeUnique == true) {
889 result = result + System.currentTimeMillis() + Math.abs(random.nextInt());