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