]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0063f4c8c03f84e97139ce0e3fcbd499cdc7b886
[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.LoanStatusGroup;
39 import org.collectionspace.services.loanout.LoanStatusGroupList;
40 import org.collectionspace.services.loanout.LoansoutCommon;
41
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.testng.Assert;
45 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         assertStatusCode(res, testName);
287
288         // Get the common part of the response and verify that it is not null.
289         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
290         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
291         LoansoutCommon loanoutCommon = null;
292         if (payloadInputPart != null) {
293             loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
294         }
295         Assert.assertNotNull(loanoutCommon);
296
297         // Check selected fields in the common part.
298         Assert.assertNotNull(loanoutCommon.getLoanOutNumber());
299
300         LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
301         Assert.assertNotNull(statusGroupList);
302         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
303         Assert.assertNotNull(statusGroups);
304         Assert.assertTrue(statusGroups.size() > 0);
305         LoanStatusGroup statusGroup = statusGroups.get(0);
306         Assert.assertNotNull(statusGroup);
307         Assert.assertNotNull(statusGroup.getLoanStatus());
308
309         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
310         if (logger.isDebugEnabled()) {
311             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
312                     + "UTF-8 data received=" + loanoutCommon.getLoanOutNote());
313         }
314         Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(),
315                 "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote()
316                 + "' does not match expected data '" + getUTF8DataFragment());
317     }
318
319     // Failure outcomes
320     /* (non-Javadoc)
321      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
322      */
323     @Override
324     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
325     dependsOnMethods = {"read"})
326     public void readNonExistent(String testName) throws Exception {
327
328         if (logger.isDebugEnabled()) {
329             logger.debug(testBanner(testName, CLASS_NAME));
330         }
331         // Perform setup.
332         setupReadNonExistent();
333
334         // Submit the request to the service and store the response.
335         LoanoutClient client = new LoanoutClient();
336         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
337         int statusCode = res.getStatus();
338
339         // Check the status code of the response: does it match
340         // the expected response(s)?
341         if (logger.isDebugEnabled()) {
342             logger.debug(testName + ": status = " + statusCode);
343         }
344         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
345                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
346         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
347     }
348
349     // ---------------------------------------------------------------
350     // CRUD tests : READ_LIST tests
351     // ---------------------------------------------------------------
352     // Success outcomes
353     /* (non-Javadoc)
354      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
355      */
356     @Override
357     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358     dependsOnMethods = {"createList", "read"})
359     public void readList(String testName) throws Exception {
360
361         if (logger.isDebugEnabled()) {
362             logger.debug(testBanner(testName, CLASS_NAME));
363         }
364         // Perform setup.
365         setupReadList();
366
367         // Submit the request to the service and store the response.
368         LoanoutClient client = new LoanoutClient();
369         ClientResponse<AbstractCommonList> res = client.readList();
370         assertStatusCode(res, testName);
371         AbstractCommonList list = res.getEntity();
372
373         // Optionally output additional data about list members for debugging.
374         boolean iterateThroughList = true;
375         if(iterateThroughList && logger.isDebugEnabled()){
376                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
377         }
378
379     }
380
381     // Failure outcomes
382     // None at present.
383     // ---------------------------------------------------------------
384     // CRUD tests : UPDATE tests
385     // ---------------------------------------------------------------
386     // Success outcomes
387     /* (non-Javadoc)
388      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
389      */
390     @Override
391     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
392     dependsOnMethods = {"read"})
393     public void update(String testName) throws Exception {
394
395         if (logger.isDebugEnabled()) {
396             logger.debug(testBanner(testName, CLASS_NAME));
397         }
398         // Perform setup.
399         setupUpdate();
400
401         // Retrieve the contents of a resource to update.
402         LoanoutClient client = new LoanoutClient();
403         ClientResponse<String> res = client.read(knownResourceId);
404         assertStatusCode(res, testName);
405
406         // Extract the common part from the response.
407         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
408         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
409         LoansoutCommon loanoutCommon = null;
410         if (payloadInputPart != null) {
411             loanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
412         }
413         Assert.assertNotNull(loanoutCommon);
414
415         // Update the content of this resource.
416         loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber());
417         LoanStatusGroupList statusGroupList = loanoutCommon.getLoanStatusGroupList();
418         Assert.assertNotNull(statusGroupList);
419         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
420         Assert.assertNotNull(statusGroups);
421         Assert.assertTrue(statusGroups.size() > 0);
422         LoanStatusGroup statusGroup = statusGroups.get(0);
423         Assert.assertNotNull(statusGroup);
424         String loanStatus = statusGroup.getLoanStatus();
425         Assert.assertNotNull(loanStatus);
426         String updatedLoanStatus = "updated-" + loanStatus;
427         statusGroups.get(0).setLoanStatus(updatedLoanStatus);
428         loanoutCommon.setLoanStatusGroupList(statusGroupList);
429         if (logger.isDebugEnabled()) {
430             logger.debug("to be updated object");
431             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
432         }
433         loanoutCommon.setLoanOutNote("updated-" + loanoutCommon.getLoanOutNote());
434
435         // Submit the updated resource in an update request to the service and store the response.
436         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
437         PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
438         commonPart.setLabel(client.getCommonPartName());
439         res = client.update(knownResourceId, output);
440         assertStatusCode(res, testName);
441
442         // Extract the updated common part from the response.
443         input = new PoxPayloadIn(res.getEntity());
444         payloadInputPart = input.getPart(client.getCommonPartName());
445         LoansoutCommon updatedLoanoutCommon = null;
446         if (payloadInputPart != null) {
447             updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody();
448         }
449         Assert.assertNotNull(updatedLoanoutCommon);
450
451         // Check selected fields in the updated resource.
452         Assert.assertEquals(updatedLoanoutCommon.getLoanOutNumber(),
453                 loanoutCommon.getLoanOutNumber(),
454                 "Data in updated object did not match submitted data.");
455
456         LoanStatusGroupList updatedStatusGroupList =
457                 updatedLoanoutCommon.getLoanStatusGroupList();
458         Assert.assertNotNull(updatedStatusGroupList);
459         List<LoanStatusGroup> updatedStatusGroups =
460                 updatedStatusGroupList.getLoanStatusGroup();
461         Assert.assertNotNull(updatedStatusGroups);
462         Assert.assertTrue(updatedStatusGroups.size() > 0);
463         Assert.assertNotNull(updatedStatusGroups.get(0));
464         Assert.assertEquals(updatedLoanStatus,
465                 updatedStatusGroups.get(0).getLoanStatus(),
466                 "Data in updated object did not match submitted data.");
467
468         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
469         if (logger.isDebugEnabled()) {
470             logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n"
471                     + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote());
472         }
473         Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()),
474                 "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote()
475                 + "' does not contain expected data '" + getUTF8DataFragment());
476         Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(),
477                 loanoutCommon.getLoanOutNote(),
478                 "Data in updated object did not match submitted data.");
479     }
480
481     // Failure outcomes
482     // Placeholders until the three tests below can be uncommented.
483     // See Issue CSPACE-401.
484     /* (non-Javadoc)
485      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
486      */
487     @Override
488     public void updateWithEmptyEntityBody(String testName) throws Exception {
489         //Should this really be empty?
490     }
491
492     /* (non-Javadoc)
493      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
494      */
495     @Override
496     public void updateWithMalformedXml(String testName) throws Exception {
497         //Should this really be empty?
498     }
499
500     /* (non-Javadoc)
501      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
502      */
503     @Override
504     public void updateWithWrongXmlSchema(String testName) throws Exception {
505         //Should this really be empty?
506     }
507
508     /*
509     @Override
510     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
511     dependsOnMethods = {"create", "update", "testSubmitRequest"})
512     public void updateWithEmptyEntityBody(String testName) throws Exception {
513
514     if (logger.isDebugEnabled()) {
515     logger.debug(testBanner(testName, CLASS_NAME));
516     }
517     // Perform setup.
518     setupUpdateWithEmptyEntityBody();
519
520     // Submit the request to the service and store the response.
521     String method = REQUEST_TYPE.httpMethodName();
522     String url = getResourceURL(knownResourceId);
523     String mediaType = MediaType.APPLICATION_XML;
524     final String entity = "";
525     int statusCode = submitRequest(method, url, mediaType, entity);
526
527     // Check the status code of the response: does it match
528     // the expected response(s)?
529     if(logger.isDebugEnabled()){
530     logger.debug(testName + ": url=" + url +
531     " status=" + statusCode);
532     }
533     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
536     }
537
538     @Override
539     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
540     dependsOnMethods = {"create", "update", "testSubmitRequest"})
541     public void updateWithMalformedXml(String testName) throws Exception {
542
543     if (logger.isDebugEnabled()) {
544     logger.debug(testBanner(testName, CLASS_NAME));
545     }
546     // Perform setup.
547     setupUpdateWithMalformedXml();
548
549     // Submit the request to the service and store the response.
550     String method = REQUEST_TYPE.httpMethodName();
551     String url = getResourceURL(knownResourceId);
552     String mediaType = MediaType.APPLICATION_XML;
553     final String entity = MALFORMED_XML_DATA;
554     int statusCode = submitRequest(method, url, mediaType, entity);
555
556     // Check the status code of the response: does it match
557     // the expected response(s)?
558     if(logger.isDebugEnabled()){
559     logger.debug(testName + ": url=" + url +
560     " status=" + statusCode);
561     }
562     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565     }
566
567     @Override
568     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569     dependsOnMethods = {"create", "update", "testSubmitRequest"})
570     public void updateWithWrongXmlSchema(String testName) throws Exception {
571
572     if (logger.isDebugEnabled()) {
573     logger.debug(testBanner(testName, CLASS_NAME));
574     }
575     // Perform setup.
576     setupUpdateWithWrongXmlSchema();
577
578     // Submit the request to the service and store the response.
579     String method = REQUEST_TYPE.httpMethodName();
580     String url = getResourceURL(knownResourceId);
581     String mediaType = MediaType.APPLICATION_XML;
582     final String entity = WRONG_XML_SCHEMA_DATA;
583     int statusCode = submitRequest(method, url, mediaType, entity);
584
585     // Check the status code of the response: does it match
586     // the expected response(s)?
587     if(logger.isDebugEnabled()){
588     logger.debug(testName + ": url=" + url +
589     " status=" + statusCode);
590     }
591     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594     }
595      */
596
597     /* (non-Javadoc)
598      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
599      */
600     @Override
601     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
602     dependsOnMethods = {"update", "testSubmitRequest"})
603     public void updateNonExistent(String testName) throws Exception {
604
605         if (logger.isDebugEnabled()) {
606             logger.debug(testBanner(testName, CLASS_NAME));
607         }
608         // Perform setup.
609         setupUpdateNonExistent();
610
611         // Submit the request to the service and store the response.
612         // Note: The ID used in this 'create' call may be arbitrary.
613         // The only relevant ID may be the one used in update(), below.
614         LoanoutClient client = new LoanoutClient();
615         PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID);
616         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
617         int statusCode = res.getStatus();
618
619         // Check the status code of the response: does it match
620         // the expected response(s)?
621         if (logger.isDebugEnabled()) {
622             logger.debug(testName + ": 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     // CRUD tests : DELETE tests
631     // ---------------------------------------------------------------
632     // Success outcomes
633     /* (non-Javadoc)
634      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
635      */
636     @Override
637     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
638     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
639     public void delete(String testName) throws Exception {
640
641         if (logger.isDebugEnabled()) {
642             logger.debug(testBanner(testName, CLASS_NAME));
643         }
644         // Perform setup.
645         setupDelete();
646
647         // Submit the request to the service and store the response.
648         LoanoutClient client = new LoanoutClient();
649         ClientResponse<Response> res = client.delete(knownResourceId);
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     // Failure outcomes
663     /* (non-Javadoc)
664      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
665      */
666     @Override
667     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
668     dependsOnMethods = {"delete"})
669     public void deleteNonExistent(String testName) throws Exception {
670
671         if (logger.isDebugEnabled()) {
672             logger.debug(testBanner(testName, CLASS_NAME));
673         }
674         // Perform setup.
675         setupDeleteNonExistent();
676
677         // Submit the request to the service and store the response.
678         LoanoutClient client = new LoanoutClient();
679         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
680         int statusCode = res.getStatus();
681
682         // Check the status code of the response: does it match
683         // the expected response(s)?
684         if (logger.isDebugEnabled()) {
685             logger.debug(testName + ": status = " + statusCode);
686         }
687         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
690     }
691
692     // ---------------------------------------------------------------
693     // Utility tests : tests of code used in tests above
694     // ---------------------------------------------------------------
695     /**
696      * Tests the code for manually submitting data that is used by several
697      * of the methods above.
698      */
699     @Test(dependsOnMethods = {"create", "read"})
700     public void testSubmitRequest() {
701
702         // Expected status code: 200 OK
703         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
704
705         // Submit the request to the service and store the response.
706         String method = ServiceRequestType.READ.httpMethodName();
707         String url = getResourceURL(knownResourceId);
708         int statusCode = submitRequest(method, url);
709
710         // Check the status code of the response: does it match
711         // the expected response(s)?
712         if (logger.isDebugEnabled()) {
713             logger.debug("testSubmitRequest: url=" + url
714                     + " status=" + statusCode);
715         }
716         Assert.assertEquals(statusCode, EXPECTED_STATUS);
717
718     }
719
720     // ---------------------------------------------------------------
721     // Utility methods used by tests above
722     // ---------------------------------------------------------------
723     /* (non-Javadoc)
724      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
725      */
726     @Override
727     public String getServicePathComponent() {
728         return LoanoutClient.SERVICE_PATH_COMPONENT;
729     }
730
731     @Override
732     protected PoxPayloadOut createInstance(String identifier) {
733         return createLoanoutInstance(identifier);
734     }
735     
736     /**
737      * Creates the loanout instance.
738      *
739      * @param identifier the identifier
740      * @return the multipart output
741      */
742     private PoxPayloadOut createLoanoutInstance(String identifier) {
743         return createLoanoutInstance(
744                 "loanoutNumber-" + identifier,
745                 CURRENT_DATE_UTC);
746     }
747
748     /**
749      * Creates the loanout instance.
750      *
751      * @param loanOutNumber the loan out number
752      * @param returnDate the return date
753      * @return the multipart output
754      */
755     private PoxPayloadOut createLoanoutInstance(String loanOutNumber,
756             String returnDate) {
757         LoansoutCommon loanoutCommon = new LoansoutCommon();
758         loanoutCommon.setLoanOutNumber(loanOutNumber);
759         loanoutCommon.setLoanReturnDate(returnDate);
760         loanoutCommon.setBorrower(
761                 "urn:cspace:org.collectionspace.demo:orgauthorities:name(TestOrgAuth):item:name(NorthernClimesMuseum)'Northern Climes Museum'");
762         loanoutCommon.setBorrowersContact(
763                 "urn:cspace:org.collectionspace.demo:personauthorities:name(TestPersonAuth):item:name(ChrisContact)'Chris Contact'");
764         loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
765         LoanStatusGroupList statusGroupList = new LoanStatusGroupList();
766         List<LoanStatusGroup> statusGroups = statusGroupList.getLoanStatusGroup();
767         LoanStatusGroup statusGroup = new LoanStatusGroup();
768         statusGroup.setLoanStatus("returned");
769         statusGroup.setLoanStatusNote("Left under the front mat.");
770         statusGroups.add(statusGroup);
771         loanoutCommon.setLoanStatusGroupList(statusGroupList);
772         loanoutCommon.setLoanOutNote(getUTF8DataFragment());  // For UTF-8 tests
773
774         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
775         PayloadOutputPart commonPart =
776                 multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE);
777         commonPart.setLabel(new LoanoutClient().getCommonPartName());
778
779         if (logger.isDebugEnabled()) {
780             logger.debug("to be created, loanout common");
781             logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class));
782             // logger.debug(multipart.toXML());
783         }
784
785         return multipart;
786     }
787
788     @Override
789     protected String getServiceName() {
790         return LoanoutClient.SERVICE_NAME;
791     }
792 }