]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
06b8d6c3d6f83df6c702d2871abe389ad2d1eb4b
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright (c) 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28
29 import org.collectionspace.services.client.AbstractCommonListUtils;
30 import org.collectionspace.services.client.AcquisitionClient;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.PayloadOutputPart;
33 import org.collectionspace.services.client.PoxPayloadIn;
34 import org.collectionspace.services.client.PoxPayloadOut;
35 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37
38 import org.collectionspace.services.acquisition.AcquisitionsCommon;
39 import org.collectionspace.services.acquisition.AcquisitionDateList;
40 import org.collectionspace.services.acquisition.AcquisitionSourceList;
41 import org.collectionspace.services.acquisition.OwnerList;
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
46
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 /**
51  * AcquisitionServiceTest, carries out tests against a
52  * deployed and running Acquisition Service.
53  * 
54  * $LastChangedRevision: 621 $
55  * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
56  */
57 public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, AcquisitionsCommon> {
58
59     /** The logger. */
60     private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
61     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62
63     // Instance variables specific to this test.
64     private final static String CURRENT_DATE_UTC =
65             GregorianCalendarDateTimeUtils.timestampUTC();
66
67     @Override
68     public String getServicePathComponent() {
69         return AcquisitionClient.SERVICE_PATH_COMPONENT;
70     }
71
72     @Override
73     protected String getServiceName() {
74         return AcquisitionClient.SERVICE_NAME;
75     }
76     
77     /* (non-Javadoc)
78      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79      */
80     @Override
81     protected CollectionSpaceClient getClientInstance() {
82         return new AcquisitionClient();
83     }
84     
85     // ---------------------------------------------------------------
86     // CRUD tests : CREATE tests
87     // ---------------------------------------------------------------
88     // Success outcomes
89     /* (non-Javadoc)
90      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
91      */
92     @Override
93 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
94     public void create(String testName) throws Exception {
95         // Perform setup, such as initializing the type of service request
96         // (e.g. CREATE, DELETE), its valid and expected status codes, and
97         // its associated HTTP method name (e.g. POST, DELETE).
98         setupCreate();
99
100         // Submit the request to the service and store the response.
101         String identifier = createIdentifier();
102
103         AcquisitionClient client = new AcquisitionClient();
104         PoxPayloadOut multipart = createAcquisitionInstance(identifier);
105         ClientResponse<Response> res = client.create(multipart);
106
107         int statusCode = res.getStatus();
108
109         // Check the status code of the response: does it match
110         // the expected response(s)?
111         //
112         // Specifically:
113         // Does it fall within the set of valid status codes?
114         // Does it exactly match the expected status code?
115         if(logger.isDebugEnabled()){
116             logger.debug(testName + ": status = " + statusCode);
117         }
118         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
119                 invalidStatusCodeMessage(testRequestType, statusCode));
120         Assert.assertEquals(statusCode, testExpectedStatusCode);
121
122         // Store the ID returned from the first resource created
123         // for additional tests below.
124         if (knownResourceId == null){
125             knownResourceId = extractId(res);
126             if (logger.isDebugEnabled()) {
127                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
128             }
129         }
130         
131         // Store the IDs from every resource created by tests,
132         // so they can be deleted after tests have been run.
133         allResourceIdsCreated.add(extractId(res));
134     }
135
136     /* (non-Javadoc)
137      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
138      */
139     @Override
140 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
141 //       dependsOnMethods = {"create"})
142     public void createList(String testName) throws Exception {
143         for(int i = 0; i < 3; i++){
144             create(testName);
145         }
146     }
147
148     /*
149     * Tests to diagnose and fix CSPACE-2578.
150     *
151     * This is a bug identified in release 1.0 alpha, after first implementing an
152     * Acquisition Funding repeatable group of fields, in which record creation
153     * fails if there is whitespace (or more generally, a text node) between
154     * the acquisitionFunding container element and its first child field.
155     */
156
157     // Verify that record creation occurs successfully when there is NO whitespace
158     // between the acquisitionFunding tag and its first child element tag
159     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
160         dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
161     public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
162         String testDataDir = System.getProperty("test-data.fileName");
163         String newId =
164             createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
165         testSubmitRequest(newId);
166     }
167
168     // Verify that record creation occurs successfully when there is whitespace
169     // between the acquisitionFunding tag and its first child element tag
170
171     // FIXME: This test currently fails.  @Test annotation is currently commented
172     // out for check-in, to prevent service tests from failing.  Can uncomment to test
173     // fixes, and also after the issue is resolved, to help detect any regressions.
174
175     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
176         dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
177     public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
178         String testDataDir = System.getProperty("test-data.fileName");
179         String newId =
180             createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
181         AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
182         testSubmitRequest(newId);
183     }
184
185     // Failure outcomes
186
187     // Placeholders until the three tests below can be uncommented.
188     // See Issue CSPACE-401.
189     /* (non-Javadoc)
190      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
191      */
192     @Override
193     public void createWithEmptyEntityBody(String testName) throws Exception {
194         //Should this really be empty?
195     }
196
197     /* (non-Javadoc)
198      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
199      */
200     @Override
201     public void createWithMalformedXml(String testName) throws Exception {
202         //Should this really be empty?
203     }
204
205     /* (non-Javadoc)
206      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
207      */
208     @Override
209     public void createWithWrongXmlSchema(String testName) throws Exception {
210         //Should this really be empty?
211     }
212
213     /*
214     @Override
215     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
216         dependsOnMethods = {"create", "testSubmitRequest"})
217     public void createWithMalformedXml(String testName) throws Exception {
218     
219         if (logger.isDebugEnabled()) {
220             logger.debug(testBanner(testName, CLASS_NAME));
221         };
222             
223         // Perform setup.
224         setupCreateWithMalformedXml();
225
226         // Submit the request to the service and store the response.
227         String method = REQUEST_TYPE.httpMethodName();
228         String url = getServiceRootURL();
229         final String entity = MALFORMED_XML_DATA; // Constant from base class.
230         int statusCode = submitRequest(method, url, entity);
231
232         // Check the status code of the response: does it match
233         // the expected response(s)?
234         if(logger.isDebugEnabled()){
235             logger.debug(testName + ": url=" + url +
236                 " status=" + statusCode);
237          }
238         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
239         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
240         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
241     }
242
243     @Override
244     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
245         dependsOnMethods = {"create", "testSubmitRequest"})
246     public void createWithWrongXmlSchema(String testName) throws Exception {
247     
248         if (logger.isDebugEnabled()) {
249             logger.debug(testBanner(testName, CLASS_NAME));
250         };
251         
252         // Perform setup.
253         setupCreateWithWrongXmlSchema();
254
255         // Submit the request to the service and store the response.
256         String method = REQUEST_TYPE.httpMethodName();
257         String url = getServiceRootURL();
258         final String entity = WRONG_XML_SCHEMA_DATA;
259         int statusCode = submitRequest(method, url, entity);
260
261         // Check the status code of the response: does it match
262         // the expected response(s)?
263         if(logger.isDebugEnabled()){
264             logger.debug(testName + ": url=" + url +
265                 " status=" + statusCode);
266          }
267         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
270     }
271      */
272
273     // ---------------------------------------------------------------
274     // CRUD tests : READ tests
275     // ---------------------------------------------------------------
276     // Success outcomes
277     /* (non-Javadoc)
278      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
279      */
280     @Override
281 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
282 //        dependsOnMethods = {"create"})
283     public void read(String testName) throws Exception {
284         // Perform setup.
285         setupRead();
286
287         AcquisitionClient client = new AcquisitionClient();
288
289         // Submit the request to the service and store the response.
290         ClientResponse<String> res = client.read(knownResourceId);
291         int statusCode = res.getStatus();
292
293         // Check the status code of the response: does it match
294         // the expected response(s)?
295         if(logger.isDebugEnabled()){
296             logger.debug(testName + ": status = " + statusCode);
297         }
298         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
299                 invalidStatusCodeMessage(testRequestType, statusCode));
300         Assert.assertEquals(statusCode, testExpectedStatusCode);
301
302         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
303         AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
304                 client.getCommonPartName(), AcquisitionsCommon.class);
305         Assert.assertNotNull(acquisitionObject);
306
307         // Verify the number and contents of values in repeatable fields,
308         // as created in the instance record used for testing.
309         List<String> acqSources =
310                 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
311         Assert.assertTrue(acqSources.size() > 0);
312         Assert.assertNotNull(acqSources.get(0));
313
314         List<String> acqDates =
315                 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
316         Assert.assertTrue(acqDates.size() > 0);
317         Assert.assertNotNull(acqDates.get(0));
318
319         List<String> owners =
320                 acquisitionObject.getOwners().getOwner();
321         Assert.assertTrue(owners.size() > 0);
322         Assert.assertNotNull(owners.get(0));
323     }
324
325     // Failure outcomes
326     /* (non-Javadoc)
327      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
328      */
329     @Override
330 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
331 //        dependsOnMethods = {"read"})
332     public void readNonExistent(String testName) throws Exception {
333         // Perform setup.
334         setupReadNonExistent();
335
336         // Submit the request to the service and store the response.
337         AcquisitionClient client = new AcquisitionClient();
338         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
339         int statusCode = res.getStatus();
340
341         // Check the status code of the response: does it match
342         // the expected response(s)?
343         if(logger.isDebugEnabled()){
344             logger.debug(testName + ": status = " + statusCode);
345         }
346         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
347                 invalidStatusCodeMessage(testRequestType, statusCode));
348         Assert.assertEquals(statusCode, testExpectedStatusCode);
349     }
350
351     // ---------------------------------------------------------------
352     // CRUD tests : READ_LIST tests
353     // ---------------------------------------------------------------
354     // Success outcomes
355     /* (non-Javadoc)
356      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
357      */
358     @Override
359 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
360 //        dependsOnMethods = {"createList", "read"})
361     public void readList(String testName) throws Exception {
362         // Perform setup.
363         setupReadList();
364
365         // Submit the request to the service and store the response.
366         AcquisitionClient client = new AcquisitionClient();
367         ClientResponse<AbstractCommonList> res = client.readList();
368         try {
369                 // Check the status code of the response: does it match
370                 // the expected response(s)?
371                 assertStatusCode(res, testName);
372                 AbstractCommonList list = res.getEntity();
373         
374                 // Optionally output additional data about list members for debugging.
375                 if (logger.isTraceEnabled() == true){
376                         AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
377                 }
378         } finally {
379                 if (res != null) {
380                 res.releaseConnection();
381             }
382         }
383     }
384     
385     // Failure outcomes
386     // None at present.
387
388     // ---------------------------------------------------------------
389     // CRUD tests : UPDATE tests
390     // ---------------------------------------------------------------
391
392     // Success outcomes
393     /* (non-Javadoc)
394      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
395      */
396     @Override
397 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
398 //        dependsOnMethods = {"read"})
399     public void update(String testName) throws Exception {
400         // Perform setup.
401         setupUpdate();
402
403         // Retrieve the contents of a resource to update.
404         AcquisitionClient client = new AcquisitionClient();
405         ClientResponse<String> res = client.read(knownResourceId);
406         if(logger.isDebugEnabled()){
407             logger.debug(testName + ": read status = " + res.getStatus());
408         }
409         Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
410
411         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
412
413         AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
414                 client.getCommonPartName(), AcquisitionsCommon.class);
415         Assert.assertNotNull(acquisition);
416
417         // Update the content of this resource.
418         acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
419         if(logger.isDebugEnabled()){
420             logger.debug("updated object");
421             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
422         }
423         // Submit the request to the service and store the response.
424         PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
425         PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
426         commonPart.setLabel(client.getCommonPartName());
427
428         res = client.update(knownResourceId, output);
429         int statusCode = res.getStatus();
430         // Check the status code of the response: does it match the expected response(s)?
431         if(logger.isDebugEnabled()){
432             logger.debug(testName + ": status = " + statusCode);
433         }
434         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
435                 invalidStatusCodeMessage(testRequestType, statusCode));
436         Assert.assertEquals(statusCode, testExpectedStatusCode);
437
438         input = new PoxPayloadIn(res.getEntity());
439         AcquisitionsCommon updatedAcquisition =
440                 (AcquisitionsCommon) extractPart(input,
441                         client.getCommonPartName(), AcquisitionsCommon.class);
442         Assert.assertNotNull(updatedAcquisition);
443
444         Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
445                 acquisition.getAcquisitionReferenceNumber(),
446                 "Data in updated object did not match submitted data.");
447
448     }
449
450     // Failure outcomes
451     // Placeholders until the three tests below can be uncommented.
452     // See Issue CSPACE-401.
453     /* (non-Javadoc)
454      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
455      */
456     @Override
457     public void updateWithEmptyEntityBody(String testName) throws Exception {
458         //Should this really be empty?
459     }
460
461     /* (non-Javadoc)
462      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
463      */
464     @Override
465     public void updateWithMalformedXml(String testName) throws Exception {
466         //Should this really be empty?
467     }
468
469     /* (non-Javadoc)
470      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
471      */
472     @Override
473     public void updateWithWrongXmlSchema(String testName) throws Exception {
474         //Should this really be empty?
475     }
476
477     /*
478     @Override
479     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
480         dependsOnMethods = {"create", "update", "testSubmitRequest"})
481     public void updateWithEmptyEntityBody(String testName) throws Exception {
482     
483         if (logger.isDebugEnabled()) {
484             logger.debug(testBanner(testName, CLASS_NAME));
485         };
486             
487         // Perform setup.
488         setupUpdateWithEmptyEntityBody();
489
490         // Submit the request to the service and store the response.
491         String method = REQUEST_TYPE.httpMethodName();
492         String url = getResourceURL(knownResourceId);
493         String mediaType = MediaType.APPLICATION_XML;
494         final String entity = "";
495         int statusCode = submitRequest(method, url, mediaType, entity);
496
497         // Check the status code of the response: does it match
498         // the expected response(s)?
499         if(logger.isDebugEnabled()){
500             (testName + ": url=" + url + " status=" + statusCode);
501         }
502         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
503         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
504         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
505         }
506
507     @Override
508     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
509         dependsOnMethods = {"create", "testSubmitRequest"})
510     public void createWithEmptyEntityBody(String testName) throws Exception {
511     
512         if (logger.isDebugEnabled()) {
513             logger.debug(testBanner(testName, CLASS_NAME));
514         };
515         
516         // Perform setup.
517         setupCreateWithEmptyEntityBody();
518
519         // Submit the request to the service and store the response.
520         String method = REQUEST_TYPE.httpMethodName();
521         String url = getServiceRootURL();
522         String mediaType = MediaType.APPLICATION_XML;
523         final String entity = "";
524         int statusCode = submitRequest(method, url, mediaType, entity);
525
526         // Check the status code of the response: does it match
527         // the expected response(s)?
528         if(logger.isDebugEnabled()){
529             logger.debug(testName + ": url=" + url +
530                 " status=" + statusCode);
531         }
532         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
533         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
534         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
535     }
536
537     @Override
538     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
539         dependsOnMethods = {"create", "update", "testSubmitRequest"})
540     public void updateWithMalformedXml(String testName) throws Exception {
541
542         if (logger.isDebugEnabled()) {
543             logger.debug(testBanner(testName, CLASS_NAME));
544         };
545         
546         // Perform setup.
547         setupUpdateWithMalformedXml();
548
549         // Submit the request to the service and store the response.
550         String method = REQUEST_TYPE.httpMethodName();
551         String url = getResourceURL(knownResourceId);
552         final String entity = MALFORMED_XML_DATA;
553         int statusCode = submitRequest(method, url, entity);
554
555         // Check the status code of the response: does it match
556         // the expected response(s)?
557         if(logger.isDebugEnabled()){
558             logger.debug(testName + ": url=" + url +
559                 " status=" + statusCode);
560          }
561         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
562         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
563         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
564     }
565
566     @Override
567     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
568     public void updateWithWrongXmlSchema(String testName) {
569     
570         if (logger.isDebugEnabled()) {
571             logger.debug(testBanner(testName, CLASS_NAME));
572         };
573         
574         // Perform setup.
575         setupUpdateWithWrongXmlSchema();
576
577         // Submit the request to the service and store the response.
578         String method = REQUEST_TYPE.httpMethodName();
579         String url = getResourceURL(knownResourceId);
580         final String entity = WRONG_XML_SCHEMA_DATA;
581         int statusCode = submitRequest(method, url, entity);
582
583         // Check the status code of the response: does it match
584         // the expected response(s)?
585         if(logger.isDebugEnabled()){
586             logger.debug(testName + ": url=" + url +
587                 " status=" + statusCode);
588          }
589         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
590         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
591         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
592     }
593      */
594     
595     /* (non-Javadoc)
596      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
597      */
598     @Override
599 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
600 //        dependsOnMethods = {"update", "testSubmitRequest"})
601     public void updateNonExistent(String testName) throws Exception {
602         // Perform setup.
603         setupUpdateNonExistent();
604
605         // Submit the request to the service and store the response.
606         // Note: The ID used in this 'create' call may be arbitrary.
607         // The only relevant ID may be the one used in update(), below.
608         AcquisitionClient client = new AcquisitionClient();
609         PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
610         ClientResponse<String> res =
611             client.update(NON_EXISTENT_ID, multipart);
612         int statusCode = res.getStatus();
613
614         // Check the status code of the response: does it match
615         // the expected response(s)?
616         if(logger.isDebugEnabled()){
617             logger.debug(testName + ": status = " + statusCode);
618         }
619         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
620                 invalidStatusCodeMessage(testRequestType, statusCode));
621         Assert.assertEquals(statusCode, testExpectedStatusCode);
622     }
623
624     // ---------------------------------------------------------------
625     // CRUD tests : DELETE tests
626     // ---------------------------------------------------------------
627     // Success outcomes
628     /* (non-Javadoc)
629      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
630      */
631     @Override
632 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
633 //        dependsOnMethods = {"create", "read", "update"})
634     public void delete(String testName) throws Exception {
635         // Perform setup.
636         setupDelete();
637
638         // Submit the request to the service and store the response.
639         AcquisitionClient client = new AcquisitionClient();
640         ClientResponse<Response> res = client.delete(knownResourceId);
641         int statusCode = res.getStatus();
642
643         // Check the status code of the response: does it match
644         // the expected response(s)?
645         if(logger.isDebugEnabled()){
646             logger.debug(testName + ": status = " + statusCode);
647         }
648         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
649                 invalidStatusCodeMessage(testRequestType, statusCode));
650         Assert.assertEquals(statusCode, testExpectedStatusCode);
651     }
652
653     // Failure outcomes
654     /* (non-Javadoc)
655      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
656      */
657     @Override
658 //    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
659 //        dependsOnMethods = {"delete"})
660     public void deleteNonExistent(String testName) throws Exception {
661         // Perform setup.
662         setupDeleteNonExistent();
663
664         // Submit the request to the service and store the response.
665         AcquisitionClient client = new AcquisitionClient();
666         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
667         int statusCode = res.getStatus();
668
669         // Check the status code of the response: does it match
670         // the expected response(s)?
671         if(logger.isDebugEnabled()){
672             logger.debug(testName + ": status = " + statusCode);
673         }
674         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
675                 invalidStatusCodeMessage(testRequestType, statusCode));
676         Assert.assertEquals(statusCode, testExpectedStatusCode);
677     }
678
679     // ---------------------------------------------------------------
680     // Utility tests : tests of code used in tests above
681     // ---------------------------------------------------------------
682
683     @Override
684     protected PoxPayloadOut createInstance(String identifier) {
685         return createAcquisitionInstance(identifier);
686     }
687         
688     /**
689      * Creates the acquisition instance.
690      *
691      * @param identifier the identifier
692      * @return the multipart output
693      */
694     private PoxPayloadOut createAcquisitionInstance(String identifier) {
695         AcquisitionsCommon acquisition = new AcquisitionsCommon();
696         acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-"  + identifier);
697
698         AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
699         List<String> acqSources = acqSourcesList.getAcquisitionSource();
700         // FIXME Use properly formatted refNames for representative acquisition
701         // sources in this example test record. The following are mere placeholders.
702         acqSources.add("Donor Acquisition Source-" + identifier);
703         acqSources.add("Museum Acquisition Source-" + identifier);
704         acquisition.setAcquisitionSources(acqSourcesList);
705
706         AcquisitionDateList acqDatesList = new AcquisitionDateList();
707         List<String> acqDates = acqDatesList.getAcquisitionDate();
708         acqDates.add(CURRENT_DATE_UTC);
709         acqDates.add(CURRENT_DATE_UTC);
710         acquisition.setAcquisitionDates(acqDatesList);
711
712         OwnerList ownersList = new OwnerList();
713         List<String> owners = ownersList.getOwner();
714         // FIXME Use properly formatted refNames for representative owners
715         // in this example test record. The following are mere placeholders.
716         owners.add("First Owner -" + identifier);
717         owners.add("Second Owner-" + identifier);
718         acquisition.setOwners(ownersList);
719
720         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
721         PayloadOutputPart commonPart = multipart.addPart(acquisition,
722             MediaType.APPLICATION_XML_TYPE);
723         commonPart.setLabel(new AcquisitionClient().getCommonPartName());
724
725         if(logger.isDebugEnabled()){
726             logger.debug("to be created, acquisition common");
727             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
728         }
729         return multipart;
730     }
731
732     // FIXME: The following methods might be made generic and moved to a common package.
733
734     /**
735      * Retrives an XML document from the given file, and uses
736      * the JAXB unmarshaller to create a Java object representation
737      * and ultimately a multipart payload that can be submitted in
738      * a create or update request.
739      *
740      * @param commonPartName
741      * @param commonPartFileName
742      * @return
743      * @throws Exception
744      */
745     private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
746             String commonPartFileName) throws Exception {
747
748         AcquisitionsCommon acquisition =
749                 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
750                 commonPartFileName);
751         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
752         PayloadOutputPart commonPart = multipart.addPart(acquisition,
753                 MediaType.APPLICATION_XML_TYPE);
754         commonPart.setLabel(commonPartName);
755
756         if (logger.isDebugEnabled()) {
757             logger.debug(testName + " to be created, acquisitions common");
758             logger.debug(objectAsXmlString(acquisition,
759                     AcquisitionsCommon.class));
760         }
761         return multipart;
762
763     }
764
765     /**
766      * Creates a record / resource from the data in an XML file.
767      *
768      * @param testName the test name
769      * @param fileName the file name
770      * @param useJaxb the use jaxb
771      * @return the string
772      * @throws Exception the exception
773      */
774     private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
775
776         // Perform setup.
777         setupCreate();
778
779         PoxPayloadOut multipart = null;
780
781         AcquisitionClient client = new AcquisitionClient();
782         if (useJaxb) {
783             multipart = createAcquisitionInstanceFromXml(testName,
784                     client.getCommonPartName(), fileName);
785         } else {
786
787             multipart = createAcquisitionInstanceFromRawXml(testName,
788                     client.getCommonPartName(), fileName);
789         }
790         ClientResponse<Response> res = client.create(multipart);
791         int statusCode = res.getStatus();
792
793         if (logger.isDebugEnabled()) {
794             logger.debug(testName + ": status = " + statusCode);
795         }
796         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
797                 invalidStatusCodeMessage(testRequestType, statusCode));
798         Assert.assertEquals(statusCode, testExpectedStatusCode);
799         String newId = extractId(res);
800         allResourceIdsCreated.add(newId);
801         return newId;
802     }
803
804      /**
805      * Returns a multipart payload that can be submitted with a
806      * create or update request, by reading from an XML file.
807      *
808      * @param commonPartName
809      * @param commonPartFileName
810      * @return
811      * @throws Exception
812      */
813     private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
814             String commonPartFileName) throws Exception {
815
816         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
817         String stringObject = getXmlDocumentAsString(commonPartFileName);
818         if (logger.isDebugEnabled()) {
819             logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
820         }
821         PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
822         commonPart.setLabel(commonPartName);
823
824         return multipart;
825
826     }
827
828     // FIXME: This duplicates code in read(), and should be consolidated.
829     // This is an expedient to support reading and verifying the contents
830     // of resources that have been created from test data XML files.
831     private AcquisitionsCommon readAcquisitionCommonPart(String csid)
832         throws Exception {
833
834         String testName = "readAcquisitionCommonPart";
835
836         setupRead();
837
838         // Submit the request to the service and store the response.
839         AcquisitionClient client = new AcquisitionClient();
840         ClientResponse<String> res = client.read(csid);
841         AcquisitionsCommon acquisition = null;
842         try {
843                 // Check the status code of the response: does it match
844                 // the expected response(s)?
845                 assertStatusCode(res, testName);
846                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
847         
848                 if (logger.isDebugEnabled()) {
849                     logger.debug(testName + ": Reading Common part ...");
850                 }
851                 acquisition = (AcquisitionsCommon) extractPart(input,
852                         client.getCommonPartName(), AcquisitionsCommon.class);
853                 Assert.assertNotNull(acquisition);
854         } finally {
855                 if (res != null) {
856                 res.releaseConnection();
857             }
858         }
859
860         return acquisition;
861      }
862
863
864         @Override
865         protected PoxPayloadOut createInstance(String commonPartName,
866                         String identifier) {
867                 // TODO Auto-generated method stub
868                 return null;
869         }
870
871         @Override
872         protected AcquisitionsCommon updateInstance(
873                         AcquisitionsCommon commonPartObject) {
874                 // TODO Auto-generated method stub
875                 return null;
876         }
877
878         @Override
879         protected void compareUpdatedInstances(AcquisitionsCommon original,
880                         AcquisitionsCommon updated) throws Exception {
881                 // TODO Auto-generated method stub
882                 
883         }
884
885     /*
886      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
887      * refer to this method in their @Test annotation declarations.
888      */
889     @Override
890     @Test(dataProvider = "testName",
891                 dependsOnMethods = {
892                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
893     public void CRUDTests(String testName) {
894         // Do nothing.  Simply here to for a TestNG execution order for our tests
895     }   
896 }
897