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