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