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