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