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