]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
de18d234c7eabec58b526befdc59dbc2b32986af
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.client.test;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import javax.ws.rs.core.Response;
9 import org.apache.http.HttpStatus;
10
11 import org.collectionspace.services.client.AbstractCommonListUtils;
12 import org.collectionspace.services.client.AuthorityClient;
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.RelationClient;
19 import org.collectionspace.services.client.XmlTools;
20 import org.collectionspace.services.client.workflow.WorkflowClient;
21 import org.collectionspace.services.description.ServiceDescription;
22 import org.collectionspace.services.jaxb.AbstractCommonList;
23 import org.collectionspace.services.relation.RelationsCommon;
24 import org.collectionspace.services.relation.RelationshipType;
25
26 import org.dom4j.Document;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.testng.Assert;
30 import org.testng.annotations.Test;
31
32 /**
33  * 
34  * @author remillet
35  *
36  * @param <AUTHORITY_COMMON_TYPE>
37  * @param <AUTHORITY_ITEM_TYPE>
38  * 
39  * All CRUD related authority test classes should extend this class.
40  * 
41  */
42 public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE> 
43         extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
44
45     private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
46         
47     protected String knownResourceShortIdentifer = null;
48         protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems" + random.nextInt(1000); 
49         protected String knownAuthorityWithItems = null;
50         protected String knownAuthorityWithItemsIdentifier = null;
51         
52         protected static final String SAS_IDENTIFIER = "SAS";
53         protected static final String SAS_WITH_RELATIONS = "_RELATIONS_"; 
54
55         private static final int SAS_ITEMLIST_SIZE = 5;
56
57         protected String knownSASAuthorityResourceId = null;
58         protected String knownSASAuthorityResourceShortId = null;
59         protected List<String> knownSASItemIdentifiersList = new ArrayList<String>();
60         protected String knownSASItemResourceId = null;
61         protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
62
63         protected String knownResourceRefName = null;
64     protected String knownItemResourceId = null;
65     protected String knownItemResourceShortIdentifer = null;    
66     protected int nItemsToCreateInList = 5;
67     protected String TEST_SHORTID = "johnWayneActor";
68
69         protected String knownSASAuthorityResourceWithRelationsId = null;
70         protected String knownSASAuthorityResourceWithRelationsShortId = null;
71
72     /*
73      * Abstract methods that subclasses must override/implement
74      */
75     
76     /**
77      * 
78      * @param testName
79      */
80     public abstract void authorityTests(String testName);
81         
82         /**
83          * 
84          * @param client
85          * @param vcsid
86          * @return
87          */
88         abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);
89         
90     
91     /**
92      * 
93      * @param authorityItem
94      * @return
95      */
96     protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);    
97     
98     /**
99      * 
100      * @param original
101      * @param updated
102      * @throws Exception
103      */
104     protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
105                 AUTHORITY_ITEM_TYPE updated,
106                 boolean compareRevNumbers) throws Exception;
107     
108     /**
109      * 
110      * @param original
111      * @param updated
112      * @throws Exception
113      */
114     protected void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
115                 AUTHORITY_ITEM_TYPE updated) throws Exception {
116         compareUpdatedItemInstances(original, updated, false);
117     }
118     
119     /**
120      * 
121      * @param id
122      * @param shortIdentifer
123      */
124     protected void setKnownItemResource(String id, String shortIdentifer ) {
125         knownItemResourceId = id;
126         knownItemResourceShortIdentifer = shortIdentifer;
127     }
128
129     /**
130      * 
131      * @param id
132      * @param shortIdentifer
133      * @param refName
134      */
135     protected void setKnownResource(String id, String shortIdentifer,
136             String refName) {
137         knownResourceId = id;
138         knownResourceShortIdentifer = shortIdentifer;
139         knownResourceRefName = refName;
140     }
141
142     /**
143      * 
144      * @return
145      */
146         protected String getSASAuthorityIdentifier() {
147                 return this.getKnowResourceIdentifier() + SAS_IDENTIFIER;
148         }
149     
150     /**
151      * 
152      * @return
153      */
154         protected String getSASAuthorityWithRelationsIdentifier() {
155                 return this.getKnowResourceIdentifier() + SAS_WITH_RELATIONS + SAS_IDENTIFIER;
156         }
157     
158         /**
159          * 
160          * @param shortId
161          * @return
162          */
163         protected String getUrnIdentifier(String shortId) {
164                 return String.format("urn:cspace:name(%s)", shortId);
165         }
166         
167     /**
168      * Sets up create tests.
169      */
170     protected void setupSync() {
171         testExpectedStatusCode = this.STATUS_OK;
172         testRequestType = ServiceRequestType.SYNC;
173         testSetup(testExpectedStatusCode, testRequestType);
174     }
175     
176     /**
177      * Gets a client to the SAS (Shared Authority Server)
178      *
179      * @return the client
180      */
181     protected AuthorityClient getSASClientInstance() {
182         return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
183     }
184
185     /**
186      * Returns the root URL for a service.
187      *
188      * This URL consists of a base URL for all services, followed by
189      * a path component for the owning vocabulary, followed by the 
190      * path component for the items.
191      *
192      * @return The root URL for a service.
193      */
194     protected String getItemServiceRootURL(String parentResourceIdentifier) {
195         return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
196     }
197
198     /**
199      * Returns the URL of a specific resource managed by a service, and
200      * designated by an identifier (such as a universally unique ID, or UUID).
201      *
202      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
203      *
204      * @return The URL of a specific resource managed by a service.
205      */
206     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
207         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
208     }
209         
210     /**
211      * For authorities we override this method so we can save the shortid.
212      */
213     @Override
214     protected String createWithIdentifier(String testName, String identifier) throws Exception {
215         String csid = createResource(testName, identifier);
216         // Store the ID returned from the first resource created
217         // for additional tests below.
218         if (getKnowResourceId() == null) {
219                 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
220             if (logger.isDebugEnabled()) {
221                 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
222             }
223         }
224         
225         return identifier;
226     }    
227     
228     @Test(dependsOnMethods = {"readItem", "CRUDTests"})
229     public void testItemSubmitRequest() {
230
231         // Expected status code: 200 OK
232         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
233
234         // Submit the request to the service and store the response.
235         String method = ServiceRequestType.READ.httpMethodName();
236         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
237         int statusCode = submitRequest(method, url);
238
239         // Check the status code of the response: does it match
240         // the expected response(s)?
241         if (logger.isDebugEnabled()) {
242             logger.debug("testItemSubmitRequest: url=" + url
243                     + " status=" + statusCode);
244         }
245         Assert.assertEquals(statusCode, EXPECTED_STATUS);
246     }    
247
248     
249     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
250         dependsOnMethods = {"readItem"})
251     public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
252         // Perform setup.
253         setupUpdate();
254
255         // Submit the request to the service and store the response.
256         AuthorityClient client = (AuthorityClient)this.getClientInstance();
257         Response res = client.readItem(knownResourceId, knownItemResourceId);
258         AUTHORITY_ITEM_TYPE vitem = null;
259         try {
260                 int statusCode = res.getStatus();
261         
262                 // Check the status code of the response: does it match
263                 // the expected response(s)?
264                 if (logger.isDebugEnabled()) {
265                         logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
266                                         + knownItemResourceId + " status = " + statusCode);
267                 }
268                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
269                                 invalidStatusCodeMessage(testRequestType, statusCode));
270                 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
271         
272                 vitem = extractItemCommonPartValue(res);
273                 Assert.assertNotNull(vitem);
274                 // Try to Update with new parent vocab (use self, for test).
275                 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
276                                 "VocabularyItem inAuthority does not match knownResourceId.");
277                 client.setInAuthority(vitem, knownItemResourceId);
278
279         } finally {
280                 res.close();
281         }
282         
283         // Submit the updated resource to the service and store the response.
284         PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
285         res = client.updateItem(knownResourceId, knownItemResourceId, output);
286         try {
287                 int statusCode = res.getStatus();
288         
289                 // Check the status code of the response: does it match the expected response(s)?
290                 if (logger.isDebugEnabled()) {
291                         logger.debug(testName + ": status = " + statusCode);
292                 }
293                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
294                                 invalidStatusCodeMessage(testRequestType, statusCode));
295                 Assert.assertEquals(statusCode, testExpectedStatusCode);
296         } finally {
297                 res.close();
298         }
299         
300         res = client.readItem(knownResourceId, knownItemResourceId);
301         try {
302                 // Retrieve the updated resource and verify that the parent did not change
303                 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
304                 Assert.assertNotNull(updatedVocabularyItem);
305         
306                 // Verify that the updated resource received the correct data.
307                 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
308                                 knownResourceId,
309                                 "VocabularyItem allowed update to the parent (inAuthority).");
310         } finally {
311                 res.close();
312         }
313     }
314     
315     @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
316     public void createItem(String testName) {
317         // Perform setup.
318         setupCreate();
319
320         String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId());
321
322         // Store the ID returned from the first item resource created
323         // for additional tests below.
324         if (knownItemResourceId == null) {
325             knownItemResourceId = newID;
326             if (null != testName && logger.isDebugEnabled()) {
327                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
328             }
329         }
330     }
331         
332     /**
333      * Sync the local with the SAS
334      * @throws Exception 
335      */
336     @Test(dataProvider = "testName", dependsOnMethods = {"createSASItemList", "CRUDTests"})
337     public void syncWithSAS(String testName) throws Exception {
338         //
339         // First check to see if the authority supports synchronization.
340         //
341         AuthorityClient client = (AuthorityClient) this.getClientInstance();
342         if (client.supportsSync() == false) {
343                 return; // Exit the test since this authority doesn't support synchronization
344         }
345         
346         //
347         // Create an empty instance of the authority, so we can sync items with it.  We're
348         // using the short ID of the SAS authority.  The short ID of the local and the SAS will (must) be the same.
349         //
350         String localAuthorityId = null;
351         try {
352                         localAuthorityId = createResource(client, testName, knownSASAuthorityResourceShortId, false);
353                 } catch (Exception e) {
354                         Assert.assertNotNull(localAuthorityId);
355                 }
356
357         //
358         // Now we can try to sync the SAS authority with the local one we just created.
359         //
360         setupSync();
361         Response response = client.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
362         try {
363                 int statusCode = response.getStatus();
364                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
365                         invalidStatusCodeMessage(testRequestType, statusCode));
366                 Assert.assertEquals(statusCode, testExpectedStatusCode);
367         } finally {
368                 response.close();
369         }
370         
371         //
372         // Check to see if the parent authority (local) is in the "Replicated" state.
373         //
374         setupRead();
375         response = client.readByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
376         try {
377                 int statusCode = response.getStatus();
378                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
379                         invalidStatusCodeMessage(testRequestType, statusCode));
380                 Assert.assertEquals(statusCode, testExpectedStatusCode);
381                         String workflowState = this.extractAuthorityWorkflowState(response);
382                         Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED));  // After a sync, the parent should be in the "Replicated" state
383         } finally {
384                 response.close();
385         }        
386         
387     }
388     
389     /**
390      * Check to make sure the sync with the SAS returned the correct number of items as well as items
391      * with the correct short IDs.
392      * 
393      */
394     @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSAS", "CRUDTests"})
395     public void veryifySyncWithSAS(String testName) {
396         //
397         // First check to see if we support sync.
398         //
399         AuthorityClient client = (AuthorityClient) getClientInstance();
400         if (client.supportsSync() == false) {
401                 return; // Exit the test since this authority doesn't support synchronization
402         }        
403
404         // Perform setup.
405         setupReadList();
406
407         // Submit the request to the service and store the response.
408         Response res = null;
409         res = client.readItemListForNamedAuthority(knownSASAuthorityResourceShortId, null, null);
410
411         try {
412                 int statusCode = res.getStatus();
413         
414                 // Check the status code of the response: does it match
415                 // the expected response(s)?
416                 if (logger.isDebugEnabled()) {
417                     logger.debug("  " + testName + ": status = " + statusCode);
418                 }
419                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
420                         invalidStatusCodeMessage(testRequestType, statusCode));
421                 Assert.assertEquals(statusCode, testExpectedStatusCode);
422         
423                 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
424                 List<AbstractCommonList.ListItem> items = list.getListItem();
425                 int nItemsReturned = items.size();
426                 long nItemsTotal = list.getTotalItems();
427                 if (logger.isDebugEnabled()) {
428                     logger.debug("  " + testName + ": Expected "
429                             + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
430                 }
431                 Assert.assertEquals(nItemsTotal, SAS_ITEMLIST_SIZE);
432                 //
433                 // Verify that each of our local items has a corresponding remote item
434                 //
435                         for (AbstractCommonList.ListItem item : items) {
436                                 String shortId = AbstractCommonListUtils.ListItemGetElementValue(
437                                                 item, AuthorityClient.SHORT_IDENTIFIER);
438                                 Assert.assertTrue(knownSASItemIdentifiersList.contains(shortId)); // The local short ID should be in SAS list
439                                 
440                                 String workflowState = AbstractCommonListUtils.ListItemGetElementValue(
441                                                 item, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
442                                 Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // Workflow state must show up in a "replicated" state
443                                 
444                                 String refName = AbstractCommonListUtils.ListItemGetElementValue(
445                                                 item, AuthorityClient.REF_NAME);
446                                 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
447                                 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
448                                                 AuthorityClient.TERM_DISPLAY_NAME);
449                                 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
450                                                 AuthorityClient.VOCAB_DISPLAY_NAME);
451                                 // One of these names needs to be set.
452                                 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
453                         }
454                 
455                 if(logger.isTraceEnabled()){
456                         AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
457                 }
458         } finally {
459                 res.close();
460         }
461     }
462         
463     /**
464      * SAS - Create a new authority on the SAS server.
465      * @param testName
466      */    
467     @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
468     public void createSASAuthority(String testName) {
469         //
470         // First check to see if the authority supports synchronization.
471         //
472         AuthorityClient client = (AuthorityClient) this.getClientInstance();
473         if (client.supportsSync() == false) {
474                 return; // Exit the test since this authority doesn't support synchronization
475         }
476         
477         // Perform setup.
478         setupCreate();
479
480         try {
481                 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier(), true);
482                 knownSASAuthorityResourceId = newID;
483                 knownSASAuthorityResourceShortId = getShortId(getSASClientInstance(), knownSASAuthorityResourceId);
484             if (logger.isDebugEnabled()) {
485                 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
486             }
487         } catch (Exception e) {
488                 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
489         }
490     }
491     
492     @Test(dataProvider = "testName", dependsOnMethods = {"deleteLocalItemWithSync", "CRUDTests"})
493     public void createSASAuthorityWithRelations(String testName) {
494         //
495         // First check to see if the authority supports synchronization.
496         //
497         AuthorityClient client = (AuthorityClient) getClientInstance();
498         if (client.supportsSync() == false) {
499                 return; // Exit the test since this authority doesn't support synchronization
500         }
501         
502         // Perform setup.
503         setupCreate();
504         //
505         // Create a new authority on the remote server
506         //
507         try {
508                 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityWithRelationsIdentifier(), true);
509                 knownSASAuthorityResourceWithRelationsId = newID;
510                 knownSASAuthorityResourceWithRelationsShortId = getShortId(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId);
511         } catch (Exception e) {
512                 logger.info(String.format("Failed to create SAS authority with relations '%s'.", getSASAuthorityWithRelationsIdentifier()));
513         }
514         //
515         // Add three items to the remote authority
516         //
517         String continentShortId = "Continent" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
518         String continentCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, continentShortId);
519         this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(continentShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
520         
521         String countryShortId = "Country" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
522         String countryCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, countryShortId);
523         this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(countryShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
524
525         String cityShortId = "City" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
526         String cityCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, cityShortId);
527         this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(cityShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
528         //
529         // Create a set of hierarchical relationships between the items
530         //
531         ServiceDescription serviceDescription = client.getServiceDescription();
532         final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
533         
534         RelationsCommon relationCommon = new RelationsCommon();
535         relationCommon.setSubjectCsid(countryCSID);
536         relationCommon.setSubjectDocumentType(authorityItemDocumentType);
537         relationCommon.setObjectCsid(continentCSID);
538         relationCommon.setObjectDocumentType(authorityItemDocumentType);
539         relationCommon.setRelationshipType(RelationshipType.HAS_BROADER.value());
540         relationCommon.setPredicateDisplayName(RelationshipType.HAS_BROADER.value());
541         
542         RelationClient relationClient = new RelationClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); // Get a Relation service client to the SAS
543         PoxPayloadOut payloadOut = relationClient.createRequestTypeInstance(relationCommon);
544         Response res = relationClient.create(payloadOut);
545         if (res.getStatus() != HttpStatus.SC_CREATED) {
546                 logger.error("Could not create Relationship.");
547         }
548
549 }
550
551     /**
552      * SAS - Create an item in the SAS authority on the SAS server.
553      * @param testName
554      */
555     @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
556     public void createSASItemList(String testName) {
557         //
558         // First check to see if the authority supports synchronization.
559         //
560         AuthorityClient client = (AuthorityClient) this.getClientInstance();
561         if (client.supportsSync() == false) {
562                 return; // Exit the test since this authority doesn't support synchronization
563         }
564         
565         // Perform setup.
566         setupCreate();
567
568         for (int i = 0; i < SAS_ITEMLIST_SIZE; i++) {
569                 String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
570                 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
571         
572                         // Store the ID returned from the first item resource created
573                 // for additional tests below.
574                 if (knownSASItemResourceId == null) {
575                         knownSASItemResourceId = newID;
576                     if (null != testName && logger.isDebugEnabled()) {
577                         logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
578                     }
579                 }
580                 
581                 knownSASItemIdentifiersList.add(shortId);
582
583                 //
584                 // Keep track of the SAS authority items we create, so we can delete them from
585                 // the *local* authority after we perform a sync operation.  We need to keep track
586                 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
587                 //
588                 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(knownSASAuthorityResourceShortId));
589         }
590         
591     }
592     
593     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
594                 dependsOnMethods = {"createItem"})
595     public void createItemList(String testName) throws Exception {
596         knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
597         knownAuthorityWithItemsIdentifier = getShortId(knownAuthorityWithItems);
598         for (int j = 0; j < nItemsToCreateInList; j++) {
599                 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
600         }
601     }
602     
603     private String getShortId(AuthorityClient client, String authorityCsid) throws Exception {
604         String result = null;
605         
606         // Submit the request to the service and store the response.
607         Response res = client.read(authorityCsid);
608         try {
609                 int statusCode = res.getStatus();
610                 result = this.extractAuthorityShortId(res);
611         } finally {
612                 res.close();
613         }
614         
615         return result;
616     }
617     
618     private String getShortId(String authorityCsid) throws Exception {
619         AuthorityClient client = (AuthorityClient) getClientInstance();
620         return getShortId(client, authorityCsid);
621     }
622
623     /**
624      * Read by name.
625      *
626      * @param testName the test name
627      * @throws Exception the exception
628      */
629     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
630                 dependsOnMethods = {"CRUDTests"})
631     public void readByName(String testName) throws Exception {
632         // Perform setup.
633         setupRead();
634
635         // Submit the request to the service and store the response.
636         AuthorityClient client = (AuthorityClient) this.getClientInstance();
637         Response res = client.readByName(getKnowResourceIdentifier());
638         try {
639                 int statusCode = res.getStatus();
640         
641                 // Check the status code of the response: does it match
642                 // the expected response(s)?
643                 if (logger.isDebugEnabled()) {
644                     logger.debug(testName + ": status = " + statusCode);
645                 }
646                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
647                         invalidStatusCodeMessage(testRequestType, statusCode));
648                 Assert.assertEquals(statusCode, testExpectedStatusCode);
649                 
650                 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
651                 Assert.assertNotNull(commonPart);
652         } finally {
653                 res.close();
654         }
655     }
656     
657     /**
658      * Extracts the common part item from a service's item payload.
659      * 
660      * @param res
661      * @return
662      * @throws Exception
663      */
664         public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
665                 AUTHORITY_ITEM_TYPE result = null;
666                 
667         AuthorityClient client = (AuthorityClient) getClientInstance();
668                 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
669                 if (payloadInputPart != null) {
670                         result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
671                 }
672                 Assert.assertNotNull(result,
673                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
674                 
675                 return result;
676         }
677                 
678         
679     /**
680      * Extracts the short ID from a service request payload
681      * 
682      * @param res
683      * @return
684      * @throws Exception
685      */
686         protected String extractAuthorityShortId(Response res) throws Exception {
687                 String result = null;
688                 
689         PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));         
690                 Document document = input.getDOMDocument();
691                 result = XmlTools.getElementValue(document, "//" + AuthorityClient.SHORT_IDENTIFIER);
692
693                 return result;
694         }    
695         
696     
697     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
698                 dependsOnMethods = {"readItem"})
699     public void readItemNonExistent(String testName) {
700         // Perform setup.
701         setupReadNonExistent();
702
703         // Submit the request to the service and store the response.
704         AuthorityClient client = (AuthorityClient) getClientInstance();
705         Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
706         try {
707                 int statusCode = res.getStatus();
708         
709                 // Check the status code of the response: does it match
710                 // the expected response(s)?
711                 if (logger.isDebugEnabled()) {
712                     logger.debug(testName + ": status = " + statusCode);
713                 }
714                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
715                         invalidStatusCodeMessage(testRequestType, statusCode));
716                 Assert.assertEquals(statusCode, testExpectedStatusCode);
717         } finally {
718                 res.close();
719         }
720     }
721         
722     @Test(dataProvider = "testName",
723                 dependsOnMethods = {"createItem"})
724     public void readItem(String testName) throws Exception {
725         // Perform setup.
726         setupRead();
727
728         // Submit the request to the service and store the response.
729         AuthorityClient client = (AuthorityClient) getClientInstance();
730         Response res = client.readItem(knownResourceId, knownItemResourceId);
731         try {
732                 int statusCode = res.getStatus();
733         
734                 // Check the status code of the response: does it match
735                 // the expected response(s)?
736                 if (logger.isDebugEnabled()) {
737                     logger.debug(testName + ": status = " + statusCode);
738                 }
739                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
740                         invalidStatusCodeMessage(testRequestType, statusCode));
741                 Assert.assertEquals(statusCode, testExpectedStatusCode);
742         
743                 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
744                 Assert.assertNotNull(itemCommonPart);
745                 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
746                 verifyReadItemInstance(itemCommonPart);
747         } finally {
748                 res.close();
749         }
750     }
751     
752     protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
753         
754     @Test(dataProvider = "testName",
755                 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})    
756     public void deleteItem(String testName) throws Exception {
757         // Perform setup.
758         setupDelete();
759
760         // Submit the request to the service and store the response.
761         AuthorityClient client = (AuthorityClient) getClientInstance();
762         Response res = client.deleteItem(knownResourceId, knownItemResourceId);
763         int statusCode;
764         try {
765                 statusCode = res.getStatus();
766         } finally {
767                 res.close();
768         }
769
770         // Check the status code of the response: does it match
771         // the expected response(s)?
772         if (logger.isDebugEnabled()) {
773             logger.debug("delete: status = " + statusCode);
774         }
775         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
776                 invalidStatusCodeMessage(testRequestType, statusCode));
777         Assert.assertEquals(statusCode, testExpectedStatusCode);
778     }
779     
780     protected void readItemListInt(String vcsid, String shortId, String testName) {
781         // Perform setup.
782         setupReadList();
783
784         // Submit the request to the service and store the response.
785         AuthorityClient client = (AuthorityClient) getClientInstance();
786         Response res = null;
787         if (vcsid != null) {
788             res = client.readItemList(vcsid, null, null);
789         } else if (shortId != null) {
790             res = client.readItemListForNamedAuthority(shortId, null, null);
791         } else {
792             Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
793         }
794         try {
795                 int statusCode = res.getStatus();
796         
797                 // Check the status code of the response: does it match
798                 // the expected response(s)?
799                 if (logger.isDebugEnabled()) {
800                     logger.debug("  " + testName + ": status = " + statusCode);
801                 }
802                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
803                         invalidStatusCodeMessage(testRequestType, statusCode));
804                 Assert.assertEquals(statusCode, testExpectedStatusCode);
805         
806                 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
807                 List<AbstractCommonList.ListItem> items = list.getListItem();
808                 int nItemsReturned = items.size();
809                 long nItemsTotal = list.getTotalItems();
810                 if (logger.isDebugEnabled()) {
811                     logger.debug("  " + testName + ": Expected "
812                             + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
813                 }
814                 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
815         
816                         for (AbstractCommonList.ListItem item : items) {
817                                 String refName = AbstractCommonListUtils.ListItemGetElementValue(
818                                                 item, AuthorityClient.REF_NAME);
819                                 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
820                                 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
821                                                 AuthorityClient.TERM_DISPLAY_NAME);
822                                 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
823                                                 AuthorityClient.VOCAB_DISPLAY_NAME);
824                                 // One of these names needs to be set.
825                                 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
826                         }
827                 
828                 if(logger.isTraceEnabled()){
829                         AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
830                 }
831         } finally {
832                 res.close();
833         }
834     }
835     
836     @Test(dataProvider = "testName", dependsOnMethods = {"createItemList"})
837     public void readItemList(String testName) {
838         readItemListInt(knownAuthorityWithItems, null, testName);
839     }
840
841     @Test(dataProvider = "testName", dependsOnMethods = {"readItemList"})
842     public void readItemListByName(String testName) {
843         readItemListInt(null, knownAuthorityWithItemsIdentifier, testName);
844     }
845
846     @Test(dataProvider = "testName",
847                 dependsOnMethods = {"deleteItem"})
848     public void deleteNonExistentItem(String testName) {
849         // Perform setup.
850         setupDeleteNonExistent();
851
852         // Submit the request to the service and store the response.
853         AuthorityClient client = (AuthorityClient) getClientInstance();
854         Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
855         int statusCode;
856         try {
857                 statusCode = res.getStatus();
858         } finally {
859                 res.close();
860         }
861
862         // Check the status code of the response: does it match
863         // the expected response(s)?
864         if (logger.isDebugEnabled()) {
865             logger.debug(testName + ": status = " + statusCode);
866         }
867         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
868                 invalidStatusCodeMessage(testRequestType, statusCode));
869         Assert.assertEquals(statusCode, testExpectedStatusCode);
870     }
871     
872     protected String getServicePathItemsComponent() {
873         return AuthorityClient.ITEMS;
874     }
875     
876         public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
877                 PoxPayloadOut result = null;
878                 
879         AuthorityClient client = (AuthorityClient) getClientInstance();
880         PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
881         PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
882         result = payloadOut;
883                 
884                 return result;
885         }
886
887         /**
888          * Update an Authority item.
889          * 
890          * @param testName
891          * @throws Exception
892          */
893     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
894                 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
895     public void updateItem(String testName) throws Exception {
896         // Perform setup.
897         setupUpdate();
898         AUTHORITY_ITEM_TYPE theUpdate = null;
899
900         // Retrieve the contents of a resource to update.
901         AuthorityClient client = (AuthorityClient)this.getClientInstance();
902         Response res = client.readItem(knownResourceId, knownItemResourceId);
903         try {
904                 if (logger.isDebugEnabled()) {
905                     logger.debug(testName + ": read status = " + res.getStatus());
906                 }
907                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
908         
909                 if (logger.isDebugEnabled()) {
910                     logger.debug("got Authority item to update with ID: "
911                             + knownItemResourceId
912                             + " in authority: " + knownResourceId);
913                 }
914                 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
915                 Assert.assertNotNull(authorityItem);
916
917                 // Update the contents of this resource.
918                 theUpdate = updateItemInstance(authorityItem);
919                 if (logger.isDebugEnabled()) {
920                     logger.debug("\n\nTo be updated fields: CSID = "  + knownItemResourceId + "\n"
921                                 + objectAsXmlString(theUpdate));
922                 }
923         } finally {
924                 res.close();
925         }
926
927         // Submit the updated resource to the service and store the response.
928         PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
929         res = client.updateItem(knownResourceId, knownItemResourceId, output);
930         try {
931                 int statusCode = res.getStatus();
932         
933                 // Check the status code of the response: does it match the expected response(s)?
934                 if (logger.isDebugEnabled()) {
935                     logger.debug("updateItem: status = " + statusCode);
936                 }
937                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
938                         invalidStatusCodeMessage(testRequestType, statusCode));
939                 Assert.assertEquals(statusCode, testExpectedStatusCode);
940         
941                 // Retrieve the updated resource and verify that its contents exist.
942                 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
943                 Assert.assertNotNull(updatedVocabularyItem);
944
945                 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
946         } finally {
947                 res.close();
948         }
949     }
950     
951     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
952                 dependsOnMethods = {"updateLocalItemWithSync", "CRUDTests"})
953     public void deleteLocalItemWithSync(String testName) throws Exception {
954         final int itemIndexToDelete = 1;
955         //
956         // First check to see if we support sync.
957         //
958         AuthorityClient client = (AuthorityClient) getClientInstance();
959         if (client.supportsSync() == false) {
960                 return; // Exit the test since this authority doesn't support synchronization
961         }        
962         
963         // Perform test setup for a DELETE.
964         setupDelete();
965         AUTHORITY_ITEM_TYPE theUpdate = null;
966
967         // Delete an item from the SAS server
968         AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
969         Response res = sasClient.deleteNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(itemIndexToDelete));
970         try {
971                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);   
972         } finally {
973                 res.close();
974         }
975         
976         // Synchronize the local item's parent authority and verify the delete we just made
977         // to the SAS takes place locally after the sync -i.e., the local item should be deleted as well.
978         setupSync();
979         AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
980         Response response = localClient.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
981         try {
982                 int statusCode = response.getStatus();
983                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode));
984                 Assert.assertEquals(statusCode, testExpectedStatusCode);
985         } finally {
986                 response.close();
987         }        
988         
989         // Verify that the local item has been deleted.
990         setupReadNonExistent();
991         res = localClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(itemIndexToDelete));
992         try {
993                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
994                 knownSASItemIdentifiersList.remove(0); // remove it from our known set now that we've deleted it
995         } finally {
996                 res.close();
997         }
998     }
999     
1000     /**
1001      * We create a new item on the SAS, perform a sync with the local authority, and verify the local authority contains a copy
1002      * of the SAS item. 
1003      */
1004     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1005                 dependsOnMethods = {"veryifySyncWithSAS", "CRUDTests"})
1006     public void updateLocalItemWithSync(String testName) throws Exception {
1007         //
1008         // First check to see if we support sync.
1009         //
1010         AuthorityClient client = (AuthorityClient) getClientInstance();
1011         if (client.supportsSync() == false) {
1012                 return; // Exit the test since this authority doesn't support synchronization
1013         }        
1014         
1015         // Perform setup.
1016         setupUpdate();
1017         AUTHORITY_ITEM_TYPE theUpdate = null;
1018
1019         // Retrieve the contents of a shared authority item that we're going to update.
1020         AUTHORITY_ITEM_TYPE sasAuthorityItem = null;
1021         AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
1022         Response res = sasClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0));
1023         try {
1024                 if (logger.isDebugEnabled()) {
1025                     logger.debug(testName + ": read status = " + res.getStatus());
1026                 }
1027                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1028         
1029                 sasAuthorityItem = extractItemCommonPartValue(res);  // This is a SAS authority item
1030                 Assert.assertNotNull(sasAuthorityItem);
1031         } finally {
1032                 res.close();
1033         }
1034
1035         // Update the contents of this authority item so we can post an UPDATE to the server
1036         theUpdate = updateItemInstance(sasAuthorityItem);
1037
1038         // Submit the updated authority item and check the response.
1039         PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
1040         res = sasClient.updateNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0), output);
1041         AUTHORITY_ITEM_TYPE updatedSASAuthorityItem = null;
1042         try {
1043                 int statusCode = res.getStatus();
1044         
1045                 // Check the status code of the response: does it match the expected response(s)?
1046                 if (logger.isDebugEnabled()) {
1047                     logger.debug("updateItem: status = " + statusCode);
1048                 }
1049                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1050                         invalidStatusCodeMessage(testRequestType, statusCode));
1051                 Assert.assertEquals(statusCode, testExpectedStatusCode);
1052         
1053                 // Retrieve the updated authority item and verify that its contents exist.
1054                 updatedSASAuthorityItem = extractItemCommonPartValue(res);
1055                 Assert.assertNotNull(updatedSASAuthorityItem);
1056
1057                 compareUpdatedItemInstances(theUpdate, updatedSASAuthorityItem);
1058         } finally {
1059                 res.close();
1060         }
1061         
1062         // Synchronize the local item's parent authority and verify the update we just made
1063         // to the SAS item appears locally after the sync
1064         setupSync();
1065         AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
1066         Response response = localClient.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
1067         try {
1068                 int statusCode = response.getStatus();
1069                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode));
1070                 Assert.assertEquals(statusCode, testExpectedStatusCode);
1071         } finally {
1072                 response.close();
1073         }        
1074         
1075         setupRead();
1076         res = localClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0));
1077         try {
1078                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1079                 AUTHORITY_ITEM_TYPE syncedAuthorityItem = extractItemCommonPartValue(res);
1080                 Assert.assertNotNull(syncedAuthorityItem);
1081                 compareUpdatedItemInstances(syncedAuthorityItem, updatedSASAuthorityItem);
1082         } finally {
1083                 res.close();
1084         }
1085     }    
1086     
1087     protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
1088     
1089     /* (non-Javadoc)
1090      * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
1091      */
1092     @Test(dataProvider = "testName",
1093         dependsOnMethods = {"create", "update", "updateNonExistent"})
1094     public void updateNonExistentItem(String testName) throws Exception {
1095         // Perform setup.
1096         setupUpdateNonExistent();
1097
1098         // Submit the request to the service and store the response.
1099         // Note: The ID used in this 'create' call may be arbitrary.
1100         // The only relevant ID may be the one used in update(), below.
1101         AuthorityClient client = (AuthorityClient)this.getClientInstance();
1102         PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
1103         Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1104         try {
1105                 int statusCode = res.getStatus();
1106         
1107                 // Check the status code of the response: does it match
1108                 // the expected response(s)?
1109                 if (logger.isDebugEnabled()) {
1110                         logger.debug(testName + ": status = " + statusCode);
1111                 }
1112                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1113                                 invalidStatusCodeMessage(testRequestType, statusCode));
1114                 Assert.assertEquals(statusCode, testExpectedStatusCode);
1115         } finally {
1116                 res.close();
1117         }
1118     }
1119         
1120     //
1121     // Methods to persuade TestNG to follow the correct test dependency path
1122     //
1123     
1124     @Test(dataProvider = "testName",
1125                 dependsOnMethods = {"createItem"})
1126     public void baseAuthorityTests(String testName) {
1127         // Do nothing.  Here just to setup a test dependency chain.
1128     }
1129     
1130     /*
1131      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
1132      * refer to this method in their @Test annotation declarations.
1133      */
1134     @Override
1135     @Test(dataProvider = "testName",
1136                 dependsOnMethods = {
1137                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
1138         public void CRUDTests(String testName) {
1139                 // TODO Auto-generated method stub
1140         }
1141         
1142     @Override
1143     public void cleanUp() {
1144         String noTest = System.getProperty("noTestCleanup");
1145         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1146             if (logger.isDebugEnabled()) {
1147                 logger.debug("Skipping Cleanup phase ...");
1148             }
1149             return;
1150         }
1151         
1152         AuthorityClient client = (AuthorityClient) this.getClientInstance();
1153         String parentResourceId;
1154         String itemResourceId;
1155         //
1156         // Clean up all authority item resources.
1157         //
1158         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1159             itemResourceId = entry.getKey();
1160             parentResourceId = entry.getValue();
1161             Response response = client.deleteItem(parentResourceId, itemResourceId);
1162             try {
1163                 int status = response.getStatus();
1164                 if (status != Response.Status.OK.getStatusCode()) {
1165                         logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
1166                                         itemResourceId, parentResourceId));
1167                 }
1168             } finally {
1169                 response.close();
1170             }
1171         }
1172         //
1173         // Clean up authority items that were the result of a sync with the SAS
1174         // all the IDs are URN (not CSIDs).  The URNs work for the local items as well
1175         // as the SAS items.
1176         //
1177         for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
1178             itemResourceId = entry.getKey();
1179             parentResourceId = entry.getValue();
1180             // Note: Any non-success responses from the delete operation
1181             // below are ignored and not reported.
1182             client.deleteItem(parentResourceId, itemResourceId).close();
1183         }
1184         //
1185         // Clean up authority items on the SAS using the SAS client.
1186         //
1187         client = (AuthorityClient) this.getSASClientInstance();
1188         for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
1189             itemResourceId = entry.getKey();
1190             parentResourceId = entry.getValue();
1191             client.deleteItem(parentResourceId, itemResourceId).close();
1192         }
1193         //
1194         // Finally, call out superclass's cleanUp method to deleted the local authorities
1195         //
1196         super.cleanUp();
1197         //
1198         // Call out superclass's cleanUp method to delete the SAS authorities
1199         //
1200         super.cleanUp(client);        
1201     }
1202     
1203         protected String getTestAuthorityItemShortId() {
1204                 return getTestAuthorityItemShortId(false);
1205         }
1206
1207         protected String getTestAuthorityItemShortId(boolean makeUnique) {
1208                 String result = TEST_SHORTID;
1209                 
1210                 if (makeUnique == true) {
1211                         result = result + System.currentTimeMillis() + Math.abs(random.nextInt());
1212                 }
1213                 
1214                 return result;
1215         }
1216 }