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