]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
3147e8a153846c83614b02e7bba56cf789fbf6ee
[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         AbstractCommonList list = res.getEntity();
399         int statusCode = res.getStatus();
400
401         // Check the status code of the response: does it match
402         // the expected response(s)?
403         if(logger.isDebugEnabled()){
404             logger.debug(testName + ": status = " + statusCode);
405         }
406         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
407                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
408         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
409
410         // Optionally output additional data about list members for debugging.
411         if(logger.isTraceEnabled()){
412                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
413         }
414
415     }
416     
417     // Failure outcomes
418     // None at present.
419
420     // ---------------------------------------------------------------
421     // CRUD tests : UPDATE tests
422     // ---------------------------------------------------------------
423
424     // Success outcomes
425     /* (non-Javadoc)
426      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
427      */
428     @Override
429     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
430         dependsOnMethods = {"read"})
431     public void update(String testName) throws Exception {
432
433         if (logger.isDebugEnabled()) {
434             logger.debug(testBanner(testName, CLASS_NAME));
435         }
436         
437         // Perform setup.
438         setupUpdate();
439
440         // Retrieve the contents of a resource to update.
441         AcquisitionClient client = new AcquisitionClient();
442         ClientResponse<String> res = client.read(knownResourceId);
443         if(logger.isDebugEnabled()){
444             logger.debug(testName + ": read status = " + res.getStatus());
445         }
446         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
447
448         if(logger.isDebugEnabled()){
449             logger.debug("got object to update with ID: " + knownResourceId);
450         }
451         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
452
453         AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
454                 client.getCommonPartName(), AcquisitionsCommon.class);
455         Assert.assertNotNull(acquisition);
456
457         // Update the content of this resource.
458         acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
459         if(logger.isDebugEnabled()){
460             logger.debug("updated object");
461             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
462         }
463         // Submit the request to the service and store the response.
464         PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
465         PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
466         commonPart.setLabel(client.getCommonPartName());
467
468         res = client.update(knownResourceId, output);
469         int statusCode = res.getStatus();
470         // Check the status code of the response: does it match the expected response(s)?
471         if(logger.isDebugEnabled()){
472             logger.debug(testName + ": status = " + statusCode);
473         }
474         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
475                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
476         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
477
478
479         input = new PoxPayloadIn(res.getEntity());
480         AcquisitionsCommon updatedAcquisition =
481                 (AcquisitionsCommon) extractPart(input,
482                         client.getCommonPartName(), AcquisitionsCommon.class);
483         Assert.assertNotNull(updatedAcquisition);
484
485         Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
486                 acquisition.getAcquisitionReferenceNumber(),
487                 "Data in updated object did not match submitted data.");
488
489     }
490
491     // Failure outcomes
492     // Placeholders until the three tests below can be uncommented.
493     // See Issue CSPACE-401.
494     /* (non-Javadoc)
495      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
496      */
497     @Override
498     public void updateWithEmptyEntityBody(String testName) throws Exception {
499         //Should this really be empty?
500     }
501
502     /* (non-Javadoc)
503      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
504      */
505     @Override
506     public void updateWithMalformedXml(String testName) throws Exception {
507         //Should this really be empty?
508     }
509
510     /* (non-Javadoc)
511      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
512      */
513     @Override
514     public void updateWithWrongXmlSchema(String testName) throws Exception {
515         //Should this really be empty?
516     }
517
518     /*
519     @Override
520     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
521         dependsOnMethods = {"create", "update", "testSubmitRequest"})
522     public void updateWithEmptyEntityBody(String testName) throws Exception {
523     
524         if (logger.isDebugEnabled()) {
525             logger.debug(testBanner(testName, CLASS_NAME));
526         };
527             
528         // Perform setup.
529         setupUpdateWithEmptyEntityBody();
530
531         // Submit the request to the service and store the response.
532         String method = REQUEST_TYPE.httpMethodName();
533         String url = getResourceURL(knownResourceId);
534         String mediaType = MediaType.APPLICATION_XML;
535         final String entity = "";
536         int statusCode = submitRequest(method, url, mediaType, entity);
537
538         // Check the status code of the response: does it match
539         // the expected response(s)?
540         if(logger.isDebugEnabled()){
541             (testName + ": url=" + url + " status=" + statusCode);
542         }
543         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
546         }
547
548     @Override
549     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
550         dependsOnMethods = {"create", "testSubmitRequest"})
551     public void createWithEmptyEntityBody(String testName) throws Exception {
552     
553         if (logger.isDebugEnabled()) {
554             logger.debug(testBanner(testName, CLASS_NAME));
555         };
556         
557         // Perform setup.
558         setupCreateWithEmptyEntityBody();
559
560         // Submit the request to the service and store the response.
561         String method = REQUEST_TYPE.httpMethodName();
562         String url = getServiceRootURL();
563         String mediaType = MediaType.APPLICATION_XML;
564         final String entity = "";
565         int statusCode = submitRequest(method, url, mediaType, entity);
566
567         // Check the status code of the response: does it match
568         // the expected response(s)?
569         if(logger.isDebugEnabled()){
570             logger.debug(testName + ": url=" + url +
571                 " status=" + statusCode);
572         }
573         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
574         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
575         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
576     }
577
578     @Override
579     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
580         dependsOnMethods = {"create", "update", "testSubmitRequest"})
581     public void updateWithMalformedXml(String testName) throws Exception {
582
583         if (logger.isDebugEnabled()) {
584             logger.debug(testBanner(testName, CLASS_NAME));
585         };
586         
587         // Perform setup.
588         setupUpdateWithMalformedXml();
589
590         // Submit the request to the service and store the response.
591         String method = REQUEST_TYPE.httpMethodName();
592         String url = getResourceURL(knownResourceId);
593         final String entity = MALFORMED_XML_DATA;
594         int statusCode = submitRequest(method, url, entity);
595
596         // Check the status code of the response: does it match
597         // the expected response(s)?
598         if(logger.isDebugEnabled()){
599             logger.debug(testName + ": url=" + url +
600                 " status=" + statusCode);
601          }
602         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
605     }
606
607     @Override
608     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
609     public void updateWithWrongXmlSchema(String testName) {
610     
611         if (logger.isDebugEnabled()) {
612             logger.debug(testBanner(testName, CLASS_NAME));
613         };
614         
615         // Perform setup.
616         setupUpdateWithWrongXmlSchema();
617
618         // Submit the request to the service and store the response.
619         String method = REQUEST_TYPE.httpMethodName();
620         String url = getResourceURL(knownResourceId);
621         final String entity = WRONG_XML_SCHEMA_DATA;
622         int statusCode = submitRequest(method, url, entity);
623
624         // Check the status code of the response: does it match
625         // the expected response(s)?
626         if(logger.isDebugEnabled()){
627             logger.debug(testName + ": url=" + url +
628                 " status=" + statusCode);
629          }
630         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
631         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
632         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
633     }
634      */
635     
636     /* (non-Javadoc)
637      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
638      */
639     @Override
640     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
641         dependsOnMethods = {"update", "testSubmitRequest"})
642     public void updateNonExistent(String testName) throws Exception {
643
644         if (logger.isDebugEnabled()) {
645             logger.debug(testBanner(testName, CLASS_NAME));
646         }
647         
648         // Perform setup.
649         setupUpdateNonExistent();
650
651         // Submit the request to the service and store the response.
652         // Note: The ID used in this 'create' call may be arbitrary.
653         // The only relevant ID may be the one used in update(), below.
654         AcquisitionClient client = new AcquisitionClient();
655         PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
656         ClientResponse<String> res =
657             client.update(NON_EXISTENT_ID, multipart);
658         int statusCode = res.getStatus();
659
660         // Check the status code of the response: does it match
661         // the expected response(s)?
662         if(logger.isDebugEnabled()){
663             logger.debug(testName + ": status = " + statusCode);
664         }
665         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
668     }
669
670     // ---------------------------------------------------------------
671     // CRUD tests : DELETE tests
672     // ---------------------------------------------------------------
673     // Success outcomes
674     /* (non-Javadoc)
675      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
676      */
677     @Override
678     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
679         dependsOnMethods = {"create", "read", "update"})
680     public void delete(String testName) throws Exception {
681
682         if (logger.isDebugEnabled()) {
683             logger.debug(testBanner(testName, CLASS_NAME));
684         }
685         
686         // Perform setup.
687         setupDelete();
688
689         // Submit the request to the service and store the response.
690         AcquisitionClient client = new AcquisitionClient();
691         ClientResponse<Response> res = client.delete(knownResourceId);
692         int statusCode = res.getStatus();
693
694         // Check the status code of the response: does it match
695         // the expected response(s)?
696         if(logger.isDebugEnabled()){
697             logger.debug(testName + ": status = " + statusCode);
698         }
699         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702     }
703
704     // Failure outcomes
705     /* (non-Javadoc)
706      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
707      */
708     @Override
709     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
710         dependsOnMethods = {"delete"})
711     public void deleteNonExistent(String testName) throws Exception {
712
713         if (logger.isDebugEnabled()) {
714             logger.debug(testBanner(testName, CLASS_NAME));
715         }
716         
717         // Perform setup.
718         setupDeleteNonExistent();
719
720         // Submit the request to the service and store the response.
721         AcquisitionClient client = new AcquisitionClient();
722         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
723         int statusCode = res.getStatus();
724
725         // Check the status code of the response: does it match
726         // the expected response(s)?
727         if(logger.isDebugEnabled()){
728             logger.debug(testName + ": status = " + statusCode);
729         }
730         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
733     }
734
735     // ---------------------------------------------------------------
736     // Utility tests : tests of code used in tests above
737     // ---------------------------------------------------------------
738     /**
739      * Tests the code for manually submitting data that is used by several
740      * of the methods above.
741      * @throws Exception
742      */
743
744     @Test(dependsOnMethods = {"create", "read"})
745     public void testSubmitRequest() throws Exception {
746         testSubmitRequest(knownResourceId);
747     }
748
749     /**
750      * Test submit request.
751      *
752      * @param resourceId the resource id
753      * @throws Exception the exception
754      */
755     private void testSubmitRequest(String resourceId) throws Exception {
756
757         // Expected status code: 200 OK
758         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
759
760         // Submit the request to the service and store the response.
761         String method = ServiceRequestType.READ.httpMethodName();
762         String url = getResourceURL(resourceId);
763         int statusCode = submitRequest(method, url);
764
765         // Check the status code of the response: does it match
766         // the expected response(s)?
767         if (logger.isDebugEnabled()) {
768             logger.debug("testSubmitRequest: url=" + url
769                     + " status=" + statusCode);
770         }
771         Assert.assertEquals(statusCode, EXPECTED_STATUS);
772
773     }
774
775     // ---------------------------------------------------------------
776     // Utility methods used by tests above
777     // ---------------------------------------------------------------
778
779     @Override
780     protected PoxPayloadOut createInstance(String identifier) {
781         return createAcquisitionInstance(identifier);
782     }
783         
784     /**
785      * Creates the acquisition instance.
786      *
787      * @param identifier the identifier
788      * @return the multipart output
789      */
790     private PoxPayloadOut createAcquisitionInstance(String identifier) {
791         AcquisitionsCommon acquisition = new AcquisitionsCommon();
792         acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-"  + identifier);
793
794         AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
795         List<String> acqSources = acqSourcesList.getAcquisitionSource();
796         // FIXME Use properly formatted refNames for representative acquisition
797         // sources in this example test record. The following are mere placeholders.
798         acqSources.add("Donor Acquisition Source-" + identifier);
799         acqSources.add("Museum Acquisition Source-" + identifier);
800         acquisition.setAcquisitionSources(acqSourcesList);
801
802         AcquisitionDateList acqDatesList = new AcquisitionDateList();
803         List<String> acqDates = acqDatesList.getAcquisitionDate();
804         acqDates.add(CURRENT_DATE_UTC);
805         acqDates.add(CURRENT_DATE_UTC);
806         acquisition.setAcquisitionDates(acqDatesList);
807
808         OwnerList ownersList = new OwnerList();
809         List<String> owners = ownersList.getOwner();
810         // FIXME Use properly formatted refNames for representative owners
811         // in this example test record. The following are mere placeholders.
812         owners.add("First Owner -" + identifier);
813         owners.add("Second Owner-" + identifier);
814         acquisition.setOwners(ownersList);
815
816         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
817         PayloadOutputPart commonPart = multipart.addPart(acquisition,
818             MediaType.APPLICATION_XML_TYPE);
819         commonPart.setLabel(new AcquisitionClient().getCommonPartName());
820
821         if(logger.isDebugEnabled()){
822             logger.debug("to be created, acquisition common");
823             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
824         }
825         return multipart;
826     }
827
828     // FIXME: The following methods might be made generic and moved to a common package.
829
830     /**
831      * Retrives an XML document from the given file, and uses
832      * the JAXB unmarshaller to create a Java object representation
833      * and ultimately a multipart payload that can be submitted in
834      * a create or update request.
835      *
836      * @param commonPartName
837      * @param commonPartFileName
838      * @return
839      * @throws Exception
840      */
841     private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
842             String commonPartFileName) throws Exception {
843
844         AcquisitionsCommon acquisition =
845                 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
846                 commonPartFileName);
847         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
848         PayloadOutputPart commonPart = multipart.addPart(acquisition,
849                 MediaType.APPLICATION_XML_TYPE);
850         commonPart.setLabel(commonPartName);
851
852         if (logger.isDebugEnabled()) {
853             logger.debug(testName + " to be created, acquisitions common");
854             logger.debug(objectAsXmlString(acquisition,
855                     AcquisitionsCommon.class));
856         }
857         return multipart;
858
859     }
860
861     /**
862      * Creates a record / resource from the data in an XML file.
863      *
864      * @param testName the test name
865      * @param fileName the file name
866      * @param useJaxb the use jaxb
867      * @return the string
868      * @throws Exception the exception
869      */
870     private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
871
872         // Perform setup.
873         setupCreate();
874
875         PoxPayloadOut multipart = null;
876
877         AcquisitionClient client = new AcquisitionClient();
878         if (useJaxb) {
879             multipart = createAcquisitionInstanceFromXml(testName,
880                     client.getCommonPartName(), fileName);
881         } else {
882
883             multipart = createAcquisitionInstanceFromRawXml(testName,
884                     client.getCommonPartName(), fileName);
885         }
886         ClientResponse<Response> res = client.create(multipart);
887         int statusCode = res.getStatus();
888
889         if (logger.isDebugEnabled()) {
890             logger.debug(testName + ": status = " + statusCode);
891         }
892         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
893                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
894         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
895         String newId = extractId(res);
896         allResourceIdsCreated.add(newId);
897         return newId;
898     }
899
900      /**
901      * Returns a multipart payload that can be submitted with a
902      * create or update request, by reading from an XML file.
903      *
904      * @param commonPartName
905      * @param commonPartFileName
906      * @return
907      * @throws Exception
908      */
909     private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
910             String commonPartFileName) throws Exception {
911
912         PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
913         String stringObject = getXmlDocumentAsString(commonPartFileName);
914         if (logger.isDebugEnabled()) {
915             logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
916         }
917         PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
918         commonPart.setLabel(commonPartName);
919
920         return multipart;
921
922     }
923
924     // FIXME: This duplicates code in read(), and should be consolidated.
925     // This is an expedient to support reading and verifying the contents
926     // of resources that have been created from test data XML files.
927     private AcquisitionsCommon readAcquisitionCommonPart(String csid)
928         throws Exception {
929
930         String testName = "readAcquisitionCommonPart";
931
932         setupRead();
933
934         // Submit the request to the service and store the response.
935         AcquisitionClient client = new AcquisitionClient();
936         ClientResponse<String> res = client.read(csid);
937         int statusCode = res.getStatus();
938
939         // Check the status code of the response: does it match
940         // the expected response(s)?
941         if (logger.isDebugEnabled()) {
942             logger.debug(testName + ": status = " + statusCode);
943         }
944         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
945                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
946         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
947
948         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
949
950         if (logger.isDebugEnabled()) {
951             logger.debug(testName + ": Reading Common part ...");
952         }
953         AcquisitionsCommon acquisition =
954                 (AcquisitionsCommon) extractPart(input,
955                 client.getCommonPartName(), AcquisitionsCommon.class);
956         Assert.assertNotNull(acquisition);
957
958         return acquisition;
959      }
960
961 }
962