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