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