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