]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b19069700461a479186ba6494175547edf1293aa
[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.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.LoanoutClient;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.loanout.LoansoutCommon;
34 import org.collectionspace.services.loanout.LoansoutCommonList;
35
36 import org.jboss.resteasy.client.ClientResponse;
37
38 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
40 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
41 import org.testng.Assert;
42 import org.testng.annotations.AfterClass;
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: 1327 $
53  * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $
54  */
55 public class LoanoutServiceTest extends AbstractServiceTestImpl {
56
57    /** The logger. */
58    private final Logger logger =
59        LoggerFactory.getLogger(LoanoutServiceTest.class);
60
61     // Instance variables specific to this test.
62     /** The SERVIC e_ pat h_ component. */
63     final String SERVICE_PATH_COMPONENT = "loansout";
64     
65     /** The known resource id. */
66     private String knownResourceId = null;
67     
68     /** The all resource ids created. */
69     private List<String> allResourceIdsCreated = new ArrayList<String>();
70
71     /* (non-Javadoc)
72      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
73      */
74     @Override
75     protected CollectionSpaceClient getClientInstance() {
76         return new LoanoutClient();
77     }
78     
79     /* (non-Javadoc)
80      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
81      */
82     @Override
83         protected AbstractCommonList getAbstractCommonList(
84                         ClientResponse<AbstractCommonList> response) {
85         return response.getEntity(LoansoutCommonList.class);
86     }
87  
88     // ---------------------------------------------------------------
89     // CRUD tests : CREATE tests
90     // ---------------------------------------------------------------
91     // Success outcomes
92     /* (non-Javadoc)
93      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
94      */
95     @Override
96     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
97     public void create(String testName) throws Exception {
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(testName);
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     }
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     }
167
168     /* (non-Javadoc)
169      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
170      */
171     @Override
172     public void createWithWrongXmlSchema(String testName) throws Exception {
173     }
174
175     /*
176     @Override
177     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
178         dependsOnMethods = {"create", "testSubmitRequest"})
179     public void createWithEmptyEntityBody(String testName) throws Exception {
180
181     // Perform setup.
182     setupCreateWithEmptyEntityBody(testName);
183
184     // Submit the request to the service and store the response.
185     String method = REQUEST_TYPE.httpMethodName();
186     String url = getServiceRootURL();
187     String mediaType = MediaType.APPLICATION_XML;
188     final String entity = "";
189     int statusCode = submitRequest(method, url, mediaType, entity);
190
191     // Check the status code of the response: does it match
192     // the expected response(s)?
193     if(logger.isDebugEnabled()){
194         logger.debug("createWithEmptyEntityBody url=" + url +
195             " status=" + statusCode);
196      }
197     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
198     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
199     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
200     }
201
202     @Override
203     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
204         dependsOnMethods = {"create", "testSubmitRequest"})
205     public void createWithMalformedXml(String testName) throws Exception {
206
207     // Perform setup.
208     setupCreateWithMalformedXml(testName);
209
210     // Submit the request to the service and store the response.
211     String method = REQUEST_TYPE.httpMethodName();
212     String url = getServiceRootURL();
213     String mediaType = MediaType.APPLICATION_XML;
214     final String entity = MALFORMED_XML_DATA; // Constant from base class.
215     int statusCode = submitRequest(method, url, mediaType, entity);
216
217     // Check the status code of the response: does it match
218     // the expected response(s)?
219     if(logger.isDebugEnabled()){
220         logger.debug(testName + ": url=" + url +
221             " status=" + statusCode);
222      }
223     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
224     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
225     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
226     }
227
228     @Override
229     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
230         dependsOnMethods = {"create", "testSubmitRequest"})
231     public void createWithWrongXmlSchema(String testName) throws Exception {
232
233     // Perform setup.
234     setupCreateWithWrongXmlSchema(testName);
235
236     // Submit the request to the service and store the response.
237     String method = REQUEST_TYPE.httpMethodName();
238     String url = getServiceRootURL();
239     String mediaType = MediaType.APPLICATION_XML;
240     final String entity = WRONG_XML_SCHEMA_DATA;
241     int statusCode = submitRequest(method, url, mediaType, entity);
242
243     // Check the status code of the response: does it match
244     // the expected response(s)?
245     if(logger.isDebugEnabled()){
246         logger.debug(testName + ": url=" + url +
247             " status=" + statusCode);
248      }
249     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
250     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
251     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
252     }
253      */
254
255     // ---------------------------------------------------------------
256     // CRUD tests : READ tests
257     // ---------------------------------------------------------------
258     // Success outcomes
259     /* (non-Javadoc)
260      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
261      */
262     @Override
263     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
264         dependsOnMethods = {"create"})
265     public void read(String testName) throws Exception {
266
267         // Perform setup.
268         setupRead(testName);
269
270         // Submit the request to the service and store the response.
271         LoanoutClient client = new LoanoutClient();
272         ClientResponse<MultipartInput> res = client.read(knownResourceId);
273         int statusCode = res.getStatus();
274
275         // Check the status code of the response: does it match
276         // the expected response(s)?
277         if(logger.isDebugEnabled()){
278             logger.debug(testName + ": status = " + statusCode);
279         }
280         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
281                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
282         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
283
284         MultipartInput input = (MultipartInput) res.getEntity();
285         LoansoutCommon loanout = (LoansoutCommon) extractPart(input,
286                 client.getCommonPartName(), LoansoutCommon.class);
287         Assert.assertNotNull(loanout);
288     }
289
290     // Failure outcomes
291     /* (non-Javadoc)
292      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
293      */
294     @Override
295     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
296         dependsOnMethods = {"read"})
297     public void readNonExistent(String testName) throws Exception {
298
299         // Perform setup.
300         setupReadNonExistent(testName);
301
302         // Submit the request to the service and store the response.
303         LoanoutClient client = new LoanoutClient();
304         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
305         int statusCode = res.getStatus();
306
307         // Check the status code of the response: does it match
308         // the expected response(s)?
309         if(logger.isDebugEnabled()){
310             logger.debug(testName + ": status = " + statusCode);
311         }
312         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
313                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
314         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
315     }
316
317     // ---------------------------------------------------------------
318     // CRUD tests : READ_LIST tests
319     // ---------------------------------------------------------------
320     // Success outcomes
321     /* (non-Javadoc)
322      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
323      */
324     @Override
325     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
326         dependsOnMethods = {"createList", "read"})
327     public void readList(String testName) throws Exception {
328
329         // Perform setup.
330         setupReadList(testName);
331
332         // Submit the request to the service and store the response.
333         LoanoutClient client = new LoanoutClient();
334         ClientResponse<LoansoutCommonList> res = client.readList();
335         LoansoutCommonList list = res.getEntity();
336         int statusCode = res.getStatus();
337
338         // Check the status code of the response: does it match
339         // the expected response(s)?
340         if(logger.isDebugEnabled()){
341             logger.debug(testName + ": status = " + statusCode);
342         }
343         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
344                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
345         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
346
347         // Optionally output additional data about list members for debugging.
348         boolean iterateThroughList = false;
349         if(iterateThroughList && logger.isDebugEnabled()){
350             List<LoansoutCommonList.LoanoutListItem> items =
351                     list.getLoanoutListItem();
352             int i = 0;
353             for(LoansoutCommonList.LoanoutListItem item : items){
354                 logger.debug(testName + ": list-item[" + i + "] csid=" +
355                         item.getCsid());
356                 logger.debug(testName + ": list-item[" + i + "] loanOutNumber=" +
357                         item.getLoanOutNumber());
358                 logger.debug(testName + ": list-item[" + i + "] URI=" +
359                         item.getUri());
360                 i++;
361             }
362         }
363
364     }
365
366     // Failure outcomes
367     // None at present.
368     // ---------------------------------------------------------------
369     // CRUD tests : UPDATE tests
370     // ---------------------------------------------------------------
371     // Success outcomes
372     /* (non-Javadoc)
373      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
374      */
375     @Override
376     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
377         dependsOnMethods = {"read"})
378     public void update(String testName) throws Exception {
379
380         // Perform setup.
381         setupUpdate(testName);
382
383         // Retrieve the contents of a resource to update.
384         LoanoutClient client = new LoanoutClient();
385         ClientResponse<MultipartInput> res =
386                 client.read(knownResourceId);
387         if(logger.isDebugEnabled()){
388             logger.debug(testName + ": read status = " + res.getStatus());
389         }
390         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
391
392         if(logger.isDebugEnabled()){
393             logger.debug("got object to update with ID: " + knownResourceId);
394         }
395         MultipartInput input = (MultipartInput) res.getEntity();
396         LoansoutCommon loanout = (LoansoutCommon) extractPart(input,
397                 client.getCommonPartName(), LoansoutCommon.class);
398         Assert.assertNotNull(loanout);
399
400         // Update the content of this resource.
401         loanout.setLoanOutNumber("updated-" + loanout.getLoanOutNumber());
402         loanout.setLoanReturnDate("updated-" + loanout.getLoanReturnDate());
403         if(logger.isDebugEnabled()){
404             logger.debug("to be updated object");
405             logger.debug(objectAsXmlString(loanout, LoansoutCommon.class));
406         }
407         // Submit the request to the service and store the response.
408         MultipartOutput output = new MultipartOutput();
409         OutputPart commonPart = output.addPart(loanout, MediaType.APPLICATION_XML_TYPE);
410         commonPart.getHeaders().add("label", client.getCommonPartName());
411
412         res = client.update(knownResourceId, output);
413         int statusCode = res.getStatus();
414         // Check the status code of the response: does it match the expected response(s)?
415         if(logger.isDebugEnabled()){
416             logger.debug(testName + ": status = " + statusCode);
417         }
418         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
419                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
420         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
421
422
423         input = (MultipartInput) res.getEntity();
424         LoansoutCommon updatedLoanout =
425                 (LoansoutCommon) extractPart(input,
426                         client.getCommonPartName(), LoansoutCommon.class);
427         Assert.assertNotNull(updatedLoanout);
428
429         Assert.assertEquals(updatedLoanout.getLoanReturnDate(),
430                 loanout.getLoanReturnDate(),
431                 "Data in updated object did not match submitted data.");
432
433     }
434
435     // Failure outcomes
436     // Placeholders until the three tests below can be uncommented.
437     // See Issue CSPACE-401.
438     /* (non-Javadoc)
439      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
440      */
441     @Override
442     public void updateWithEmptyEntityBody(String testName) throws Exception{
443     }
444     
445     /* (non-Javadoc)
446      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
447      */
448     @Override
449     public void updateWithMalformedXml(String testName) throws Exception {
450     }
451     
452     /* (non-Javadoc)
453      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
454      */
455     @Override
456     public void updateWithWrongXmlSchema(String testName) throws Exception {
457     }
458
459     /*
460     @Override
461     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
462         dependsOnMethods = {"create", "update", "testSubmitRequest"})
463     public void updateWithEmptyEntityBody(String testName) throws Exception {
464
465     // Perform setup.
466     setupUpdateWithEmptyEntityBody(testName);
467
468     // Submit the request to the service and store the response.
469     String method = REQUEST_TYPE.httpMethodName();
470     String url = getResourceURL(knownResourceId);
471     String mediaType = MediaType.APPLICATION_XML;
472     final String entity = "";
473     int statusCode = submitRequest(method, url, mediaType, entity);
474
475     // Check the status code of the response: does it match
476     // the expected response(s)?
477     if(logger.isDebugEnabled()){
478         logger.debug(testName + ": url=" + url +
479             " status=" + statusCode);
480      }
481     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
482     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
483     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484     }
485
486     @Override
487     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
488         dependsOnMethods = {"create", "update", "testSubmitRequest"})
489     public void updateWithMalformedXml(String testName) throws Exception {
490
491     // Perform setup.
492     setupUpdateWithMalformedXml(testName);
493
494     // Submit the request to the service and store the response.
495     String method = REQUEST_TYPE.httpMethodName();
496     String url = getResourceURL(knownResourceId);
497     String mediaType = MediaType.APPLICATION_XML;
498     final String entity = MALFORMED_XML_DATA;
499     int statusCode = submitRequest(method, url, mediaType, entity);
500
501     // Check the status code of the response: does it match
502     // the expected response(s)?
503     if(logger.isDebugEnabled()){
504         logger.debug(testName + ": url=" + url +
505          " status=" + statusCode);
506      }
507     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
508     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
509     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
510     }
511
512     @Override
513     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
514         dependsOnMethods = {"create", "update", "testSubmitRequest"})
515     public void updateWithWrongXmlSchema(String testName) throws Exception {
516
517     // Perform setup.
518     setupUpdateWithWrongXmlSchema(testName);
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 = WRONG_XML_SCHEMA_DATA;
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
539     /* (non-Javadoc)
540      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
541      */
542     @Override
543     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
544         dependsOnMethods = {"update", "testSubmitRequest"})
545     public void updateNonExistent(String testName) throws Exception {
546
547         // Perform setup.
548         setupUpdateNonExistent(testName);
549
550         // Submit the request to the service and store the response.
551         // Note: The ID used in this 'create' call may be arbitrary.
552         // The only relevant ID may be the one used in update(), below.
553         LoanoutClient client = new LoanoutClient();
554         MultipartOutput multipart = createLoanoutInstance(NON_EXISTENT_ID);
555         ClientResponse<MultipartInput> res =
556                 client.update(NON_EXISTENT_ID, multipart);
557         int statusCode = res.getStatus();
558
559         // Check the status code of the response: does it match
560         // the expected response(s)?
561         if(logger.isDebugEnabled()){
562             logger.debug(testName + ": status = " + statusCode);
563         }
564         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567     }
568
569     // ---------------------------------------------------------------
570     // CRUD tests : DELETE tests
571     // ---------------------------------------------------------------
572     // Success outcomes
573     /* (non-Javadoc)
574      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
575      */
576     @Override
577     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
578         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
579     public void delete(String testName) throws Exception {
580
581         // Perform setup.
582         setupDelete(testName);
583
584         // Submit the request to the service and store the response.
585         LoanoutClient client = new LoanoutClient();
586         ClientResponse<Response> res = client.delete(knownResourceId);
587         int statusCode = res.getStatus();
588
589         // Check the status code of the response: does it match
590         // the expected response(s)?
591         if(logger.isDebugEnabled()){
592             logger.debug(testName + ": status = " + statusCode);
593         }
594         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
595                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
596         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
597     }
598
599     // Failure outcomes
600     /* (non-Javadoc)
601      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
602      */
603     @Override
604     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
605         dependsOnMethods = {"delete"})
606     public void deleteNonExistent(String testName) throws Exception {
607
608         // Perform setup.
609         setupDeleteNonExistent(testName);
610
611         // Submit the request to the service and store the response.
612         LoanoutClient client = new LoanoutClient();
613         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
614         int statusCode = res.getStatus();
615
616         // Check the status code of the response: does it match
617         // the expected response(s)?
618         if(logger.isDebugEnabled()){
619             logger.debug(testName + ": status = " + statusCode);
620         }
621         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624     }
625
626     // ---------------------------------------------------------------
627     // Utility tests : tests of code used in tests above
628     // ---------------------------------------------------------------
629     /**
630      * Tests the code for manually submitting data that is used by several
631      * of the methods above.
632      */
633     @Test(dependsOnMethods = {"create", "read"})
634     public void testSubmitRequest() {
635
636         // Expected status code: 200 OK
637         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
638
639         // Submit the request to the service and store the response.
640         String method = ServiceRequestType.READ.httpMethodName();
641         String url = getResourceURL(knownResourceId);
642         int statusCode = submitRequest(method, url);
643
644         // Check the status code of the response: does it match
645         // the expected response(s)?
646         if(logger.isDebugEnabled()){
647             logger.debug("testSubmitRequest: url=" + url +
648                 " status=" + statusCode);
649         }
650         Assert.assertEquals(statusCode, EXPECTED_STATUS);
651
652     }
653
654     // ---------------------------------------------------------------
655     // Cleanup of resources created during testing
656     // ---------------------------------------------------------------
657
658     /**
659      * Deletes all resources created by tests, after all tests have been run.
660      *
661      * This cleanup method will always be run, even if one or more tests fail.
662      * For this reason, it attempts to remove all resources created
663      * at any point during testing, even if some of those resources
664      * may be expected to be deleted by certain tests.
665      */
666     @AfterClass(alwaysRun=true)
667     public void cleanUp() {
668         String noTest = System.getProperty("noTestCleanup");
669         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
670             if (logger.isDebugEnabled()) {
671                 logger.debug("Skipping Cleanup phase ...");
672             }
673             return;
674         }
675         if (logger.isDebugEnabled()) {
676             logger.debug("Cleaning up temporary resources created for testing ...");
677         }
678        LoanoutClient client = new LoanoutClient();
679        for (String resourceId : allResourceIdsCreated) {
680             // Note: Any non-success responses are ignored and not reported.
681             ClientResponse<Response> res = client.delete(resourceId);
682         }
683     }
684
685     // ---------------------------------------------------------------
686     // Utility methods used by tests above
687     // ---------------------------------------------------------------
688     /* (non-Javadoc)
689      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
690      */
691     @Override
692     public String getServicePathComponent() {
693         return SERVICE_PATH_COMPONENT;
694     }
695
696     /**
697      * Creates the loanout instance.
698      *
699      * @param identifier the identifier
700      * @return the multipart output
701      */
702     private MultipartOutput createLoanoutInstance(String identifier) {
703         return createLoanoutInstance(
704                 "loanoutNumber-" + identifier,
705                 "returnDate-" + identifier);
706     }
707
708     /**
709      * Creates the loanout instance.
710      *
711      * @param loanOutNumber the loan out number
712      * @param returnDate the return date
713      * @return the multipart output
714      */
715     private MultipartOutput createLoanoutInstance(String loanOutNumber,
716                 String returnDate) {
717         LoansoutCommon loanout = new LoansoutCommon();
718         loanout.setLoanOutNumber(loanOutNumber);
719         loanout.setLoanReturnDate(returnDate);
720         loanout.setBorrower(
721            "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'");
722         loanout.setBorrowersContact(
723             "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'");
724         loanout.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s.");
725         MultipartOutput multipart = new MultipartOutput();
726         OutputPart commonPart =
727             multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE);
728         commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName());
729
730         if(logger.isDebugEnabled()){
731             logger.debug("to be created, loanout common");
732             logger.debug(objectAsXmlString(loanout, LoansoutCommon.class));
733         }
734
735         return multipart;
736     }
737 }