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