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