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