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