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