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