]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b3370c00df52c066227e147bae6e3e0638711a81
[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.AbstractCommonListUtils;
35 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
36 import org.collectionspace.services.client.CollectionSpaceClient;
37 import org.collectionspace.services.client.MovementClient;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.movement.MovementsCommon;
40 import org.collectionspace.services.movement.MovementMethodsList;
41
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.collectionspace.services.client.PayloadInputPart;
45 import org.collectionspace.services.client.PayloadOutputPart;
46 import org.collectionspace.services.client.PoxPayloadIn;
47 import org.collectionspace.services.client.PoxPayloadOut;
48 import org.testng.Assert;
49 import org.testng.annotations.Test;
50
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 /**
55  * MovementServiceTest, carries out tests against a
56  * deployed and running Movement Service.
57  *
58  * $LastChangedRevision$
59  * $LastChangedDate$
60  */
61 public class MovementServiceTest extends AbstractServiceTestImpl {
62
63    /** The logger. */
64     private final String CLASS_NAME = MovementServiceTest.class.getName();
65     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
66
67     final String SERVICE_NAME = "movements";
68     final String SERVICE_PATH_COMPONENT = "movements";
69
70     // Instance variables specific to this test.
71     private String knownResourceId = null;
72     private final static String TIMESTAMP_UTC =
73             GregorianCalendarDateTimeUtils.timestampUTC();
74     
75     /* (non-Javadoc)
76      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
77      */
78     @Override
79     protected CollectionSpaceClient getClientInstance() {
80         return new MovementClient();
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         MovementClient client = new MovementClient();
104         String identifier = createIdentifier();
105         PoxPayloadOut multipart = createMovementInstance(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         MovementClient client = new MovementClient();
285         ClientResponse<String> res = client.read(knownResourceId);
286         assertStatusCode(res, testName);
287
288         // Get the common part of the response and verify that it is not null.
289         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
290         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
291         MovementsCommon movementCommon = null;
292         if (payloadInputPart != null) {
293                 movementCommon = (MovementsCommon) payloadInputPart.getBody();
294         }
295         Assert.assertNotNull(movementCommon);
296
297         // Check selected fields.
298
299         // Check the values of one or more date/time fields.
300         if (logger.isDebugEnabled()) {
301             logger.debug("locationDate=" + movementCommon.getLocationDate());
302             logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC);
303         }
304         Assert.assertTrue(movementCommon.getLocationDate().equals(TIMESTAMP_UTC));
305         Assert.assertTrue(movementCommon.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
306         Assert.assertNull(movementCommon.getRemovalDate());
307         
308         // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
309        if(logger.isDebugEnabled()){
310             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
311                     + "UTF-8 data received=" + movementCommon.getMovementNote());
312     }
313         Assert.assertEquals(movementCommon.getMovementNote(), getUTF8DataFragment(),
314                 "UTF-8 data retrieved '" + movementCommon.getMovementNote()
315                 + "' does not match expected data '" + getUTF8DataFragment());
316
317     }
318
319     // Failure outcomes
320     /* (non-Javadoc)
321      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
322      */
323     @Override
324     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
325         dependsOnMethods = {"read"})
326     public void readNonExistent(String testName) throws Exception {
327
328         if (logger.isDebugEnabled()) {
329             logger.debug(testBanner(testName, CLASS_NAME));
330         }
331         // Perform setup.
332         setupReadNonExistent();
333
334         // Submit the request to the service and store the response.
335         MovementClient client = new MovementClient();
336         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
337         int statusCode = res.getStatus();
338
339         // Check the status code of the response: does it match
340         // the expected response(s)?
341         if(logger.isDebugEnabled()){
342             logger.debug(testName + ": status = " + statusCode);
343         }
344         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
345                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
346         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
347     }
348
349     // ---------------------------------------------------------------
350     // CRUD tests : READ_LIST tests
351     // ---------------------------------------------------------------
352     // Success outcomes
353     /* (non-Javadoc)
354      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
355      */
356     @Override
357     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
358         dependsOnMethods = {"createList", "read"})
359     public void readList(String testName) throws Exception {
360
361         if (logger.isDebugEnabled()) {
362             logger.debug(testBanner(testName, CLASS_NAME));
363         }
364         // Perform setup.
365         setupReadList();
366
367         // Submit the request to the service and store the response.
368         MovementClient client = new MovementClient();
369         ClientResponse<AbstractCommonList> res = client.readList();
370         assertStatusCode(res, testName);
371         AbstractCommonList list = res.getEntity();
372
373         // Optionally output additional data about list members for debugging.
374         if(logger.isTraceEnabled()){
375                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
376         }
377     }
378
379     // Failure outcomes
380     // None at present.
381     // ---------------------------------------------------------------
382     // CRUD tests : UPDATE tests
383     // ---------------------------------------------------------------
384     // Success outcomes
385     /* (non-Javadoc)
386      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
387      */
388     @Override
389     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
390         dependsOnMethods = {"read"})
391     public void update(String testName) throws Exception {
392
393         if (logger.isDebugEnabled()) {
394             logger.debug(testBanner(testName, CLASS_NAME));
395         }
396         // Perform setup.
397         setupUpdate();
398
399         // Retrieve the contents of a resource to update.
400         MovementClient client = new MovementClient();
401         ClientResponse<String> res = client.read(knownResourceId);
402                         assertStatusCode(res, testName);
403         assertStatusCode(res, testName);
404
405         // Extract the common part from the response.
406         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
407         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
408         MovementsCommon movementCommon = null;
409         if (payloadInputPart != null) {
410                 movementCommon = (MovementsCommon) payloadInputPart.getBody();
411         }
412         Assert.assertNotNull(movementCommon);
413
414         // Update its content.
415         movementCommon.setMovementReferenceNumber("updated-" + movementCommon.getMovementReferenceNumber());
416         movementCommon.setMovementNote("updated movement note-" + movementCommon.getMovementNote());
417         movementCommon.setNormalLocation(""); // Test deletion of existing string value
418
419         String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
420         movementCommon.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value
421         movementCommon.setRemovalDate(currentTimestamp);
422
423         if(logger.isDebugEnabled()){
424             logger.debug("to be updated object");
425             logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));
426         }
427
428         // Submit the request to the service and store the response.
429         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
430         PayloadOutputPart commonPart = output.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE);
431         commonPart.setLabel(client.getCommonPartName());
432         res = client.update(knownResourceId, output);
433         assertStatusCode(res, testName);
434
435         // Extract the updated common part from the response.
436         input = new PoxPayloadIn(res.getEntity());
437         payloadInputPart = input.getPart(client.getCommonPartName());
438         MovementsCommon updatedMovementCommon = null;
439         if (payloadInputPart != null) {
440                 updatedMovementCommon = (MovementsCommon) payloadInputPart.getBody();
441         }
442         Assert.assertNotNull(movementCommon);
443         if(logger.isDebugEnabled()){
444             logger.debug("updated object");
445             logger.debug(objectAsXmlString(updatedMovementCommon, MovementsCommon.class));
446         }
447
448         // Check selected fields in the updated common part.
449         
450         // By submitting an empty string in the update payload, the value of this field
451         // in the object created from the response payload will be null.
452         Assert.assertNull(updatedMovementCommon.getNormalLocation(), "Data in updated object did not match submitted data.");
453         if(logger.isDebugEnabled()){
454             logger.debug("Normal location after update=|" + updatedMovementCommon.getNormalLocation() + "|");
455         }
456
457         Assert.assertEquals(updatedMovementCommon.getMovementReferenceNumber(),
458             movementCommon.getMovementReferenceNumber(),
459             "Data in updated object did not match submitted data.");
460         Assert.assertEquals(updatedMovementCommon.getMovementNote(),
461             movementCommon.getMovementNote(),
462             "Data in updated object did not match submitted data.");
463         Assert.assertNull(updatedMovementCommon.getPlannedRemovalDate());
464         Assert.assertEquals(updatedMovementCommon.getRemovalDate(),
465             movementCommon.getRemovalDate(),
466             "Data in updated object did not match submitted data.");
467
468         if(logger.isDebugEnabled()){
469             logger.debug("UTF-8 data sent=" + movementCommon.getMovementNote() + "\n"
470                     + "UTF-8 data received=" + updatedMovementCommon.getMovementNote());
471     }
472         Assert.assertTrue(updatedMovementCommon.getMovementNote().contains(getUTF8DataFragment()),
473                 "UTF-8 data retrieved '" + updatedMovementCommon.getMovementNote()
474                 + "' does not contain expected data '" + getUTF8DataFragment());
475         Assert.assertEquals(updatedMovementCommon.getMovementNote(),
476                 movementCommon.getMovementNote(),
477                 "Data in updated object did not match submitted data.");
478
479     }
480
481     // Failure outcomes
482     // Placeholders until the three tests below can be uncommented.
483     // See Issue CSPACE-401.
484     /* (non-Javadoc)
485      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
486      */
487     @Override
488     public void updateWithEmptyEntityBody(String testName) throws Exception{
489         //Should this really be empty?
490     }
491     
492     /* (non-Javadoc)
493      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
494      */
495     @Override
496     public void updateWithMalformedXml(String testName) throws Exception {
497         //Should this really be empty?
498     }
499     
500     /* (non-Javadoc)
501      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
502      */
503     @Override
504     public void updateWithWrongXmlSchema(String testName) throws Exception {
505         //Should this really be empty?
506     }
507
508     /*
509     @Override
510     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
511         dependsOnMethods = {"create", "update", "testSubmitRequest"})
512     public void updateWithEmptyEntityBody(String testName) throws Exception {
513
514         if (logger.isDebugEnabled()) {
515             logger.debug(testBanner(testName, CLASS_NAME));
516         }
517         // Perform setup.
518         setupUpdateWithEmptyEntityBody();
519
520         // Submit the request to the service and store the response.
521         String method = REQUEST_TYPE.httpMethodName();
522         String url = getResourceURL(knownResourceId);
523         String mediaType = MediaType.APPLICATION_XML;
524         final String entity = "";
525         int statusCode = submitRequest(method, url, mediaType, entity);
526
527         // Check the status code of the response: does it match
528         // the expected response(s)?
529         if(logger.isDebugEnabled()){
530             logger.debug(testName + ": url=" + url +
531                 " status=" + statusCode);
532          }
533         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
536     }
537
538     @Override
539     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
540         dependsOnMethods = {"create", "update", "testSubmitRequest"})
541     public void updateWithMalformedXml(String testName) throws Exception {
542
543         if (logger.isDebugEnabled()) {
544             logger.debug(testBanner(testName, CLASS_NAME));
545         }
546         // Perform setup.
547         setupUpdateWithMalformedXml();
548
549         // Submit the request to the service and store the response.
550         String method = REQUEST_TYPE.httpMethodName();
551         String url = getResourceURL(knownResourceId);
552         String mediaType = MediaType.APPLICATION_XML;
553         final String entity = MALFORMED_XML_DATA;
554         int statusCode = submitRequest(method, url, mediaType, entity);
555
556         // Check the status code of the response: does it match
557         // the expected response(s)?
558         if(logger.isDebugEnabled()){
559             logger.debug(testName + ": url=" + url +
560              " status=" + statusCode);
561          }
562         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565     }
566
567     @Override
568     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569         dependsOnMethods = {"create", "update", "testSubmitRequest"})
570     public void updateWithWrongXmlSchema(String testName) throws Exception {
571
572         if (logger.isDebugEnabled()) {
573             logger.debug(testBanner(testName, CLASS_NAME));
574         }
575         // Perform setup.
576         setupUpdateWithWrongXmlSchema();
577
578         // Submit the request to the service and store the response.
579         String method = REQUEST_TYPE.httpMethodName();
580         String url = getResourceURL(knownResourceId);
581         String mediaType = MediaType.APPLICATION_XML;
582         final String entity = WRONG_XML_SCHEMA_DATA;
583         int statusCode = submitRequest(method, url, mediaType, entity);
584
585         // Check the status code of the response: does it match
586         // the expected response(s)?
587         if(logger.isDebugEnabled()){
588             logger.debug(testName + ": url=" + url +
589             " status=" + statusCode);
590          }
591         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594     }
595      */
596
597     /* (non-Javadoc)
598      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
599      */
600     @Override
601     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
602         dependsOnMethods = {"update", "testSubmitRequest"})
603     public void updateNonExistent(String testName) throws Exception {
604
605         if (logger.isDebugEnabled()) {
606             logger.debug(testBanner(testName, CLASS_NAME));
607         }
608         // Perform setup.
609         setupUpdateNonExistent();
610
611         // Submit the request to the service and store the response.
612         // Note: The ID used in this 'create' call may be arbitrary.
613         // The only relevant ID may be the one used in update(), below.
614         MovementClient client = new MovementClient();
615         PoxPayloadOut multipart = createMovementInstance(NON_EXISTENT_ID);
616         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
617         int statusCode = res.getStatus();
618
619         // Check the status code of the response: does it match
620         // the expected response(s)?
621         if(logger.isDebugEnabled()){
622             logger.debug(testName + ": status = " + statusCode);
623         }
624         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
625                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
626         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
627     }
628
629     // ---------------------------------------------------------------
630     // CRUD tests : DELETE tests
631     // ---------------------------------------------------------------
632     // Success outcomes
633     /* (non-Javadoc)
634      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
635      */
636
637     @Override
638     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
639         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
640     public void delete(String testName) throws Exception {
641
642         if (logger.isDebugEnabled()) {
643             logger.debug(testBanner(testName, CLASS_NAME));
644         }
645         /*
646         // Perform setup.
647         setupDelete();
648
649         // Submit the request to the service and store the response.
650         MovementClient client = new MovementClient();
651         ClientResponse<Response> res = client.delete(knownResourceId);
652         int statusCode = res.getStatus();
653
654         // Check the status code of the response: does it match
655         // the expected response(s)?
656         if(logger.isDebugEnabled()){
657             logger.debug(testName + ": status = " + statusCode);
658         }
659         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
660                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
661         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
662      *
663      */
664     }
665
666
667     // Failure outcomes
668     /* (non-Javadoc)
669      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
670      */
671     @Override
672     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
673         dependsOnMethods = {"delete"})
674     public void deleteNonExistent(String testName) throws Exception {
675
676         if (logger.isDebugEnabled()) {
677             logger.debug(testBanner(testName, CLASS_NAME));
678         }
679         // Perform setup.
680         setupDeleteNonExistent();
681
682         // Submit the request to the service and store the response.
683         MovementClient client = new MovementClient();
684         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
685         int statusCode = res.getStatus();
686
687         // Check the status code of the response: does it match
688         // the expected response(s)?
689         if(logger.isDebugEnabled()){
690             logger.debug(testName + ": status = " + statusCode);
691         }
692         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
693                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
694         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
695     }
696
697     // ---------------------------------------------------------------
698     // Utility tests : tests of code used in tests above
699     // ---------------------------------------------------------------
700     /**
701      * Tests the code for manually submitting data that is used by several
702      * of the methods above.
703      */
704     @Test(dependsOnMethods = {"create", "read"})
705     public void testSubmitRequest() {
706
707         // Expected status code: 200 OK
708         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
709
710         // Submit the request to the service and store the response.
711         String method = ServiceRequestType.READ.httpMethodName();
712         String url = getResourceURL(knownResourceId);
713         int statusCode = submitRequest(method, url);
714
715         // Check the status code of the response: does it match
716         // the expected response(s)?
717         if(logger.isDebugEnabled()){
718             logger.debug("testSubmitRequest: url=" + url +
719                 " status=" + statusCode);
720         }
721         Assert.assertEquals(statusCode, EXPECTED_STATUS);
722
723     }
724
725     // ---------------------------------------------------------------
726     // Utility methods used by tests above
727     // ---------------------------------------------------------------
728
729     @Override
730     protected String getServiceName() {
731         return SERVICE_NAME;
732     }
733
734     /* (non-Javadoc)
735      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
736      */
737     @Override
738     public String getServicePathComponent() {
739         return SERVICE_PATH_COMPONENT;
740     }
741
742     /**
743      * Creates the movement instance.
744      *
745      * @param identifier the identifier
746      * @return the multipart output
747      */
748     private PoxPayloadOut createMovementInstance(String identifier) {
749         return createInstance("movementReferenceNumber-" + identifier);
750     }
751
752     /**
753      * Creates an instance of a Movement record for testing.
754      *
755      * @param movementReferenceNumber A movement reference number.
756      * @return Multipart output suitable for use as a payload
757      *     in a create or update request.
758      */
759     @Override
760     public PoxPayloadOut createInstance(String movementReferenceNumber) {
761         MovementsCommon movementCommon = new MovementsCommon();
762         // FIXME: Values of currentLocation, normalLocation,
763         // and movementContact should be refNames.
764         movementCommon.setCurrentLocation("currentLocation value");
765         movementCommon.setCurrentLocationFitness("currentLocationFitness value");
766         movementCommon.setCurrentLocationNote("currentLocationNote value");
767         movementCommon.setLocationDate(TIMESTAMP_UTC);
768         movementCommon.setNormalLocation("normalLocation value");
769         movementCommon.setMovementContact("movementContact value");
770         MovementMethodsList movementMethodsList = new MovementMethodsList();
771         List<String> methods = movementMethodsList.getMovementMethod();
772         // @TODO Use properly formatted refNames for representative movement
773         // methods in this example record. The values below are placeholders.
774         String identifier = createIdentifier();
775         methods.add("First Movement Method-" + identifier);
776         methods.add("Second Movement Method-" + identifier);
777         movementCommon.setMovementMethods(movementMethodsList);
778         movementCommon.setMovementNote(getUTF8DataFragment());
779         movementCommon.setMovementReferenceNumber(movementReferenceNumber);
780         movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC);
781         movementCommon.setRemovalDate(""); // Test empty date value
782         movementCommon.setReasonForMove("reasonForMove value");
783
784         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
785         PayloadOutputPart commonPart =
786             multipart.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE);
787         commonPart.setLabel(new MovementClient().getCommonPartName());
788
789         if(logger.isDebugEnabled()){
790             logger.debug("to be created, movement common");
791             logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));
792         }
793
794         return multipart;
795     }
796
797 }