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