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