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