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