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