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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
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;
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;
42 import org.jboss.resteasy.client.ClientResponse;
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;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
55 * MovementServiceTest, carries out tests against a
56 * deployed and running Movement Service.
58 * $LastChangedRevision$
61 public class MovementServiceTest extends AbstractServiceTestImpl {
64 private final String CLASS_NAME = MovementServiceTest.class.getName();
65 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
67 final String SERVICE_NAME = "movements";
68 final String SERVICE_PATH_COMPONENT = "movements";
70 // Instance variables specific to this test.
71 private String knownResourceId = null;
72 private final static String TIMESTAMP_UTC =
73 GregorianCalendarDateTimeUtils.timestampUTC();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79 protected CollectionSpaceClient getClientInstance() {
80 return new MovementClient();
83 // ---------------------------------------------------------------
84 // CRUD tests : CREATE tests
85 // ---------------------------------------------------------------
88 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
91 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
92 public void create(String testName) throws Exception {
94 if (logger.isDebugEnabled()) {
95 logger.debug(testBanner(testName, CLASS_NAME));
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).
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);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
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);
119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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));
138 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
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++){
150 // Placeholders until the three tests below can be uncommented.
151 // See Issue CSPACE-401.
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
156 public void createWithEmptyEntityBody(String testName) throws Exception {
157 //Should this really be empty?
161 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
164 public void createWithMalformedXml(String testName) throws Exception {
165 //Should this really be empty?
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
172 public void createWithWrongXmlSchema(String testName) throws Exception {
173 //Should this really be empty?
178 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
179 dependsOnMethods = {"create", "testSubmitRequest"})
180 public void createWithEmptyEntityBody(String testName) throws Exception {
182 if (logger.isDebugEnabled()) {
183 logger.debug(testBanner(testName, CLASS_NAME));
186 setupCreateWithEmptyEntityBody();
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);
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);
201 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
202 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
203 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
207 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
208 dependsOnMethods = {"create", "testSubmitRequest"})
209 public void createWithMalformedXml(String testName) throws Exception {
211 if (logger.isDebugEnabled()) {
212 logger.debug(testBanner(testName, CLASS_NAME));
215 setupCreateWithMalformedXml();
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);
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);
230 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
231 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
232 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
237 dependsOnMethods = {"create", "testSubmitRequest"})
238 public void createWithWrongXmlSchema(String testName) throws Exception {
240 if (logger.isDebugEnabled()) {
241 logger.debug(testBanner(testName, CLASS_NAME));
244 setupCreateWithWrongXmlSchema();
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);
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);
259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265 // ---------------------------------------------------------------
266 // CRUD tests : READ tests
267 // ---------------------------------------------------------------
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
273 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
274 dependsOnMethods = {"create"})
275 public void read(String testName) throws Exception {
277 if (logger.isDebugEnabled()) {
278 logger.debug(testBanner(testName, CLASS_NAME));
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);
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();
295 Assert.assertNotNull(movementCommon);
297 // Check selected fields.
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);
304 Assert.assertTrue(movementCommon.getLocationDate().equals(TIMESTAMP_UTC));
305 Assert.assertTrue(movementCommon.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
306 Assert.assertNull(movementCommon.getRemovalDate());
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());
313 Assert.assertEquals(movementCommon.getMovementNote(), getUTF8DataFragment(),
314 "UTF-8 data retrieved '" + movementCommon.getMovementNote()
315 + "' does not match expected data '" + getUTF8DataFragment());
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
324 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
325 dependsOnMethods = {"read"})
326 public void readNonExistent(String testName) throws Exception {
328 if (logger.isDebugEnabled()) {
329 logger.debug(testBanner(testName, CLASS_NAME));
332 setupReadNonExistent();
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();
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);
344 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
345 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
346 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
349 // ---------------------------------------------------------------
350 // CRUD tests : READ_LIST tests
351 // ---------------------------------------------------------------
354 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
357 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
358 dependsOnMethods = {"createList", "read"})
359 public void readList(String testName) throws Exception {
361 if (logger.isDebugEnabled()) {
362 logger.debug(testBanner(testName, CLASS_NAME));
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();
373 // Optionally output additional data about list members for debugging.
374 if(logger.isTraceEnabled()){
375 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
381 // ---------------------------------------------------------------
382 // CRUD tests : UPDATE tests
383 // ---------------------------------------------------------------
386 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
389 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
390 dependsOnMethods = {"read"})
391 public void update(String testName) throws Exception {
393 if (logger.isDebugEnabled()) {
394 logger.debug(testBanner(testName, CLASS_NAME));
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);
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();
412 Assert.assertNotNull(movementCommon);
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
419 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
420 movementCommon.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value
421 movementCommon.setRemovalDate(currentTimestamp);
423 if(logger.isDebugEnabled()){
424 logger.debug("to be updated object");
425 logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));
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);
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();
442 Assert.assertNotNull(movementCommon);
443 if(logger.isDebugEnabled()){
444 logger.debug("updated object");
445 logger.debug(objectAsXmlString(updatedMovementCommon, MovementsCommon.class));
448 // Check selected fields in the updated common part.
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() + "|");
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.");
468 if(logger.isDebugEnabled()){
469 logger.debug("UTF-8 data sent=" + movementCommon.getMovementNote() + "\n"
470 + "UTF-8 data received=" + updatedMovementCommon.getMovementNote());
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.");
482 // Placeholders until the three tests below can be uncommented.
483 // See Issue CSPACE-401.
485 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
488 public void updateWithEmptyEntityBody(String testName) throws Exception{
489 //Should this really be empty?
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
496 public void updateWithMalformedXml(String testName) throws Exception {
497 //Should this really be empty?
501 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
504 public void updateWithWrongXmlSchema(String testName) throws Exception {
505 //Should this really be empty?
510 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
511 dependsOnMethods = {"create", "update", "testSubmitRequest"})
512 public void updateWithEmptyEntityBody(String testName) throws Exception {
514 if (logger.isDebugEnabled()) {
515 logger.debug(testBanner(testName, CLASS_NAME));
518 setupUpdateWithEmptyEntityBody();
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);
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);
533 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
539 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
540 dependsOnMethods = {"create", "update", "testSubmitRequest"})
541 public void updateWithMalformedXml(String testName) throws Exception {
543 if (logger.isDebugEnabled()) {
544 logger.debug(testBanner(testName, CLASS_NAME));
547 setupUpdateWithMalformedXml();
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);
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);
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
568 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569 dependsOnMethods = {"create", "update", "testSubmitRequest"})
570 public void updateWithWrongXmlSchema(String testName) throws Exception {
572 if (logger.isDebugEnabled()) {
573 logger.debug(testBanner(testName, CLASS_NAME));
576 setupUpdateWithWrongXmlSchema();
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);
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);
591 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
598 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
601 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
602 dependsOnMethods = {"update", "testSubmitRequest"})
603 public void updateNonExistent(String testName) throws Exception {
605 if (logger.isDebugEnabled()) {
606 logger.debug(testBanner(testName, CLASS_NAME));
609 setupUpdateNonExistent();
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();
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);
624 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
625 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
626 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629 // ---------------------------------------------------------------
630 // CRUD tests : DELETE tests
631 // ---------------------------------------------------------------
634 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
638 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
639 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
640 public void delete(String testName) throws Exception {
642 if (logger.isDebugEnabled()) {
643 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
659 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
660 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
661 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
672 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
673 dependsOnMethods = {"delete"})
674 public void deleteNonExistent(String testName) throws Exception {
676 if (logger.isDebugEnabled()) {
677 logger.debug(testBanner(testName, CLASS_NAME));
680 setupDeleteNonExistent();
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();
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);
692 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
693 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
694 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
697 // ---------------------------------------------------------------
698 // Utility tests : tests of code used in tests above
699 // ---------------------------------------------------------------
701 * Tests the code for manually submitting data that is used by several
702 * of the methods above.
704 @Test(dependsOnMethods = {"create", "read"})
705 public void testSubmitRequest() {
707 // Expected status code: 200 OK
708 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
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);
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);
721 Assert.assertEquals(statusCode, EXPECTED_STATUS);
725 // ---------------------------------------------------------------
726 // Utility methods used by tests above
727 // ---------------------------------------------------------------
730 protected String getServiceName() {
735 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
738 public String getServicePathComponent() {
739 return SERVICE_PATH_COMPONENT;
743 * Creates the movement instance.
745 * @param identifier the identifier
746 * @return the multipart output
748 private PoxPayloadOut createMovementInstance(String identifier) {
749 return createInstance("movementReferenceNumber-" + identifier);
753 * Creates an instance of a Movement record for testing.
755 * @param movementReferenceNumber A movement reference number.
756 * @return Multipart output suitable for use as a payload
757 * in a create or update request.
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");
784 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
785 PayloadOutputPart commonPart =
786 multipart.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE);
787 commonPart.setLabel(new MovementClient().getCommonPartName());
789 if(logger.isDebugEnabled()){
790 logger.debug("to be created, movement common");
791 logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));