]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b8595a3a1fe7d83689ab4123d2385e60f62a3471
[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
41 import org.jboss.resteasy.client.ClientResponse;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * LoaninServiceTest, carries out tests against a
50  * deployed and running Loanin (aka Loans In) Service.
51  *
52  * $LastChangedRevision$
53  * $LastChangedDate$
54  */
55 public class LoaninServiceTest extends AbstractServiceTestImpl {
56
57    /** The logger. */
58     private final String CLASS_NAME = LoaninServiceTest.class.getName();
59     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60
61     // Instance variables specific to this test.
62     /** The service path component. */
63     final String SERVICE_NAME = "loansin";
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(AbstractCommonList.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         PoxPayloadOut 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         LoaninClient client = new LoaninClient();
297         ClientResponse<String> res = client.read(knownResourceId);
298         PoxPayloadIn input = null;
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                 input = new PoxPayloadIn(res.getEntity());
311         } finally {
312                 res.releaseConnection();
313         }
314
315         // Get the common part of the response and verify that it is not null.
316         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
317         LoansinCommon loaninCommon = null;
318         if (payloadInputPart != null) {
319                 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
320         }
321         Assert.assertNotNull(loaninCommon);
322
323         // Check selected fields.
324         LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
325         Assert.assertNotNull(lenderGroupList);
326         List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
327         Assert.assertNotNull(lenderGroups);
328         Assert.assertTrue(lenderGroups.size() > 0);
329         String lender = lenderGroups.get(0).getLender();
330         Assert.assertEquals(lender, LENDER_REF_NAME);
331
332         if(logger.isDebugEnabled()){
333             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
334                     + "UTF-8 data received=" + loaninCommon.getLoanInNote());
335     }
336
337         Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
338                 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
339                 + "' does not match expected data '" + getUTF8DataFragment());
340
341     }
342
343     // Failure outcomes
344     /* (non-Javadoc)
345      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
346      */
347     @Override
348     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349         dependsOnMethods = {"read"})
350     public void readNonExistent(String testName) throws Exception {
351
352         if (logger.isDebugEnabled()) {
353             logger.debug(testBanner(testName, CLASS_NAME));
354         }
355         // Perform setup.
356         setupReadNonExistent();
357
358         // Submit the request to the service and store the response.
359         LoaninClient client = new LoaninClient();
360         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
361         try {
362                 int statusCode = res.getStatus();
363         
364                 // Check the status code of the response: does it match
365                 // the expected response(s)?
366                 if(logger.isDebugEnabled()){
367                     logger.debug(testName + ": status = " + statusCode);
368                 }
369                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
370                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
371                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
372         } finally {
373                 res.releaseConnection();
374         }
375     }
376
377     // ---------------------------------------------------------------
378     // CRUD tests : READ_LIST tests
379     // ---------------------------------------------------------------
380     // Success outcomes
381     /* (non-Javadoc)
382      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
383      */
384     @Override
385     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
386         dependsOnMethods = {"createList", "read"})
387     public void readList(String testName) throws Exception {
388         
389         if (logger.isDebugEnabled()) {
390             logger.debug(testBanner(testName, CLASS_NAME));
391         }
392         // Perform setup.
393         setupReadList();
394
395         // Submit the request to the service and store the response.
396         AbstractCommonList list = null;
397         LoaninClient client = new LoaninClient();
398         ClientResponse<AbstractCommonList> res = client.readList();
399         try {
400                 int statusCode = res.getStatus();
401         
402                 // Check the status code of the response: does it match
403                 // the expected response(s)?
404                 if(logger.isDebugEnabled()){
405                     logger.debug(testName + ": status = " + statusCode);
406                 }
407                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
408                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
409                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
410                 
411                 list = res.getEntity();
412         } finally {
413                 res.releaseConnection();
414         }
415
416         // Optionally output additional data about list members for debugging.
417         boolean iterateThroughList = false;
418         if (iterateThroughList && logger.isDebugEnabled()){
419             List<AbstractCommonList.ListItem> items =
420                     list.getListItem();
421             int i = 0;
422             for(AbstractCommonList.ListItem item : items){
423                 logger.debug(testName + ": list-item[" + i + "] " +
424                         item.toString());
425                 i++;
426             }
427         }
428     }
429
430     // Failure outcomes
431     // None at present.
432     // ---------------------------------------------------------------
433     // CRUD tests : UPDATE tests
434     // ---------------------------------------------------------------
435     // Success outcomes
436     /* (non-Javadoc)
437      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
438      */
439     @Override
440     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
441         dependsOnMethods = {"read"})
442     public void update(String testName) throws Exception {
443
444         if (logger.isDebugEnabled()) {
445             logger.debug(testBanner(testName, CLASS_NAME));
446         }
447         // Perform setup.
448         setupUpdate();
449
450         // Retrieve the contents of a resource to update.
451         LoaninClient client = new LoaninClient();
452         ClientResponse<String> res = client.read(knownResourceId);
453         PoxPayloadIn input = null;
454         try {
455                 if(logger.isDebugEnabled()){
456                     logger.debug(testName + ": read status = " + res.getStatus());
457                 }
458                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
459         
460                 if(logger.isDebugEnabled()){
461                     logger.debug("got object to update with ID: " + knownResourceId);
462                 }
463                 input = new PoxPayloadIn(res.getEntity());
464         } finally {
465                 res.releaseConnection();
466         }
467
468         // Extract the common part from the response.
469         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
470         LoansinCommon loaninCommon = null;
471         if (payloadInputPart != null) {
472                 loaninCommon = (LoansinCommon) payloadInputPart.getBody();
473         }
474         Assert.assertNotNull(loaninCommon);
475
476         // Update the content of this resource.
477         loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
478         loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate());
479         loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
480         if(logger.isDebugEnabled()){
481             logger.debug("to be updated object");
482             logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
483         }
484
485         // Submit the updated common part in an update request to the service
486         // and store the response.
487         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
488         PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
489         commonPart.setLabel(client.getCommonPartName());
490         res = client.update(knownResourceId, output);
491         try {
492                 int statusCode = res.getStatus();
493                 // Check the status code of the response: does it match the expected response(s)?
494                 if(logger.isDebugEnabled()){
495                     logger.debug(testName + ": status = " + statusCode);
496                 }
497                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
498                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
499                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
500                 input = new PoxPayloadIn(res.getEntity());
501         } finally {
502                 res.releaseConnection();
503         }
504
505         // Extract the updated common part from the response.
506         payloadInputPart = input.getPart(client.getCommonPartName());
507         LoansinCommon updatedLoaninCommon = null;
508         if (payloadInputPart != null) {
509                 updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
510         }
511         Assert.assertNotNull(updatedLoaninCommon);
512
513         // Check selected fields in the updated common part.
514         Assert.assertEquals(updatedLoaninCommon.getLoanReturnDate(),
515                 loaninCommon.getLoanReturnDate(),
516                 "Data in updated object did not match submitted data.");
517
518         if(logger.isDebugEnabled()){
519             logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n"
520                     + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote());
521     }
522         Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
523                 "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote()
524                 + "' does not contain expected data '" + getUTF8DataFragment());
525         Assert.assertEquals(updatedLoaninCommon.getLoanInNote(),
526                 loaninCommon.getLoanInNote(),
527                 "Data in updated object did not match submitted data.");
528     }
529
530     // Failure outcomes
531     // Placeholders until the three tests below can be uncommented.
532     // See Issue CSPACE-401.
533     /* (non-Javadoc)
534      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
535      */
536     @Override
537     public void updateWithEmptyEntityBody(String testName) throws Exception {
538         //Should this really be empty?
539     }
540     
541     /* (non-Javadoc)
542      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
543      */
544     @Override
545     public void updateWithMalformedXml(String testName) throws Exception {
546         //Should this really be empty?
547     }
548     
549     /* (non-Javadoc)
550      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
551      */
552     @Override
553     public void updateWithWrongXmlSchema(String testName) throws Exception {
554         //Should this really be empty?
555     }
556
557     /*
558     @Override
559     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
560         dependsOnMethods = {"create", "update", "testSubmitRequest"})
561     public void updateWithEmptyEntityBody(String testName) throws Exception {
562
563         if (logger.isDebugEnabled()) {
564             logger.debug(testBanner(testName, CLASS_NAME));
565         }
566         // Perform setup.
567         setupUpdateWithEmptyEntityBody();
568
569         // Submit the request to the service and store the response.
570         String method = REQUEST_TYPE.httpMethodName();
571         String url = getResourceURL(knownResourceId);
572         String mediaType = MediaType.APPLICATION_XML;
573         final String entity = "";
574         int statusCode = submitRequest(method, url, mediaType, entity);
575
576         // Check the status code of the response: does it match
577         // the expected response(s)?
578         if(logger.isDebugEnabled()){
579             logger.debug(testName + ": url=" + url +
580                 " status=" + statusCode);
581          }
582         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
585     }
586
587     @Override
588     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
589         dependsOnMethods = {"create", "update", "testSubmitRequest"})
590     public void updateWithMalformedXml(String testName) throws Exception {
591
592         if (logger.isDebugEnabled()) {
593             logger.debug(testBanner(testName, CLASS_NAME));
594         }
595         // Perform setup.
596         setupUpdateWithMalformedXml();
597
598         // Submit the request to the service and store the response.
599         String method = REQUEST_TYPE.httpMethodName();
600         String url = getResourceURL(knownResourceId);
601         String mediaType = MediaType.APPLICATION_XML;
602         final String entity = MALFORMED_XML_DATA;
603         int statusCode = submitRequest(method, url, mediaType, entity);
604
605         // Check the status code of the response: does it match
606         // the expected response(s)?
607         if(logger.isDebugEnabled()){
608             logger.debug(testName + ": url=" + url +
609              " status=" + statusCode);
610          }
611         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614     }
615
616     @Override
617     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
618         dependsOnMethods = {"create", "update", "testSubmitRequest"})
619     public void updateWithWrongXmlSchema(String testName) throws Exception {
620
621         if (logger.isDebugEnabled()) {
622             logger.debug(testBanner(testName, CLASS_NAME));
623         }
624         // Perform setup.
625         setupUpdateWithWrongXmlSchema();
626
627         // Submit the request to the service and store the response.
628         String method = REQUEST_TYPE.httpMethodName();
629         String url = getResourceURL(knownResourceId);
630         String mediaType = MediaType.APPLICATION_XML;
631         final String entity = WRONG_XML_SCHEMA_DATA;
632         int statusCode = submitRequest(method, url, mediaType, entity);
633
634         // Check the status code of the response: does it match
635         // the expected response(s)?
636         if(logger.isDebugEnabled()){
637             logger.debug(testName + ": url=" + url +
638             " status=" + statusCode);
639          }
640         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
643     }
644      */
645
646     /* (non-Javadoc)
647      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
648      */
649     @Override
650     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
651         dependsOnMethods = {"update", "testSubmitRequest"})
652     public void updateNonExistent(String testName) throws Exception {
653
654         if (logger.isDebugEnabled()) {
655             logger.debug(testBanner(testName, CLASS_NAME));
656         }
657         // Perform setup.
658         setupUpdateNonExistent();
659
660         // Submit the request to the service and store the response.
661         // Note: The ID used in this 'create' call may be arbitrary.
662         // The only relevant ID may be the one used in update(), below.
663         LoaninClient client = new LoaninClient();
664         PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
665         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
666         try {
667                 int statusCode = res.getStatus();
668
669                 // Check the status code of the response: does it match
670                 // the expected response(s)?
671                 if(logger.isDebugEnabled()){
672                     logger.debug(testName + ": status = " + statusCode);
673                 }
674                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677         } finally {
678                 res.releaseConnection();
679         }
680     }
681
682     // ---------------------------------------------------------------
683     // CRUD tests : DELETE tests
684     // ---------------------------------------------------------------
685     // Success outcomes
686     /* (non-Javadoc)
687      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
688      */
689     @Override
690     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
691         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
692     public void delete(String testName) throws Exception {
693
694         if (logger.isDebugEnabled()) {
695             logger.debug(testBanner(testName, CLASS_NAME));
696         }
697         // Perform setup.
698         setupDelete();
699
700         // Submit the request to the service and store the response.
701         LoaninClient client = new LoaninClient();
702         ClientResponse<Response> res = client.delete(knownResourceId);
703         try {
704                 int statusCode = res.getStatus();
705         
706                 // Check the status code of the response: does it match
707                 // the expected response(s)?
708                 if(logger.isDebugEnabled()){
709                     logger.debug(testName + ": status = " + statusCode);
710                 }
711                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
712                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
713                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
714         } finally {
715                 res.releaseConnection();
716         }
717     }
718
719     // Failure outcomes
720     /* (non-Javadoc)
721      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
722      */
723     @Override
724     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
725         dependsOnMethods = {"delete"})
726     public void deleteNonExistent(String testName) throws Exception {
727         
728         if (logger.isDebugEnabled()) {
729             logger.debug(testBanner(testName, CLASS_NAME));
730         }
731         // Perform setup.
732         setupDeleteNonExistent();
733
734         // Submit the request to the service and store the response.
735         LoaninClient client = new LoaninClient();
736         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
737         try {
738                 int statusCode = res.getStatus();
739         
740                 // Check the status code of the response: does it match
741                 // the expected response(s)?
742                 if(logger.isDebugEnabled()){
743                     logger.debug(testName + ": status = " + statusCode);
744                 }
745                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
746                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
747                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
748         } finally {
749                 res.releaseConnection();
750         }
751     }
752
753     // ---------------------------------------------------------------
754     // Utility tests : tests of code used in tests above
755     // ---------------------------------------------------------------
756     /**
757      * Tests the code for manually submitting data that is used by several
758      * of the methods above.
759      */
760     @Test(dependsOnMethods = {"create", "read"})
761     public void testSubmitRequest() {
762
763         // Expected status code: 200 OK
764         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
765
766         // Submit the request to the service and store the response.
767         String method = ServiceRequestType.READ.httpMethodName();
768         String url = getResourceURL(knownResourceId);
769         int statusCode = submitRequest(method, url);
770
771         // Check the status code of the response: does it match
772         // the expected response(s)?
773         if(logger.isDebugEnabled()){
774             logger.debug("testSubmitRequest: url=" + url +
775                 " status=" + statusCode);
776         }
777         Assert.assertEquals(statusCode, EXPECTED_STATUS);
778
779     }
780
781     // ---------------------------------------------------------------
782     // Utility methods used by tests above
783     // ---------------------------------------------------------------
784
785     @Override
786     public String getServiceName() {
787         return SERVICE_NAME;
788     }
789
790     /* (non-Javadoc)
791      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
792      */
793     @Override
794     public String getServicePathComponent() {
795         return SERVICE_PATH_COMPONENT;
796     }
797
798     @Override
799     protected PoxPayloadOut createInstance(String identifier) {
800         return createLoaninInstance(identifier);
801     }
802     
803     /**
804      * Creates the loanin instance.
805      *
806      * @param identifier the identifier
807      * @return the multipart output
808      */
809     private PoxPayloadOut createLoaninInstance(String identifier) {
810         return createLoaninInstance(
811                 "loaninNumber-" + identifier,
812                 "returnDate-" + identifier);
813     }
814
815     /**
816      * Creates the loanin instance.
817      *
818      * @param loaninNumber the loanin number
819      * @param returnDate the return date
820      * @return the multipart output
821      */
822     private PoxPayloadOut createLoaninInstance(String loaninNumber,
823                 String returnDate) {
824
825         LoansinCommon loaninCommon = new LoansinCommon();
826         loaninCommon.setLoanInNumber(loaninNumber);
827         loaninCommon.setLoanReturnDate(returnDate);
828         LenderGroupList lenderGroupList = new LenderGroupList();
829         LenderGroup lenderGroup = new LenderGroup();
830         lenderGroup.setLender(LENDER_REF_NAME);
831         lenderGroupList.getLenderGroup().add(lenderGroup);
832         loaninCommon.setLenderGroupList(lenderGroupList);
833         loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
834         loaninCommon.setLoanInNote(getUTF8DataFragment());
835
836         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
837         PayloadOutputPart commonPart =
838             multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
839         commonPart.setLabel(new LoaninClient().getCommonPartName());
840
841         if(logger.isDebugEnabled()){
842             logger.debug("to be created, loanin common");
843             logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
844         }
845
846         return multipart;
847     }
848 }