]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a101f882307788277cb52d478cf0867a44aad9e2
[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.common.AbstractCommonListUtils;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.loanin.LenderGroup;
39 import org.collectionspace.services.loanin.LenderGroupList;
40 import org.collectionspace.services.loanin.LoansinCommon;
41
42 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
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     // 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     /** The known resource id. */
66     private String knownResourceId = null;
67     private String LENDER_REF_NAME =
68             "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Harry Lender)'Harry Lender'";
69
70     /* (non-Javadoc)
71      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
72      */
73     @Override
74     protected CollectionSpaceClient getClientInstance() {
75         return new LoaninClient();
76     }
77
78     /* (non-Javadoc)
79      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
80      */
81     @Override
82     protected AbstractCommonList getAbstractCommonList(
83             ClientResponse<AbstractCommonList> response) {
84         return response.getEntity(AbstractCommonList.class);
85     }
86
87     // ---------------------------------------------------------------
88     // CRUD tests : CREATE tests
89     // ---------------------------------------------------------------
90     
91     // Success outcomes
92     
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     
165     /* (non-Javadoc)
166      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
167      */
168     @Override
169     public void createWithEmptyEntityBody(String testName) throws Exception {
170         //Should this really be empty?
171     }
172
173     /* (non-Javadoc)
174      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
175      */
176     @Override
177     public void createWithMalformedXml(String testName) throws Exception {
178         //Should this really be empty?
179     }
180
181     /* (non-Javadoc)
182      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
183      */
184     @Override
185     public void createWithWrongXmlSchema(String testName) throws Exception {
186         //Should this really be empty?
187     }
188
189     /*
190     @Override
191     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
192     dependsOnMethods = {"create", "testSubmitRequest"})
193     public void createWithEmptyEntityBody(String testName) throws Exception {
194     
195     if (logger.isDebugEnabled()) {
196     logger.debug(testBanner(testName, CLASS_NAME));
197     }
198     // Perform setup.
199     setupCreateWithEmptyEntityBody();
200     
201     // Submit the request to the service and store the response.
202     String method = REQUEST_TYPE.httpMethodName();
203     String url = getServiceRootURL();
204     String mediaType = MediaType.APPLICATION_XML;
205     final String entity = "";
206     int statusCode = submitRequest(method, url, mediaType, entity);
207     
208     // Check the status code of the response: does it match
209     // the expected response(s)?
210     if(logger.isDebugEnabled()){
211     logger.debug("createWithEmptyEntityBody url=" + url +
212     " status=" + statusCode);
213     }
214     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
215     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
216     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
217     }
218     
219     @Override
220     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
221     dependsOnMethods = {"create", "testSubmitRequest"})
222     public void createWithMalformedXml(String testName) throws Exception {
223     
224     if (logger.isDebugEnabled()) {
225     logger.debug(testBanner(testName, CLASS_NAME));
226     }
227     // Perform setup.
228     setupCreateWithMalformedXml(testName, logger);
229     
230     // Submit the request to the service and store the response.
231     String method = REQUEST_TYPE.httpMethodName();
232     String url = getServiceRootURL();
233     String mediaType = MediaType.APPLICATION_XML;
234     final String entity = MALFORMED_XML_DATA; // Constant from base class.
235     int statusCode = submitRequest(method, url, mediaType, entity);
236     
237     // Check the status code of the response: does it match
238     // the expected response(s)?
239     if(logger.isDebugEnabled()){
240     logger.debug(testName + ": url=" + url +
241     " status=" + statusCode);
242     }
243     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
244     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
245     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
246     }
247     
248     @Override
249     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
250     dependsOnMethods = {"create", "testSubmitRequest"})
251     public void createWithWrongXmlSchema(String testName) throws Exception {
252     
253     if (logger.isDebugEnabled()) {
254     logger.debug(testBanner(testName, CLASS_NAME));
255     }
256     // Perform setup.
257     setupCreateWithWrongXmlSchema(testName, logger);
258     
259     // Submit the request to the service and store the response.
260     String method = REQUEST_TYPE.httpMethodName();
261     String url = getServiceRootURL();
262     String mediaType = MediaType.APPLICATION_XML;
263     final String entity = WRONG_XML_SCHEMA_DATA;
264     int statusCode = submitRequest(method, url, mediaType, entity);
265     
266     // Check the status code of the response: does it match
267     // the expected response(s)?
268     if(logger.isDebugEnabled()){
269     logger.debug(testName + ": url=" + url +
270     " status=" + statusCode);
271     }
272     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
275     }
276      */
277     
278     // ---------------------------------------------------------------
279     // CRUD tests : READ tests
280     // ---------------------------------------------------------------
281     
282     // Success outcomes
283     
284     /* (non-Javadoc)
285      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
286      */
287     @Override
288     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
289     dependsOnMethods = {"create"})
290     public void read(String testName) throws Exception {
291
292         if (logger.isDebugEnabled()) {
293             logger.debug(testBanner(testName, CLASS_NAME));
294         }
295         // Perform setup.
296         setupRead();
297
298         // Submit the request to the service and store the response.
299         LoaninClient client = new LoaninClient();
300         ClientResponse<String> res = client.read(knownResourceId);
301         PoxPayloadIn input = null;
302         try {
303             int statusCode = res.getStatus();
304
305             // Check the status code of the response: does it match
306             // the expected response(s)?
307             if (logger.isDebugEnabled()) {
308                 logger.debug(testName + ": status = " + statusCode);
309             }
310             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
311                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
312             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
313             input = new PoxPayloadIn(res.getEntity());
314         } finally {
315             res.releaseConnection();
316         }
317
318         // Get the common part of the response and verify that it is not null.
319         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
320         LoansinCommon loaninCommon = null;
321         if (payloadInputPart != null) {
322             loaninCommon = (LoansinCommon) payloadInputPart.getBody();
323         }
324         Assert.assertNotNull(loaninCommon);
325
326         // Check selected fields.
327         LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
328         Assert.assertNotNull(lenderGroupList);
329         List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
330         Assert.assertNotNull(lenderGroups);
331         Assert.assertTrue(lenderGroups.size() > 0);
332         String lender = lenderGroups.get(0).getLender();
333         Assert.assertEquals(lender, LENDER_REF_NAME);
334
335         if (logger.isDebugEnabled()) {
336             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
337                     + "UTF-8 data received=" + loaninCommon.getLoanInNote());
338         }
339
340         Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(),
341                 "UTF-8 data retrieved '" + loaninCommon.getLoanInNote()
342                 + "' does not match expected data '" + getUTF8DataFragment());
343     }
344
345     // Failure outcomes
346     
347     /* (non-Javadoc)
348      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
349      */
350     @Override
351     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352     dependsOnMethods = {"read"})
353     public void readNonExistent(String testName) throws Exception {
354
355         if (logger.isDebugEnabled()) {
356             logger.debug(testBanner(testName, CLASS_NAME));
357         }
358         // Perform setup.
359         setupReadNonExistent();
360
361         // Submit the request to the service and store the response.
362         LoaninClient client = new LoaninClient();
363         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
364         try {
365             int statusCode = res.getStatus();
366
367             // Check the status code of the response: does it match
368             // the expected response(s)?
369             if (logger.isDebugEnabled()) {
370                 logger.debug(testName + ": status = " + statusCode);
371             }
372             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
375         } finally {
376             res.releaseConnection();
377         }
378     }
379
380     // ---------------------------------------------------------------
381     // CRUD tests : READ_LIST tests
382     // ---------------------------------------------------------------
383     
384     // Success outcomes
385     
386     /* (non-Javadoc)
387      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
388      */
389     @Override
390     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
391     dependsOnMethods = {"createList", "read"})
392     public void readList(String testName) throws Exception {
393
394         if (logger.isDebugEnabled()) {
395             logger.debug(testBanner(testName, CLASS_NAME));
396         }
397         // Perform setup.
398         setupReadList();
399
400         // Submit the request to the service and store the response.
401         AbstractCommonList list = null;
402         LoaninClient client = new LoaninClient();
403         ClientResponse<AbstractCommonList> res = client.readList();
404         try {
405             int statusCode = res.getStatus();
406
407             // Check the status code of the response: does it match
408             // the expected response(s)?
409             if (logger.isDebugEnabled()) {
410                 logger.debug(testName + ": status = " + statusCode);
411             }
412             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
415
416             list = res.getEntity();
417         } finally {
418             res.releaseConnection();
419         }
420
421         // Optionally output additional data about list members for debugging.
422         boolean iterateThroughList = true;
423         if(iterateThroughList && logger.isDebugEnabled()){
424                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
425         }
426
427     }
428
429     // Failure outcomes
430     // None at present.
431     
432     // ---------------------------------------------------------------
433     // CRUD tests : UPDATE tests
434     // ---------------------------------------------------------------
435     
436     // Success outcomes
437     
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     
536     /* (non-Javadoc)
537      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
538      */
539     @Override
540     public void updateWithEmptyEntityBody(String testName) throws Exception {
541         //Should this really be empty?
542     }
543
544     /* (non-Javadoc)
545      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
546      */
547     @Override
548     public void updateWithMalformedXml(String testName) throws Exception {
549         //Should this really be empty?
550     }
551
552     /* (non-Javadoc)
553      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
554      */
555     @Override
556     public void updateWithWrongXmlSchema(String testName) throws Exception {
557         //Should this really be empty?
558     }
559
560     /*
561     @Override
562     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
563     dependsOnMethods = {"create", "update", "testSubmitRequest"})
564     public void updateWithEmptyEntityBody(String testName) throws Exception {
565     
566     if (logger.isDebugEnabled()) {
567     logger.debug(testBanner(testName, CLASS_NAME));
568     }
569     // Perform setup.
570     setupUpdateWithEmptyEntityBody();
571     
572     // Submit the request to the service and store the response.
573     String method = REQUEST_TYPE.httpMethodName();
574     String url = getResourceURL(knownResourceId);
575     String mediaType = MediaType.APPLICATION_XML;
576     final String entity = "";
577     int statusCode = submitRequest(method, url, mediaType, entity);
578     
579     // Check the status code of the response: does it match
580     // the expected response(s)?
581     if(logger.isDebugEnabled()){
582     logger.debug(testName + ": url=" + url +
583     " status=" + statusCode);
584     }
585     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588     }
589     
590     @Override
591     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
592     dependsOnMethods = {"create", "update", "testSubmitRequest"})
593     public void updateWithMalformedXml(String testName) throws Exception {
594     
595     if (logger.isDebugEnabled()) {
596     logger.debug(testBanner(testName, CLASS_NAME));
597     }
598     // Perform setup.
599     setupUpdateWithMalformedXml();
600     
601     // Submit the request to the service and store the response.
602     String method = REQUEST_TYPE.httpMethodName();
603     String url = getResourceURL(knownResourceId);
604     String mediaType = MediaType.APPLICATION_XML;
605     final String entity = MALFORMED_XML_DATA;
606     int statusCode = submitRequest(method, url, mediaType, entity);
607     
608     // Check the status code of the response: does it match
609     // the expected response(s)?
610     if(logger.isDebugEnabled()){
611     logger.debug(testName + ": url=" + url +
612     " status=" + statusCode);
613     }
614     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617     }
618     
619     @Override
620     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
621     dependsOnMethods = {"create", "update", "testSubmitRequest"})
622     public void updateWithWrongXmlSchema(String testName) throws Exception {
623     
624     if (logger.isDebugEnabled()) {
625     logger.debug(testBanner(testName, CLASS_NAME));
626     }
627     // Perform setup.
628     setupUpdateWithWrongXmlSchema();
629     
630     // Submit the request to the service and store the response.
631     String method = REQUEST_TYPE.httpMethodName();
632     String url = getResourceURL(knownResourceId);
633     String mediaType = MediaType.APPLICATION_XML;
634     final String entity = WRONG_XML_SCHEMA_DATA;
635     int statusCode = submitRequest(method, url, mediaType, entity);
636     
637     // Check the status code of the response: does it match
638     // the expected response(s)?
639     if(logger.isDebugEnabled()){
640     logger.debug(testName + ": url=" + url +
641     " status=" + statusCode);
642     }
643     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
644     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
645     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
646     }
647      */
648
649     /* (non-Javadoc)
650      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
651      */
652     @Override
653     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
654     dependsOnMethods = {"update", "testSubmitRequest"})
655     public void updateNonExistent(String testName) throws Exception {
656
657         if (logger.isDebugEnabled()) {
658             logger.debug(testBanner(testName, CLASS_NAME));
659         }
660         // Perform setup.
661         setupUpdateNonExistent();
662
663         // Submit the request to the service and store the response.
664         // Note: The ID used in this 'create' call may be arbitrary.
665         // The only relevant ID may be the one used in update(), below.
666         LoaninClient client = new LoaninClient();
667         PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
668         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
669         try {
670             int statusCode = res.getStatus();
671
672             // Check the status code of the response: does it match
673             // the expected response(s)?
674             if (logger.isDebugEnabled()) {
675                 logger.debug(testName + ": status = " + statusCode);
676             }
677             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
678                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
679             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
680         } finally {
681             res.releaseConnection();
682         }
683     }
684
685     // ---------------------------------------------------------------
686     // CRUD tests : DELETE tests
687     // ---------------------------------------------------------------
688     
689     // Success outcomes
690     
691     /* (non-Javadoc)
692      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
693      */
694     @Override
695     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
696     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
697     public void delete(String testName) throws Exception {
698
699         if (logger.isDebugEnabled()) {
700             logger.debug(testBanner(testName, CLASS_NAME));
701         }
702         // Perform setup.
703         setupDelete();
704
705         // Submit the request to the service and store the response.
706         LoaninClient client = new LoaninClient();
707         ClientResponse<Response> res = client.delete(knownResourceId);
708         try {
709             int statusCode = res.getStatus();
710
711             // Check the status code of the response: does it match
712             // the expected response(s)?
713             if (logger.isDebugEnabled()) {
714                 logger.debug(testName + ": status = " + statusCode);
715             }
716             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
717                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
718             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
719         } finally {
720             res.releaseConnection();
721         }
722     }
723
724     // Failure outcomes
725     
726     /* (non-Javadoc)
727      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
728      */
729     @Override
730     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
731     dependsOnMethods = {"delete"})
732     public void deleteNonExistent(String testName) throws Exception {
733
734         if (logger.isDebugEnabled()) {
735             logger.debug(testBanner(testName, CLASS_NAME));
736         }
737         // Perform setup.
738         setupDeleteNonExistent();
739
740         // Submit the request to the service and store the response.
741         LoaninClient client = new LoaninClient();
742         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
743         try {
744             int statusCode = res.getStatus();
745
746             // Check the status code of the response: does it match
747             // the expected response(s)?
748             if (logger.isDebugEnabled()) {
749                 logger.debug(testName + ": status = " + statusCode);
750             }
751             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
752                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
753             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754         } finally {
755             res.releaseConnection();
756         }
757     }
758
759     // ---------------------------------------------------------------
760     // Utility tests : tests of code used in tests above
761     // ---------------------------------------------------------------
762     
763     /**
764      * Tests the code for manually submitting data that is used by several
765      * of the methods above.
766      */
767     @Test(dependsOnMethods = {"create", "read"})
768     public void testSubmitRequest() {
769
770         // Expected status code: 200 OK
771         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
772
773         // Submit the request to the service and store the response.
774         String method = ServiceRequestType.READ.httpMethodName();
775         String url = getResourceURL(knownResourceId);
776         int statusCode = submitRequest(method, url);
777
778         // Check the status code of the response: does it match
779         // the expected response(s)?
780         if (logger.isDebugEnabled()) {
781             logger.debug("testSubmitRequest: url=" + url
782                     + " status=" + statusCode);
783         }
784         Assert.assertEquals(statusCode, EXPECTED_STATUS);
785
786     }
787
788     // ---------------------------------------------------------------
789     // Utility methods used by tests above
790     // ---------------------------------------------------------------
791     
792     @Override
793     public String getServiceName() {
794         return SERVICE_NAME;
795     }
796
797     /* (non-Javadoc)
798      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
799      */
800     @Override
801     public String getServicePathComponent() {
802         return SERVICE_PATH_COMPONENT;
803     }
804
805     @Override
806     protected PoxPayloadOut createInstance(String identifier) {
807         return createLoaninInstance(identifier);
808     }
809
810     /**
811      * Creates the loanin instance.
812      *
813      * @param identifier the identifier
814      * @return the multipart output
815      */
816     private PoxPayloadOut createLoaninInstance(String identifier) {
817         return createLoaninInstance(
818                 "loaninNumber-" + identifier,
819                 "returnDate-" + identifier);
820     }
821
822     /**
823      * Creates the loanin instance.
824      *
825      * @param loaninNumber the loanin number
826      * @param returnDate the return date
827      * @return the multipart output
828      */
829     private PoxPayloadOut createLoaninInstance(String loaninNumber,
830             String returnDate) {
831
832         LoansinCommon loaninCommon = new LoansinCommon();
833         loaninCommon.setLoanInNumber(loaninNumber);
834         loaninCommon.setLoanReturnDate(returnDate);
835         LenderGroupList lenderGroupList = new LenderGroupList();
836         LenderGroup lenderGroup = new LenderGroup();
837         lenderGroup.setLender(LENDER_REF_NAME);
838         lenderGroupList.getLenderGroup().add(lenderGroup);
839         loaninCommon.setLenderGroupList(lenderGroupList);
840         loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition.");
841         loaninCommon.setLoanInNote(getUTF8DataFragment());
842
843         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
844         PayloadOutputPart commonPart =
845                 multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE);
846         commonPart.setLabel(new LoaninClient().getCommonPartName());
847
848         if (logger.isDebugEnabled()) {
849             logger.debug("to be created, loanin common");
850             logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
851         }
852
853         return multipart;
854     }
855 }