]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bb3975981d63e55b2a55f4f91baf3b5336572499
[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.jaxb.AbstractCommonList;
36 import org.collectionspace.services.loanout.LoanedObjectStatusGroup;
37 import org.collectionspace.services.loanout.LoanedObjectStatusGroupList;
38 import org.collectionspace.services.loanout.LoansoutCommon;
39 import org.collectionspace.services.loanout.LoansoutCommonList;
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(LoansoutCommonList.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<LoansoutCommonList> res = client.readList();
376         LoansoutCommonList 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 = false;
390         if (iterateThroughList && logger.isDebugEnabled()) {
391             List<LoansoutCommonList.LoanoutListItem> items =
392                     list.getLoanoutListItem();
393             int i = 0;
394             for (LoansoutCommonList.LoanoutListItem item : items) {
395                 logger.debug(testName + ": list-item[" + i + "] csid="
396                         + item.getCsid());
397                 logger.debug(testName + ": list-item[" + i + "] loanOutNumber="
398                         + item.getLoanOutNumber());
399                 logger.debug(testName + ": list-item[" + i + "] URI="
400                         + item.getUri());
401                 i++;
402             }
403         }
404
405     }
406
407     // Failure outcomes
408     // None at present.
409     // ---------------------------------------------------------------
410     // CRUD tests : UPDATE tests
411     // ---------------------------------------------------------------
412     // Success outcomes
413     /* (non-Javadoc)
414      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
415      */
416     @Override
417     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
418     dependsOnMethods = {"read"})
419     public void update(String testName) throws Exception {
420
421         if (logger.isDebugEnabled()) {
422             logger.debug(testBanner(testName, CLASS_NAME));
423         }
424         // Perform setup.
425         setupUpdate();
426
427         // Retrieve the contents of a resource to update.
428         LoanoutClient client = new LoanoutClient();
429         ClientResponse<String> res = client.read(knownResourceId);
430         if (logger.isDebugEnabled()) {
431             logger.debug(testName + ": read status = " + res.getStatus());
432         }
433         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
434
435         if (logger.isDebugEnabled()) {
436             logger.debug("got object to update with ID: " + knownResourceId);
437         }
438
439         // Extract the common part from the response.
440         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
441         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
442         LoansoutCommon loanoutCommon = null;
443         if (payloadInputPart != null) {
444             loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
445         }
446         Assert.assertNotNull(loanoutCommon);
447
448         // Update the content of this resource.
449         loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
450         loanoutCommon.setLoanReturnDate("updated-" + loanoutCommon.getLoanReturnDate());
451         LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList();
452         Assert.assertNotNull(statusGroupList);
453         List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
454         Assert.assertNotNull(statusGroups);
455         Assert.assertTrue(statusGroups.size() > 0);
456         LoanedObjectStatusGroup statusGroup = statusGroups.get(0);
457         Assert.assertNotNull(statusGroup);
458         String loanedObjectStatus = statusGroup.getLoanedObjectStatus();
459         Assert.assertNotNull(loanedObjectStatus);
460         String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus;
461         statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus);
462         loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
463         if (logger.isDebugEnabled()) {
464             logger.debug("to be updated object");
465             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
466         }
467         loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
468
469         // Submit the updated resource in an update request to the service and store the response.
470         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
471         PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
472         commonPart.setLabel(client.getCommonPartName());
473         res = client.update(knownResourceId, output);
474         int statusCode = res.getStatus();
475
476         // Check the status code of the response: does it match the expected response(s)?
477         if (logger.isDebugEnabled()) {
478             logger.debug(testName + ": status = " + statusCode);
479         }
480         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
483
484         // Extract the updated common part from the response.
485         input = new PoxPayloadIn(res.getEntity());
486         payloadInputPart = input.getPart(client.getCommonPartName());
487         LoansoutCommon updatedLoanoutCommon = null;
488         if (payloadInputPart != null) {
489             updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
490         }
491         Assert.assertNotNull(updatedLoanoutCommon);
492
493         // Check selected fields in the updated resource.
494         Assert.assertEquals(updatedLoanoutCommon.getLoanReturnDate(),
495                 loanoutCommon.getLoanReturnDate(),
496                 "Data in updated object did not match submitted data.");
497
498         LoanedObjectStatusGroupList updatedStatusGroupList =
499                 updatedLoanoutCommon.getLoanedObjectStatusGroupList();
500         Assert.assertNotNull(updatedStatusGroupList);
501         List<LoanedObjectStatusGroup> updatedStatusGroups =
502                 updatedStatusGroupList.getLoanedObjectStatusGroup();
503         Assert.assertNotNull(updatedStatusGroups);
504         Assert.assertTrue(updatedStatusGroups.size() > 0);
505         Assert.assertNotNull(updatedStatusGroups.get(0));
506         Assert.assertEquals(updatedLoanedObjectStatus,
507                 updatedStatusGroups.get(0).getLoanedObjectStatus(),
508                 "Data in updated object did not match submitted data.");
509
510         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
511         if (logger.isDebugEnabled()) {
512             logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
513                     + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
514         }
515         Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
516                 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
517                 + "' does not contain expected data '" + getUTF8DataFragment());
518         Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
519                 loanoutCommon.getLoanOutNote(),
520                 "Data in updated object did not match submitted data.");
521     }
522
523     // Failure outcomes
524     // Placeholders until the three tests below can be uncommented.
525     // See Issue CSPACE-401.
526     /* (non-Javadoc)
527      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
528      */
529     @Override
530     public void updateWithEmptyEntityBody(String testName) throws Exception {
531         //Should this really be empty?
532     }
533
534     /* (non-Javadoc)
535      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
536      */
537     @Override
538     public void updateWithMalformedXml(String testName) throws Exception {
539         //Should this really be empty?
540     }
541
542     /* (non-Javadoc)
543      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
544      */
545     @Override
546     public void updateWithWrongXmlSchema(String testName) throws Exception {
547         //Should this really be empty?
548     }
549
550     /*
551     @Override
552     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
553     dependsOnMethods = {"create", "update", "testSubmitRequest"})
554     public void updateWithEmptyEntityBody(String testName) throws Exception {
555
556     if (logger.isDebugEnabled()) {
557     logger.debug(testBanner(testName, CLASS_NAME));
558     }
559     // Perform setup.
560     setupUpdateWithEmptyEntityBody();
561
562     // Submit the request to the service and store the response.
563     String method = REQUEST_TYPE.httpMethodName();
564     String url = getResourceURL(knownResourceId);
565     String mediaType = MediaType.APPLICATION_XML;
566     final String entity = "";
567     int statusCode = submitRequest(method, url, mediaType, entity);
568
569     // Check the status code of the response: does it match
570     // the expected response(s)?
571     if(logger.isDebugEnabled()){
572     logger.debug(testName + ": url=" + url +
573     " status=" + statusCode);
574     }
575     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578     }
579
580     @Override
581     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
582     dependsOnMethods = {"create", "update", "testSubmitRequest"})
583     public void updateWithMalformedXml(String testName) throws Exception {
584
585     if (logger.isDebugEnabled()) {
586     logger.debug(testBanner(testName, CLASS_NAME));
587     }
588     // Perform setup.
589     setupUpdateWithMalformedXml();
590
591     // Submit the request to the service and store the response.
592     String method = REQUEST_TYPE.httpMethodName();
593     String url = getResourceURL(knownResourceId);
594     String mediaType = MediaType.APPLICATION_XML;
595     final String entity = MALFORMED_XML_DATA;
596     int statusCode = submitRequest(method, url, mediaType, entity);
597
598     // Check the status code of the response: does it match
599     // the expected response(s)?
600     if(logger.isDebugEnabled()){
601     logger.debug(testName + ": url=" + url +
602     " status=" + statusCode);
603     }
604     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607     }
608
609     @Override
610     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
611     dependsOnMethods = {"create", "update", "testSubmitRequest"})
612     public void updateWithWrongXmlSchema(String testName) throws Exception {
613
614     if (logger.isDebugEnabled()) {
615     logger.debug(testBanner(testName, CLASS_NAME));
616     }
617     // Perform setup.
618     setupUpdateWithWrongXmlSchema();
619
620     // Submit the request to the service and store the response.
621     String method = REQUEST_TYPE.httpMethodName();
622     String url = getResourceURL(knownResourceId);
623     String mediaType = MediaType.APPLICATION_XML;
624     final String entity = WRONG_XML_SCHEMA_DATA;
625     int statusCode = submitRequest(method, url, mediaType, entity);
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 + ": url=" + url +
631     " status=" + statusCode);
632     }
633     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
634     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
635     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
636     }
637      */
638
639     /* (non-Javadoc)
640      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
641      */
642     @Override
643     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
644     dependsOnMethods = {"update", "testSubmitRequest"})
645     public void updateNonExistent(String testName) throws Exception {
646
647         if (logger.isDebugEnabled()) {
648             logger.debug(testBanner(testName, CLASS_NAME));
649         }
650         // Perform setup.
651         setupUpdateNonExistent();
652
653         // Submit the request to the service and store the response.
654         // Note: The ID used in this 'create' call may be arbitrary.
655         // The only relevant ID may be the one used in update(), below.
656         LoanoutClient client = new LoanoutClient();
657         PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
658         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
659         int statusCode = res.getStatus();
660
661         // Check the status code of the response: does it match
662         // the expected response(s)?
663         if (logger.isDebugEnabled()) {
664             logger.debug(testName + ": status = " + statusCode);
665         }
666         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
667                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
668         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669     }
670
671     // ---------------------------------------------------------------
672     // CRUD tests : DELETE tests
673     // ---------------------------------------------------------------
674     // Success outcomes
675     /* (non-Javadoc)
676      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
677      */
678     @Override
679     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
680     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
681     public void delete(String testName) throws Exception {
682
683         if (logger.isDebugEnabled()) {
684             logger.debug(testBanner(testName, CLASS_NAME));
685         }
686         // Perform setup.
687         setupDelete();
688
689         // Submit the request to the service and store the response.
690         LoanoutClient client = new LoanoutClient();
691         ClientResponse<Response> res = client.delete(knownResourceId);
692         int statusCode = res.getStatus();
693
694         // Check the status code of the response: does it match
695         // the expected response(s)?
696         if (logger.isDebugEnabled()) {
697             logger.debug(testName + ": status = " + statusCode);
698         }
699         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702     }
703
704     // Failure outcomes
705     /* (non-Javadoc)
706      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
707      */
708     @Override
709     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
710     dependsOnMethods = {"delete"})
711     public void deleteNonExistent(String testName) throws Exception {
712
713         if (logger.isDebugEnabled()) {
714             logger.debug(testBanner(testName, CLASS_NAME));
715         }
716         // Perform setup.
717         setupDeleteNonExistent();
718
719         // Submit the request to the service and store the response.
720         LoanoutClient client = new LoanoutClient();
721         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
722         int statusCode = res.getStatus();
723
724         // Check the status code of the response: does it match
725         // the expected response(s)?
726         if (logger.isDebugEnabled()) {
727             logger.debug(testName + ": status = " + statusCode);
728         }
729         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
730                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
731         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
732     }
733
734     // ---------------------------------------------------------------
735     // Utility tests : tests of code used in tests above
736     // ---------------------------------------------------------------
737     /**
738      * Tests the code for manually submitting data that is used by several
739      * of the methods above.
740      */
741     @Test(dependsOnMethods = {"create", "read"})
742     public void testSubmitRequest() {
743
744         // Expected status code: 200 OK
745         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
746
747         // Submit the request to the service and store the response.
748         String method = ServiceRequestType.READ.httpMethodName();
749         String url = getResourceURL(knownResourceId);
750         int statusCode = submitRequest(method, url);
751
752         // Check the status code of the response: does it match
753         // the expected response(s)?
754         if (logger.isDebugEnabled()) {
755             logger.debug("testSubmitRequest: url=" + url
756                     + " status=" + statusCode);
757         }
758         Assert.assertEquals(statusCode, EXPECTED_STATUS);
759
760     }
761
762     // ---------------------------------------------------------------
763     // Utility methods used by tests above
764     // ---------------------------------------------------------------
765     /* (non-Javadoc)
766      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
767      */
768     @Override
769     public String getServicePathComponent() {
770         return LoanoutClient.SERVICE_PATH_COMPONENT;
771     }
772
773     @Override
774     protected PoxPayloadOut createInstance(String identifier) {
775         return createLoanoutInstance(identifier);
776     }
777     
778     /**
779      * Creates the loanout instance.
780      *
781      * @param identifier the identifier
782      * @return the multipart output
783      */
784     private PoxPayloadOut createLoanoutInstance(String identifier) {
785         return createLoanoutInstance(
786                 "loanoutNumber-" + identifier,
787                 "returnDate-" + identifier);
788     }
789
790     /**
791      * Creates the loanout instance.
792      *
793      * @param loanOutNumber the loan out number
794      * @param returnDate the return date
795      * @return the multipart output
796      */
797     private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
798             String returnDate) {
799         LoansoutCommon loanoutCommon = new LoansoutCommon();
800         loanoutCommon.setLoanOutNumber(loanOutNumber);
801         loanoutCommon.setLoanReturnDate(returnDate);
802         loanoutCommon.setBorrower(
803                 "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
804         loanoutCommon.setBorrowersContact(
805                 "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
806         loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
807         LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList();
808         List<LoanedObjectStatusGroup> statusGroups = statusGroupList.getLoanedObjectStatusGroup();
809         LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup();
810         statusGroup.setLoanedObjectStatus("returned");
811         statusGroup.setLoanedObjectStatusNote("Left under the front mat.");
812         statusGroups.add(statusGroup);
813         loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList);
814         loanoutCommon.setLoanOutNote(getUTF8DataFragment());  // For UTF-8 tests
815
816         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
817         PayloadOutputPart commonPart =
818                 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
819         commonPart.setLabel(new LoanoutClient().getCommonPartName());
820
821         if (logger.isDebugEnabled()) {
822             logger.debug("to be created, loanout common");
823             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
824             // logger.debug(multipart.toXML());
825         }
826
827         return multipart;
828     }
829
830     @Override
831     protected String getServiceName() {
832         return LoanoutClient.SERVICE_NAME;
833     }
834 }