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