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