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