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