]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
62e4d2e346015f92cb69cd150c44abb98796f779
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.client.test;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6
7 import javax.ws.rs.core.Response;
8
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.PoxPayloadOut;
17 import org.collectionspace.services.jaxb.AbstractCommonList;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.testng.Assert;
21 import org.testng.annotations.Test;
22
23 /**
24  * 
25  * @author remillet
26  *
27  * @param <AUTHORITY_COMMON_TYPE>
28  * @param <AUTHORITY_ITEM_TYPE>
29  * 
30  * All CRUD related authority test classes should extend this class.
31  * 
32  */
33 public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE> 
34         extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
35
36     private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
37         
38     protected String knownResourceShortIdentifer = null;
39         protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems"; 
40         protected String knownAuthorityWithItems = null;
41         
42         protected static final String SAS_IDENTIFIER = "SAS"; 
43         protected String knownSASAuthorityResourceId = null;
44         protected String knownSASItemResourceId = null;
45         protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
46
47         protected String knownResourceRefName = null;
48     protected String knownItemResourceId = null;
49     protected String knownItemResourceShortIdentifer = null;    
50     protected int nItemsToCreateInList = 5;
51                 
52         public abstract void authorityTests(String testName);
53     protected abstract String createItemInAuthority(AuthorityClient client, String authorityId);
54  
55     protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);    
56     protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception;
57     
58     protected void setKnownItemResource(String id, String shortIdentifer ) {
59         knownItemResourceId = id;
60         knownItemResourceShortIdentifer = shortIdentifer;
61     }
62
63     protected void setKnownResource(String id, String shortIdentifer,
64             String refName) {
65         knownResourceId = id;
66         knownResourceShortIdentifer = shortIdentifer;
67         knownResourceRefName = refName;
68     }
69
70         protected String getSASAuthorityIdentifier() {
71                 // TODO Auto-generated method stub
72                 return this.getKnowResourceIdentifier() + this.SAS_IDENTIFIER;
73         }
74     
75         protected String getUrnIdentifier(String shortId) {
76                 return String.format("urn:cspace:name:(%s)", shortId);
77         }
78         
79     /**
80      * Sets up create tests.
81      */
82     protected void setupSync() {
83         testExpectedStatusCode = this.STATUS_OK;
84         testRequestType = ServiceRequestType.SYNC;
85         testSetup(testExpectedStatusCode, testRequestType);
86     }
87     
88     /**
89      * Gets a client to the SAS (Shared Authority Server)
90      *
91      * @return the client
92      */
93     protected AuthorityClient getSASClientInstance() {
94         return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
95     }
96
97     /**
98      * Returns the root URL for a service.
99      *
100      * This URL consists of a base URL for all services, followed by
101      * a path component for the owning vocabulary, followed by the 
102      * path component for the items.
103      *
104      * @return The root URL for a service.
105      */
106     protected String getItemServiceRootURL(String parentResourceIdentifier) {
107         return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
108     }
109
110     /**
111      * Returns the URL of a specific resource managed by a service, and
112      * designated by an identifier (such as a universally unique ID, or UUID).
113      *
114      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
115      *
116      * @return The URL of a specific resource managed by a service.
117      */
118     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
119         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
120     }
121         
122     /**
123      * For authorities we override this method so we can save the shortid.
124      */
125     @Override
126     protected String createWithIdentifier(String testName, String identifier) throws Exception {
127         String csid = createResource(testName, identifier);
128         // Store the ID returned from the first resource created
129         // for additional tests below.
130         if (getKnowResourceId() == null) {
131                 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
132             if (logger.isDebugEnabled()) {
133                 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
134             }
135         }
136         
137         return identifier;
138     }    
139     
140     @Test(dependsOnMethods = {"readItem", "CRUDTests"})
141     public void testItemSubmitRequest() {
142
143         // Expected status code: 200 OK
144         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
145
146         // Submit the request to the service and store the response.
147         String method = ServiceRequestType.READ.httpMethodName();
148         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
149         int statusCode = submitRequest(method, url);
150
151         // Check the status code of the response: does it match
152         // the expected response(s)?
153         if (logger.isDebugEnabled()) {
154             logger.debug("testItemSubmitRequest: url=" + url
155                     + " status=" + statusCode);
156         }
157         Assert.assertEquals(statusCode, EXPECTED_STATUS);
158     }    
159
160     
161     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
162         dependsOnMethods = {"readItem"})
163     public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
164         // Perform setup.
165         setupUpdate();
166
167         // Submit the request to the service and store the response.
168         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = 
169                         (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
170         Response res = client.readItem(knownResourceId, knownItemResourceId);
171         AUTHORITY_ITEM_TYPE vitem = null;
172         try {
173                 int statusCode = res.getStatus();
174         
175                 // Check the status code of the response: does it match
176                 // the expected response(s)?
177                 if (logger.isDebugEnabled()) {
178                         logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
179                                         + knownItemResourceId + " status = " + statusCode);
180                 }
181                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
182                                 invalidStatusCodeMessage(testRequestType, statusCode));
183                 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
184         
185                 vitem = extractItemCommonPartValue(res);
186                 Assert.assertNotNull(vitem);
187                 // Try to Update with new parent vocab (use self, for test).
188                 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
189                                 "VocabularyItem inAuthority does not match knownResourceId.");
190                 client.setInAuthority(vitem, knownItemResourceId);
191
192         } finally {
193                 res.close();
194         }
195         
196         // Submit the updated resource to the service and store the response.
197         PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
198         res = client.updateItem(knownResourceId, knownItemResourceId, output);
199         try {
200                 int statusCode = res.getStatus();
201         
202                 // Check the status code of the response: does it match the expected response(s)?
203                 if (logger.isDebugEnabled()) {
204                         logger.debug(testName + ": status = " + statusCode);
205                 }
206                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
207                                 invalidStatusCodeMessage(testRequestType, statusCode));
208                 Assert.assertEquals(statusCode, testExpectedStatusCode);
209         } finally {
210                 res.close();
211         }
212         
213         res = client.readItem(knownResourceId, knownItemResourceId);
214         try {
215                 // Retrieve the updated resource and verify that the parent did not change
216                 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
217                 Assert.assertNotNull(updatedVocabularyItem);
218         
219                 // Verify that the updated resource received the correct data.
220                 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
221                                 knownResourceId,
222                                 "VocabularyItem allowed update to the parent (inAuthority).");
223         } finally {
224                 res.close();
225         }
226     }
227     
228     @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
229     public void createItem(String testName) {
230         // Perform setup.
231         setupCreate();
232
233         String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId);
234
235         // Store the ID returned from the first item resource created
236         // for additional tests below.
237         if (knownItemResourceId == null) {
238             knownItemResourceId = newID;
239             if (null != testName && logger.isDebugEnabled()) {
240                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
241             }
242         }
243     }
244     
245     /**
246      * Sync the local with the SAS
247      */
248     @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
249     public void syncWithSAS(String testName) {
250         setupSync();
251         AuthorityClient client = (AuthorityClient) this.getClientInstance();
252
253         //
254         // First create an empty instance of the authority, so we can sync items with it.  We're
255         // using the short ID of the SAS authority.  The short ID of the local and the SAS will (must) be the same.
256         //
257         String localAuthorityId = null;
258         try {
259                         localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
260                 } catch (Exception e) {
261                         Assert.assertNotNull(localAuthorityId);
262                 }
263
264         //
265         // Now we can try to sync the SAS authority with the local one we just created.
266         //
267         Response response = client.syncByName(getSASAuthorityIdentifier()); // Notice we're using the Short ID (short ID is the same on the local and SAS)
268         try {
269                 int statusCode = response.getStatus();
270                 if (logger.isDebugEnabled()) {
271                     logger.debug(testName + ": HTTP status = " + statusCode);
272                 }
273                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
274                         invalidStatusCodeMessage(testRequestType, statusCode));
275                 Assert.assertEquals(statusCode, testExpectedStatusCode);
276         } finally {
277                 response.close();
278         }
279     }
280     
281     /**
282      * SAS - Create a new authority on the SAS server.
283      * @param testName
284      */    
285     @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
286     public void createSASAuthority(String testName) {
287         // Perform setup.
288         setupCreate();
289
290         try {
291                 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier());
292                 knownSASAuthorityResourceId = newID;
293             if (logger.isDebugEnabled()) {
294                 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
295             }
296         } catch (Exception e) {
297                 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
298         }
299     }
300
301     /**
302      * SAS - Create an item in the SAS authority on the SAS server.
303      * @param testName
304      */
305     @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
306     public void createSASItem(String testName) {
307         // Perform setup.
308         setupCreate();
309
310         String shortId = "SassyActor" + System.currentTimeMillis() + random.nextInt();; // short ID needs to be unique
311         String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
312
313                 // Store the ID returned from the first item resource created
314         // for additional tests below.
315         if (knownSASItemResourceId == null) {
316                 knownSASItemResourceId = newID;
317             if (null != testName && logger.isDebugEnabled()) {
318                 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
319             }
320         }
321         //
322         // Keep track of the SAS authority items we create, so we can delete them from
323         // the *local* authority after we perform a sync operation.  We need to keep track
324         // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
325         //
326         this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
327     }
328     
329     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
330                 dependsOnMethods = {"createItem"})
331     public void createItemList(String testName) throws Exception {
332         knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
333         for (int j = 0; j < nItemsToCreateInList; j++) {
334                 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems);
335         }
336     }
337
338     /**
339      * Read by name.
340      *
341      * @param testName the test name
342      * @throws Exception the exception
343      */
344     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
345                 dependsOnMethods = {"CRUDTests"})
346     public void readByName(String testName) throws Exception {
347         // Perform setup.
348         setupRead();
349
350         // Submit the request to the service and store the response.
351         AuthorityClient client = (AuthorityClient) this.getClientInstance();
352         Response res = client.readByName(getKnowResourceIdentifier());
353         try {
354                 int statusCode = res.getStatus();
355         
356                 // Check the status code of the response: does it match
357                 // the expected response(s)?
358                 if (logger.isDebugEnabled()) {
359                     logger.debug(testName + ": status = " + statusCode);
360                 }
361                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
362                         invalidStatusCodeMessage(testRequestType, statusCode));
363                 Assert.assertEquals(statusCode, testExpectedStatusCode);
364                 
365                 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
366                 Assert.assertNotNull(commonPart);
367         } finally {
368                 res.close();
369         }
370     }
371     
372     /**
373      * Extracts the common part item from a service's item payload.
374      * 
375      * @param res
376      * @return
377      * @throws Exception
378      */
379         public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
380                 AUTHORITY_ITEM_TYPE result = null;
381                 
382         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
383                         this.getClientInstance();
384                 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
385                 if (payloadInputPart != null) {
386                         result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
387                 }
388                 Assert.assertNotNull(result,
389                                 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
390                 
391                 return result;
392         }
393     
394     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
395                 dependsOnMethods = {"readItem"})
396     public void readItemNonExistent(String testName) {
397         // Perform setup.
398         setupReadNonExistent();
399
400         // Submit the request to the service and store the response.
401         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
402                         this.getClientInstance();
403         Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
404         try {
405                 int statusCode = res.getStatus();
406         
407                 // Check the status code of the response: does it match
408                 // the expected response(s)?
409                 if (logger.isDebugEnabled()) {
410                     logger.debug(testName + ": status = " + statusCode);
411                 }
412                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
413                         invalidStatusCodeMessage(testRequestType, statusCode));
414                 Assert.assertEquals(statusCode, testExpectedStatusCode);
415         } finally {
416                 res.close();
417         }
418     }
419         
420     @Test(dataProvider = "testName",
421                 dependsOnMethods = {"createItem"})
422     public void readItem(String testName) throws Exception {
423         // Perform setup.
424         setupRead();
425
426         // Submit the request to the service and store the response.
427         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
428         Response res = client.readItem(knownResourceId, knownItemResourceId);
429         try {
430                 int statusCode = res.getStatus();
431         
432                 // Check the status code of the response: does it match
433                 // the expected response(s)?
434                 if (logger.isDebugEnabled()) {
435                     logger.debug(testName + ": status = " + statusCode);
436                 }
437                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
438                         invalidStatusCodeMessage(testRequestType, statusCode));
439                 Assert.assertEquals(statusCode, testExpectedStatusCode);
440         
441                 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
442                 Assert.assertNotNull(itemCommonPart);
443                 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
444                 verifyReadItemInstance(itemCommonPart);
445         } finally {
446                 res.close();
447         }
448     }
449     
450     protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
451         
452     @Test(dataProvider = "testName",
453                 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})    
454     public void deleteItem(String testName) throws Exception {
455         // Perform setup.
456         setupDelete();
457
458         // Submit the request to the service and store the response.
459         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
460                         this.getClientInstance();
461         Response res = client.deleteItem(knownResourceId, knownItemResourceId);
462         int statusCode;
463         try {
464                 statusCode = res.getStatus();
465         } finally {
466                 res.close();
467         }
468
469         // Check the status code of the response: does it match
470         // the expected response(s)?
471         if (logger.isDebugEnabled()) {
472             logger.debug("delete: status = " + statusCode);
473         }
474         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
475                 invalidStatusCodeMessage(testRequestType, statusCode));
476         Assert.assertEquals(statusCode, testExpectedStatusCode);
477     }
478     
479     protected void readItemListInt(String vcsid, String shortId, String testName) {
480         // Perform setup.
481         setupReadList();
482
483         // Submit the request to the service and store the response.
484         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
485         Response res = null;
486         if (vcsid != null) {
487             res = client.readItemList(vcsid, null, null);
488         } else if (shortId != null) {
489             res = client.readItemListForNamedAuthority(shortId, null, null);
490         } else {
491             Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
492         }
493         try {
494                 int statusCode = res.getStatus();
495         
496                 // Check the status code of the response: does it match
497                 // the expected response(s)?
498                 if (logger.isDebugEnabled()) {
499                     logger.debug("  " + testName + ": status = " + statusCode);
500                 }
501                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
502                         invalidStatusCodeMessage(testRequestType, statusCode));
503                 Assert.assertEquals(statusCode, testExpectedStatusCode);
504         
505                 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
506                 List<AbstractCommonList.ListItem> items = list.getListItem();
507                 int nItemsReturned = items.size();
508                 long nItemsTotal = list.getTotalItems();
509                 if (logger.isDebugEnabled()) {
510                     logger.debug("  " + testName + ": Expected "
511                             + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
512                 }
513                 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
514         
515                 if(logger.isTraceEnabled()){
516                         AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
517                 }
518         } finally {
519                 res.close();
520         }
521     }
522     
523     @Test(dataProvider = "testName",
524                 dependsOnMethods = {"createItemList"})
525     public void readItemList(String testName) {
526         readItemListInt(knownAuthorityWithItems, null, testName);
527     }
528
529     @Test(dataProvider = "testName",
530                 dependsOnMethods = {"readItem"})
531     public void readItemListByName(String testName) {
532         readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName);
533     }
534
535     @Test(dataProvider = "testName",
536                 dependsOnMethods = {"deleteItem"})
537     public void deleteNonExistentItem(String testName) {
538         // Perform setup.
539         setupDeleteNonExistent();
540
541         // Submit the request to the service and store the response.
542         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
543         Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
544         int statusCode;
545         try {
546                 statusCode = res.getStatus();
547         } finally {
548                 res.close();
549         }
550
551         // Check the status code of the response: does it match
552         // the expected response(s)?
553         if (logger.isDebugEnabled()) {
554             logger.debug(testName + ": status = " + statusCode);
555         }
556         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
557                 invalidStatusCodeMessage(testRequestType, statusCode));
558         Assert.assertEquals(statusCode, testExpectedStatusCode);
559     }
560     
561     protected String getServicePathItemsComponent() {
562         return AuthorityClient.ITEMS;
563     }
564     
565         public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
566                 PoxPayloadOut result = null;
567                 
568         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
569         PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
570         PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
571         result = payloadOut;
572                 
573                 return result;
574         }
575
576         /**
577          * Update an Authority item.
578          * 
579          * @param testName
580          * @throws Exception
581          */
582     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
583                 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
584     public void updateItem(String testName) throws Exception {
585         // Perform setup.
586         setupUpdate();
587         AUTHORITY_ITEM_TYPE theUpdate = null;
588
589         // Retrieve the contents of a resource to update.
590         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
591                         (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
592         Response res = client.readItem(knownResourceId, knownItemResourceId);
593         try {
594                 if (logger.isDebugEnabled()) {
595                     logger.debug(testName + ": read status = " + res.getStatus());
596                 }
597                 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
598         
599                 if (logger.isDebugEnabled()) {
600                     logger.debug("got Authority item to update with ID: "
601                             + knownItemResourceId
602                             + " in authority: " + knownResourceId);
603                 }
604                 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
605                 Assert.assertNotNull(authorityItem);
606
607                 // Update the contents of this resource.
608                 theUpdate = updateItemInstance(authorityItem);
609                 if (logger.isDebugEnabled()) {
610                     logger.debug("\n\nTo be updated fields: CSID = "  + knownItemResourceId + "\n"
611                                 + objectAsXmlString(theUpdate));
612                 }
613         } finally {
614                 res.close();
615         }
616
617         // Submit the updated resource to the service and store the response.
618         PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
619         res = client.updateItem(knownResourceId, knownItemResourceId, output);
620         try {
621                 int statusCode = res.getStatus();
622         
623                 // Check the status code of the response: does it match the expected response(s)?
624                 if (logger.isDebugEnabled()) {
625                     logger.debug("updateItem: status = " + statusCode);
626                 }
627                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
628                         invalidStatusCodeMessage(testRequestType, statusCode));
629                 Assert.assertEquals(statusCode, testExpectedStatusCode);
630         
631                 // Retrieve the updated resource and verify that its contents exist.
632                 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
633                 Assert.assertNotNull(updatedVocabularyItem);
634
635                 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
636         } finally {
637                 res.close();
638         }
639     }
640     
641     protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
642     
643     /* (non-Javadoc)
644      * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
645      */
646     @Test(dataProvider = "testName",
647         dependsOnMethods = {"create", "update", "updateNonExistent"})
648     public void updateNonExistentItem(String testName) throws Exception {
649         // Perform setup.
650         setupUpdateNonExistent();
651
652         // Submit the request to the service and store the response.
653         // Note: The ID used in this 'create' call may be arbitrary.
654         // The only relevant ID may be the one used in update(), below.
655         AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
656                         (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
657         PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
658         Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
659         try {
660                 int statusCode = res.getStatus();
661         
662                 // Check the status code of the response: does it match
663                 // the expected response(s)?
664                 if (logger.isDebugEnabled()) {
665                         logger.debug(testName + ": status = " + statusCode);
666                 }
667                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
668                                 invalidStatusCodeMessage(testRequestType, statusCode));
669                 Assert.assertEquals(statusCode, testExpectedStatusCode);
670         } finally {
671                 res.close();
672         }
673     }
674         
675     //
676     // Methods to persuade TestNG to follow the correct test dependency path
677     //
678     
679     @Test(dataProvider = "testName",
680                 dependsOnMethods = {"createItem"})
681     public void baseAuthorityTests(String testName) {
682         // Do nothing.  Here just to setup a test dependency chain.
683     }
684     
685     /*
686      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
687      * refer to this method in their @Test annotation declarations.
688      */
689     @Override
690     @Test(dataProvider = "testName",
691                 dependsOnMethods = {
692                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
693         public void CRUDTests(String testName) {
694                 // TODO Auto-generated method stub
695         }
696         
697     @Override
698     public void cleanUp() {
699         String noTest = System.getProperty("noTestCleanup");
700         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
701             if (logger.isDebugEnabled()) {
702                 logger.debug("Skipping Cleanup phase ...");
703             }
704             return;
705         }
706         
707         AuthorityClient client = (AuthorityClient) this.getClientInstance();
708         String parentResourceId;
709         String itemResourceId;
710         //
711         // Clean up all authority item resources.
712         //
713         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
714             itemResourceId = entry.getKey();
715             parentResourceId = entry.getValue();
716             Response response = client.deleteItem(parentResourceId, itemResourceId);
717             try {
718                 int status = response.getStatus();
719                 if (status != Response.Status.OK.getStatusCode()) {
720                         logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
721                                         itemResourceId, parentResourceId));
722                 }
723             } finally {
724                 response.close();
725             }
726         }
727         //
728         // Clean up authority items that were the result of a sync with the SAS
729         // all the IDs are URN (not CSIDs).  The URNs work for the local items as well
730         // as the SAS items.
731         //
732         for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
733             itemResourceId = entry.getKey();
734             parentResourceId = entry.getValue();
735             // Note: Any non-success responses from the delete operation
736             // below are ignored and not reported.
737             client.deleteItem(parentResourceId, itemResourceId).close();
738         }
739         //
740         // Clean up authority items on the SAS using the SAS client.
741         //
742         client = (AuthorityClient) this.getSASClientInstance();
743         for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
744             itemResourceId = entry.getKey();
745             parentResourceId = entry.getValue();
746             client.deleteItem(parentResourceId, itemResourceId).close();
747         }
748         //
749         // Finally, call out superclass's cleanUp method to deleted the local authorities
750         //
751         super.cleanUp();
752         //
753         // Call out superclass's cleanUp method to delete the SAS authorities
754         //
755         super.cleanUp(client);        
756     }
757     
758         abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);
759 }