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