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