]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e1b84e226c33147fa4fb7f279e1612f05f873316
[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.AcquisitionSourceList;
37 import org.jboss.resteasy.client.ClientResponse;
38
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
41 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
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     /* (non-Javadoc)
66      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
67      */
68     @Override
69     protected CollectionSpaceClient getClientInstance() {
70         return new AcquisitionClient();
71     }
72     
73     /* (non-Javadoc)
74      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
75      */
76     @Override
77         protected AbstractCommonList getAbstractCommonList(
78                         ClientResponse<AbstractCommonList> response) {
79         return response.getEntity(AcquisitionsCommonList.class);
80     }
81
82     // ---------------------------------------------------------------
83     // CRUD tests : CREATE tests
84     // ---------------------------------------------------------------
85     // Success outcomes
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
88      */
89     @Override
90     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
91     public void create(String testName) throws Exception {
92
93         if (logger.isDebugEnabled()) {
94             logger.debug(testBanner(testName, CLASS_NAME));
95         }
96         
97         // Perform setup, such as initializing the type of service request
98         // (e.g. CREATE, DELETE), its valid and expected status codes, and
99         // its associated HTTP method name (e.g. POST, DELETE).
100         setupCreate();
101
102         // Submit the request to the service and store the response.
103         String identifier = createIdentifier();
104
105         AcquisitionClient client = new AcquisitionClient();
106         MultipartOutput multipart = createAcquisitionInstance(identifier);
107         ClientResponse<Response> res = client.create(multipart);
108
109         int statusCode = res.getStatus();
110
111         // Check the status code of the response: does it match
112         // the expected response(s)?
113         //
114         // Specifically:
115         // Does it fall within the set of valid status codes?
116         // Does it exactly match the expected status code?
117         if(logger.isDebugEnabled()){
118             logger.debug(testName + ": status = " + statusCode);
119         }
120         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
121                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
122         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
123
124         // Store the ID returned from the first resource created
125         // for additional tests below.
126         if (knownResourceId == null){
127             knownResourceId = extractId(res);
128             if (logger.isDebugEnabled()) {
129                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
130             }
131         }
132         
133         // Store the IDs from every resource created by tests,
134         // so they can be deleted after tests have been run.
135         allResourceIdsCreated.add(extractId(res));
136     }
137
138     /* (non-Javadoc)
139      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
140      */
141     @Override
142     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
143        dependsOnMethods = {"create"})
144     public void createList(String testName) throws Exception {
145         for(int i = 0; i < 3; i++){
146             create(testName);
147         }
148     }
149
150     // Failure outcomes
151     // Placeholders until the three tests below can be uncommented.
152     // See Issue CSPACE-401.
153     /* (non-Javadoc)
154      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
155      */
156     @Override
157     public void createWithEmptyEntityBody(String testName) throws Exception {
158         //Should this really be empty?
159     }
160
161     /* (non-Javadoc)
162      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
163      */
164     @Override
165     public void createWithMalformedXml(String testName) throws Exception {
166         //Should this really be empty?
167     }
168
169     /* (non-Javadoc)
170      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
171      */
172     @Override
173     public void createWithWrongXmlSchema(String testName) throws Exception {
174         //Should this really be empty?
175     }
176
177     /*
178     @Override
179     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
180         dependsOnMethods = {"create", "testSubmitRequest"})
181     public void createWithMalformedXml(String testName) throws Exception {
182     
183         if (logger.isDebugEnabled()) {
184             logger.debug(testBanner(testName, CLASS_NAME));
185         };
186             
187         // Perform setup.
188         setupCreateWithMalformedXml();
189
190         // Submit the request to the service and store the response.
191         String method = REQUEST_TYPE.httpMethodName();
192         String url = getServiceRootURL();
193         final String entity = MALFORMED_XML_DATA; // Constant from base class.
194         int statusCode = submitRequest(method, url, entity);
195
196         // Check the status code of the response: does it match
197         // the expected response(s)?
198         if(logger.isDebugEnabled()){
199             logger.debug(testName + ": url=" + url +
200                 " status=" + statusCode);
201          }
202         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
203         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
204         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
205     }
206
207     @Override
208     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
209         dependsOnMethods = {"create", "testSubmitRequest"})
210     public void createWithWrongXmlSchema(String testName) throws Exception {
211     
212         if (logger.isDebugEnabled()) {
213             logger.debug(testBanner(testName, CLASS_NAME));
214         };
215         
216         // Perform setup.
217         setupCreateWithWrongXmlSchema();
218
219         // Submit the request to the service and store the response.
220         String method = REQUEST_TYPE.httpMethodName();
221         String url = getServiceRootURL();
222         final String entity = WRONG_XML_SCHEMA_DATA;
223         int statusCode = submitRequest(method, url, entity);
224
225         // Check the status code of the response: does it match
226         // the expected response(s)?
227         if(logger.isDebugEnabled()){
228             logger.debug(testName + ": url=" + url +
229                 " status=" + statusCode);
230          }
231         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
232         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
233         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
234     }
235      */
236
237     // ---------------------------------------------------------------
238     // CRUD tests : READ tests
239     // ---------------------------------------------------------------
240     // Success outcomes
241     /* (non-Javadoc)
242      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
243      */
244     @Override
245     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
246         dependsOnMethods = {"create"})
247     public void read(String testName) throws Exception {
248
249         if (logger.isDebugEnabled()) {
250             logger.debug(testBanner(testName, CLASS_NAME));
251         }
252         
253         // Perform setup.
254         setupRead();
255
256         AcquisitionClient client = new AcquisitionClient();
257
258         // Submit the request to the service and store the response.
259         ClientResponse<MultipartInput> res = client.read(knownResourceId);
260         int statusCode = res.getStatus();
261
262         // Check the status code of the response: does it match
263         // the expected response(s)?
264         if(logger.isDebugEnabled()){
265             logger.debug(testName + ": status = " + statusCode);
266         }
267         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
270
271         MultipartInput input = (MultipartInput) res.getEntity();
272         AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
273                 client.getCommonPartName(), AcquisitionsCommon.class);
274         Assert.assertNotNull(acquisitionObject);
275
276         // Verify the number and contents of values in repeatable fields,
277         // as created in the instance record used for testing.
278         List<String> acqSources =
279                 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
280         Assert.assertTrue(acqSources.size() > 0);
281         Assert.assertNotNull(acqSources.get(0));
282
283         List<String> acqDates =
284                 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
285         Assert.assertTrue(acqDates.size() > 0);
286         Assert.assertNotNull(acqDates.get(0));
287
288     }
289
290     // Failure outcomes
291     /* (non-Javadoc)
292      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
293      */
294     @Override
295     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
296         dependsOnMethods = {"read"})
297     public void readNonExistent(String testName) throws Exception {
298
299         if (logger.isDebugEnabled()) {
300             logger.debug(testBanner(testName, CLASS_NAME));
301         }
302
303         // Perform setup.
304         setupReadNonExistent();
305
306         // Submit the request to the service and store the response.
307         AcquisitionClient client = new AcquisitionClient();
308         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
309         int statusCode = res.getStatus();
310
311         // Check the status code of the response: does it match
312         // the expected response(s)?
313         if(logger.isDebugEnabled()){
314             logger.debug(testName + ": status = " + statusCode);
315         }
316         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
317                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
318         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
319     }
320
321     // ---------------------------------------------------------------
322     // CRUD tests : READ_LIST tests
323     // ---------------------------------------------------------------
324     // Success outcomes
325     /* (non-Javadoc)
326      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
327      */
328     @Override
329     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
330         dependsOnMethods = {"createList", "read"})
331     public void readList(String testName) throws Exception {
332
333         if (logger.isDebugEnabled()) {
334             logger.debug(testBanner(testName, CLASS_NAME));
335         }
336         
337         // Perform setup.
338         setupReadList();
339
340         // Submit the request to the service and store the response.
341         AcquisitionClient client = new AcquisitionClient();
342         ClientResponse<AcquisitionsCommonList> res = client.readList();
343         AcquisitionsCommonList list = res.getEntity();
344         int statusCode = res.getStatus();
345
346         // Check the status code of the response: does it match
347         // the expected response(s)?
348         if(logger.isDebugEnabled()){
349             logger.debug(testName + ": status = " + statusCode);
350         }
351         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
352                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
353         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
354
355         // Optionally output additional data about list members for debugging.
356         boolean iterateThroughList = false;
357         if(iterateThroughList && logger.isDebugEnabled()){
358             List<AcquisitionsCommonList.AcquisitionListItem> items =
359                     list.getAcquisitionListItem();
360             int i = 0;
361             for(AcquisitionsCommonList.AcquisitionListItem item : items){
362                 logger.debug(testName + ": list-item[" + i + "] csid=" +
363                     item.getCsid());
364                 logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
365                     item.getAcquisitionReferenceNumber());
366                 logger.debug(testName + ": list-item[" + i + "] acquisitionSources:");
367                 AcquisitionSourceList acqSource = item.getAcquisitionSources();
368                 for (String acquisitionSource : acqSource.getAcquisitionSource()) {
369                     logger.debug("acquisitionSource=" + acquisitionSource);
370                 }
371                 logger.debug(testName + ": list-item[" + i + "] URI=" +
372                     item.getUri());
373                 i++;
374             }
375         }
376
377     }
378
379     // Failure outcomes
380     // None at present.
381
382     // ---------------------------------------------------------------
383     // CRUD tests : UPDATE tests
384     // ---------------------------------------------------------------
385
386     // Success outcomes
387     /* (non-Javadoc)
388      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
389      */
390     @Override
391     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
392         dependsOnMethods = {"read"})
393     public void update(String testName) throws Exception {
394
395         if (logger.isDebugEnabled()) {
396             logger.debug(testBanner(testName, CLASS_NAME));
397         }
398         
399         // Perform setup.
400         setupUpdate();
401
402         // Retrieve the contents of a resource to update.
403         AcquisitionClient client = new AcquisitionClient();
404         ClientResponse<MultipartInput> res = client.read(knownResourceId);
405         if(logger.isDebugEnabled()){
406             logger.debug(testName + ": read status = " + res.getStatus());
407         }
408         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
409
410         if(logger.isDebugEnabled()){
411             logger.debug("got object to update with ID: " + knownResourceId);
412         }
413         MultipartInput input = (MultipartInput) res.getEntity();
414
415         AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
416                 client.getCommonPartName(), AcquisitionsCommon.class);
417         Assert.assertNotNull(acquisition);
418
419         // Update the content of this resource.
420         acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
421         if(logger.isDebugEnabled()){
422             logger.debug("updated object");
423             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
424         }
425         // Submit the request to the service and store the response.
426         MultipartOutput output = new MultipartOutput();
427         OutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
428         commonPart.getHeaders().add("label", client.getCommonPartName());
429
430         res = client.update(knownResourceId, output);
431         int statusCode = res.getStatus();
432         // Check the status code of the response: does it match the expected response(s)?
433         if(logger.isDebugEnabled()){
434             logger.debug(testName + ": status = " + statusCode);
435         }
436         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
437                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
438         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
439
440
441         input = (MultipartInput) res.getEntity();
442         AcquisitionsCommon updatedAcquisition =
443                 (AcquisitionsCommon) extractPart(input,
444                         client.getCommonPartName(), AcquisitionsCommon.class);
445         Assert.assertNotNull(updatedAcquisition);
446
447         Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
448                 acquisition.getAcquisitionReferenceNumber(),
449                 "Data in updated object did not match submitted data.");
450
451     }
452
453     // Failure outcomes
454     // Placeholders until the three tests below can be uncommented.
455     // See Issue CSPACE-401.
456     /* (non-Javadoc)
457      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
458      */
459     @Override
460     public void updateWithEmptyEntityBody(String testName) throws Exception {
461         //Should this really be empty?
462     }
463
464     /* (non-Javadoc)
465      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
466      */
467     @Override
468     public void updateWithMalformedXml(String testName) throws Exception {
469         //Should this really be empty?
470     }
471
472     /* (non-Javadoc)
473      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
474      */
475     @Override
476     public void updateWithWrongXmlSchema(String testName) throws Exception {
477         //Should this really be empty?
478     }
479
480     /*
481     @Override
482     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
483         dependsOnMethods = {"create", "update", "testSubmitRequest"})
484     public void updateWithEmptyEntityBody(String testName) throws Exception {
485     
486         if (logger.isDebugEnabled()) {
487             logger.debug(testBanner(testName, CLASS_NAME));
488         };
489             
490         // Perform setup.
491         setupUpdateWithEmptyEntityBody();
492
493         // Submit the request to the service and store the response.
494         String method = REQUEST_TYPE.httpMethodName();
495         String url = getResourceURL(knownResourceId);
496         String mediaType = MediaType.APPLICATION_XML;
497         final String entity = "";
498         int statusCode = submitRequest(method, url, mediaType, entity);
499
500         // Check the status code of the response: does it match
501         // the expected response(s)?
502         if(logger.isDebugEnabled()){
503             (testName + ": url=" + url + " status=" + statusCode);
504         }
505         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
506         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
507         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
508         }
509
510     @Override
511     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
512         dependsOnMethods = {"create", "testSubmitRequest"})
513     public void createWithEmptyEntityBody(String testName) throws Exception {
514     
515         if (logger.isDebugEnabled()) {
516             logger.debug(testBanner(testName, CLASS_NAME));
517         };
518         
519         // Perform setup.
520         setupCreateWithEmptyEntityBody();
521
522         // Submit the request to the service and store the response.
523         String method = REQUEST_TYPE.httpMethodName();
524         String url = getServiceRootURL();
525         String mediaType = MediaType.APPLICATION_XML;
526         final String entity = "";
527         int statusCode = submitRequest(method, url, mediaType, entity);
528
529         // Check the status code of the response: does it match
530         // the expected response(s)?
531         if(logger.isDebugEnabled()){
532             logger.debug(testName + ": url=" + url +
533                 " status=" + statusCode);
534         }
535         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
536         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
537         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
538     }
539
540     @Override
541     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
542         dependsOnMethods = {"create", "update", "testSubmitRequest"})
543     public void updateWithMalformedXml(String testName) throws Exception {
544
545         if (logger.isDebugEnabled()) {
546             logger.debug(testBanner(testName, CLASS_NAME));
547         };
548         
549         // Perform setup.
550         setupUpdateWithMalformedXml();
551
552         // Submit the request to the service and store the response.
553         String method = REQUEST_TYPE.httpMethodName();
554         String url = getResourceURL(knownResourceId);
555         final String entity = MALFORMED_XML_DATA;
556         int statusCode = submitRequest(method, url, entity);
557
558         // Check the status code of the response: does it match
559         // the expected response(s)?
560         if(logger.isDebugEnabled()){
561             logger.debug(testName + ": url=" + url +
562                 " status=" + statusCode);
563          }
564         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567     }
568
569     @Override
570     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
571     public void updateWithWrongXmlSchema(String testName) {
572     
573         if (logger.isDebugEnabled()) {
574             logger.debug(testBanner(testName, CLASS_NAME));
575         };
576         
577         // Perform setup.
578         setupUpdateWithWrongXmlSchema();
579
580         // Submit the request to the service and store the response.
581         String method = REQUEST_TYPE.httpMethodName();
582         String url = getResourceURL(knownResourceId);
583         final String entity = WRONG_XML_SCHEMA_DATA;
584         int statusCode = submitRequest(method, url, entity);
585
586         // Check the status code of the response: does it match
587         // the expected response(s)?
588         if(logger.isDebugEnabled()){
589             logger.debug(testName + ": url=" + url +
590                 " status=" + statusCode);
591          }
592         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
593         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
594         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
595     }
596      */
597     
598     /* (non-Javadoc)
599      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
600      */
601     @Override
602     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
603         dependsOnMethods = {"update", "testSubmitRequest"})
604     public void updateNonExistent(String testName) throws Exception {
605
606         if (logger.isDebugEnabled()) {
607             logger.debug(testBanner(testName, CLASS_NAME));
608         }
609         
610         // Perform setup.
611         setupUpdateNonExistent();
612
613         // Submit the request to the service and store the response.
614         // Note: The ID used in this 'create' call may be arbitrary.
615         // The only relevant ID may be the one used in update(), below.
616         AcquisitionClient client = new AcquisitionClient();
617         MultipartOutput multipart = createAcquisitionInstance(NON_EXISTENT_ID);
618         ClientResponse<MultipartInput> res =
619             client.update(NON_EXISTENT_ID, multipart);
620         int statusCode = res.getStatus();
621
622         // Check the status code of the response: does it match
623         // the expected response(s)?
624         if(logger.isDebugEnabled()){
625             logger.debug(testName + ": status = " + statusCode);
626         }
627         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
628                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
629         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
630     }
631
632     // ---------------------------------------------------------------
633     // CRUD tests : DELETE tests
634     // ---------------------------------------------------------------
635     // Success outcomes
636     /* (non-Javadoc)
637      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
638      */
639     @Override
640     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
641         dependsOnMethods = {"create", "read", "update"})
642     public void delete(String testName) throws Exception {
643
644         if (logger.isDebugEnabled()) {
645             logger.debug(testBanner(testName, CLASS_NAME));
646         }
647         
648         // Perform setup.
649         setupDelete();
650
651         // Submit the request to the service and store the response.
652         AcquisitionClient client = new AcquisitionClient();
653         ClientResponse<Response> res = client.delete(knownResourceId);
654         int statusCode = res.getStatus();
655
656         // Check the status code of the response: does it match
657         // the expected response(s)?
658         if(logger.isDebugEnabled()){
659             logger.debug(testName + ": status = " + statusCode);
660         }
661         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
662                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
663         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
664     }
665
666     // Failure outcomes
667     /* (non-Javadoc)
668      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
669      */
670     @Override
671     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
672         dependsOnMethods = {"delete"})
673     public void deleteNonExistent(String testName) throws Exception {
674
675         if (logger.isDebugEnabled()) {
676             logger.debug(testBanner(testName, CLASS_NAME));
677         }
678         
679         // Perform setup.
680         setupDeleteNonExistent();
681
682         // Submit the request to the service and store the response.
683         AcquisitionClient client = new AcquisitionClient();
684         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
685         int statusCode = res.getStatus();
686
687         // Check the status code of the response: does it match
688         // the expected response(s)?
689         if(logger.isDebugEnabled()){
690             logger.debug(testName + ": status = " + statusCode);
691         }
692         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
693                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
694         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
695     }
696
697     // ---------------------------------------------------------------
698     // Utility tests : tests of code used in tests above
699     // ---------------------------------------------------------------
700     /**
701      * Tests the code for manually submitting data that is used by several
702      * of the methods above.
703      * 
704      * @throws Exception 
705      */
706     @Test(dependsOnMethods = {"create", "read"})
707     public void testSubmitRequest() throws Exception {
708
709         // Perform setup.
710         setupRead();
711
712         // Submit the request to the service and store the response.
713         String method = ServiceRequestType.READ.httpMethodName();
714         String url = getResourceURL(knownResourceId);
715         int statusCode = submitRequest(method, url);
716
717         // Check the status code of the response: does it match
718         // the expected response(s)?
719         if(logger.isDebugEnabled()){
720             logger.debug("testSubmitRequest: url=" + url +
721                 " status=" + statusCode);
722         }
723         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724
725     }
726
727     // ---------------------------------------------------------------
728     // Utility methods used by tests above
729     // ---------------------------------------------------------------
730     /* (non-Javadoc)
731      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
732      */
733     @Override
734     public String getServicePathComponent() {
735         return new AcquisitionClient().getServicePathComponent();
736     }
737
738
739     /**
740      * Creates the acquisition instance.
741      *
742      * @param identifier the identifier
743      * @return the multipart output
744      */
745     private MultipartOutput createAcquisitionInstance(String identifier) {
746         AcquisitionsCommon acquisition = new AcquisitionsCommon();
747         acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-"  + identifier);
748         AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
749         List<String> acqSources = acqSourcesList.getAcquisitionSource();
750         // FIXME Use properly formatted refNames for representative acquisition
751         // sources in this example test record. The following are mere placeholders.
752         acqSources.add("Donor Acquisition Source-" + identifier);
753         acqSources.add("Museum Acquisition Source-" + identifier);
754         acquisition.setAcquisitionSources(acqSourcesList);
755         AcquisitionDateList acqDatesList = new AcquisitionDateList();
756         List<String> acqDates = acqDatesList.getAcquisitionDate();
757         // FIXME Use properly timestamps for representative acquisition
758         // dates in this example test record. The following are mere placeholders.
759         acqDates.add("First Acquisition Date -" + identifier);
760         acqDates.add("Second Acquisition Date-" + identifier);
761         acquisition.setAcquisitionDates(acqDatesList);
762         MultipartOutput multipart = new MultipartOutput();
763         OutputPart commonPart = multipart.addPart(acquisition,
764             MediaType.APPLICATION_XML_TYPE);
765         commonPart.getHeaders().add("label", new AcquisitionClient().getCommonPartName());
766
767         if(logger.isDebugEnabled()){
768             logger.debug("to be created, acquisition common");
769             logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
770         }
771         return multipart;
772     }
773 }
774