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