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