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