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.client.CollectionSpaceClient;
35 import org.collectionspace.services.client.MovementClient;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.collectionspace.services.movement.MovementsCommon;
38 import org.collectionspace.services.movement.MovementsCommonList;
39 import org.collectionspace.services.movement.MovementMethodsList;
41 import org.jboss.resteasy.client.ClientResponse;
43 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
44 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
45 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
46 import org.testng.Assert;
47 import org.testng.annotations.Test;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 * MovementServiceTest, carries out tests against a
54 * deployed and running Movement Service.
56 * $LastChangedRevision$
59 public class MovementServiceTest extends AbstractServiceTestImpl {
62 private final String CLASS_NAME = MovementServiceTest.class.getName();
63 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
65 // Instance variables specific to this test.
66 /** The service path component. */
67 final String SERVICE_PATH_COMPONENT = "movements";
69 /** The known resource id. */
70 private String knownResourceId = null;
73 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
76 protected CollectionSpaceClient getClientInstance() {
77 return new MovementClient();
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
84 protected AbstractCommonList getAbstractCommonList(
85 ClientResponse<AbstractCommonList> response) {
86 return response.getEntity(MovementsCommonList.class);
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
97 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
98 public void create(String testName) throws Exception {
100 if (logger.isDebugEnabled()) {
101 logger.debug(testBanner(testName, CLASS_NAME));
103 // Perform setup, such as initializing the type of service request
104 // (e.g. CREATE, DELETE), its valid and expected status codes, and
105 // its associated HTTP method name (e.g. POST, DELETE).
108 // Submit the request to the service and store the response.
109 MovementClient client = new MovementClient();
110 String identifier = createIdentifier();
111 MultipartOutput multipart = createMovementInstance(identifier);
112 ClientResponse<Response> res = client.create(multipart);
114 int statusCode = res.getStatus();
116 // Check the status code of the response: does it match
117 // the expected response(s)?
120 // Does it fall within the set of valid status codes?
121 // Does it exactly match the expected status code?
122 if(logger.isDebugEnabled()){
123 logger.debug(testName + ": status = " + statusCode);
125 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
126 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
127 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
129 // Store the ID returned from the first resource created
130 // for additional tests below.
131 if (knownResourceId == null){
132 knownResourceId = extractId(res);
133 if (logger.isDebugEnabled()) {
134 logger.debug(testName + ": knownResourceId=" + knownResourceId);
138 // Store the IDs from every resource created by tests,
139 // so they can be deleted after tests have been run.
140 allResourceIdsCreated.add(extractId(res));
144 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
147 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
148 dependsOnMethods = {"create"})
149 public void createList(String testName) throws Exception {
150 for(int i = 0; i < 3; i++){
156 // Placeholders until the three tests below can be uncommented.
157 // See Issue CSPACE-401.
159 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
162 public void createWithEmptyEntityBody(String testName) throws Exception {
163 //Should this really be empty?
167 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
170 public void createWithMalformedXml(String testName) throws Exception {
171 //Should this really be empty?
175 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
178 public void createWithWrongXmlSchema(String testName) throws Exception {
179 //Should this really be empty?
184 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
185 dependsOnMethods = {"create", "testSubmitRequest"})
186 public void createWithEmptyEntityBody(String testName) throws Exception {
188 if (logger.isDebugEnabled()) {
189 logger.debug(testBanner(testName, CLASS_NAME));
192 setupCreateWithEmptyEntityBody();
194 // Submit the request to the service and store the response.
195 String method = REQUEST_TYPE.httpMethodName();
196 String url = getServiceRootURL();
197 String mediaType = MediaType.APPLICATION_XML;
198 final String entity = "";
199 int statusCode = submitRequest(method, url, mediaType, entity);
201 // Check the status code of the response: does it match
202 // the expected response(s)?
203 if(logger.isDebugEnabled()){
204 logger.debug("createWithEmptyEntityBody url=" + url +
205 " status=" + statusCode);
207 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
208 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
209 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
213 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
214 dependsOnMethods = {"create", "testSubmitRequest"})
215 public void createWithMalformedXml(String testName) throws Exception {
217 if (logger.isDebugEnabled()) {
218 logger.debug(testBanner(testName, CLASS_NAME));
221 setupCreateWithMalformedXml();
223 // Submit the request to the service and store the response.
224 String method = REQUEST_TYPE.httpMethodName();
225 String url = getServiceRootURL();
226 String mediaType = MediaType.APPLICATION_XML;
227 final String entity = MALFORMED_XML_DATA; // Constant from base class.
228 int statusCode = submitRequest(method, url, mediaType, entity);
230 // Check the status code of the response: does it match
231 // the expected response(s)?
232 if(logger.isDebugEnabled()){
233 logger.debug(testName + ": url=" + url +
234 " status=" + statusCode);
236 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
237 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
238 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
242 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
243 dependsOnMethods = {"create", "testSubmitRequest"})
244 public void createWithWrongXmlSchema(String testName) throws Exception {
246 if (logger.isDebugEnabled()) {
247 logger.debug(testBanner(testName, CLASS_NAME));
250 setupCreateWithWrongXmlSchema();
252 // Submit the request to the service and store the response.
253 String method = REQUEST_TYPE.httpMethodName();
254 String url = getServiceRootURL();
255 String mediaType = MediaType.APPLICATION_XML;
256 final String entity = WRONG_XML_SCHEMA_DATA;
257 int statusCode = submitRequest(method, url, mediaType, entity);
259 // Check the status code of the response: does it match
260 // the expected response(s)?
261 if(logger.isDebugEnabled()){
262 logger.debug(testName + ": url=" + url +
263 " status=" + statusCode);
265 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
266 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
271 // ---------------------------------------------------------------
272 // CRUD tests : READ tests
273 // ---------------------------------------------------------------
276 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
279 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
280 dependsOnMethods = {"create"})
281 public void read(String testName) throws Exception {
283 if (logger.isDebugEnabled()) {
284 logger.debug(testBanner(testName, CLASS_NAME));
289 // Submit the request to the service and store the response.
290 MovementClient client = new MovementClient();
291 ClientResponse<MultipartInput> res = client.read(knownResourceId);
292 int statusCode = res.getStatus();
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 if(logger.isDebugEnabled()){
297 logger.debug(testName + ": status = " + statusCode);
299 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
300 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
301 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
303 MultipartInput input = (MultipartInput) res.getEntity();
304 MovementsCommon movement = (MovementsCommon) extractPart(input,
305 client.getCommonPartName(), MovementsCommon.class);
306 Assert.assertNotNull(movement);
311 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
314 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
315 dependsOnMethods = {"read"})
316 public void readNonExistent(String testName) throws Exception {
318 if (logger.isDebugEnabled()) {
319 logger.debug(testBanner(testName, CLASS_NAME));
322 setupReadNonExistent();
324 // Submit the request to the service and store the response.
325 MovementClient client = new MovementClient();
326 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
327 int statusCode = res.getStatus();
329 // Check the status code of the response: does it match
330 // the expected response(s)?
331 if(logger.isDebugEnabled()){
332 logger.debug(testName + ": status = " + statusCode);
334 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
335 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
336 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
339 // ---------------------------------------------------------------
340 // CRUD tests : READ_LIST tests
341 // ---------------------------------------------------------------
344 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
347 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
348 dependsOnMethods = {"createList", "read"})
349 public void readList(String testName) throws Exception {
351 if (logger.isDebugEnabled()) {
352 logger.debug(testBanner(testName, CLASS_NAME));
357 // Submit the request to the service and store the response.
358 MovementClient client = new MovementClient();
359 ClientResponse<MovementsCommonList> res = client.readList();
360 MovementsCommonList list = res.getEntity();
361 int statusCode = res.getStatus();
363 // Check the status code of the response: does it match
364 // the expected response(s)?
365 if(logger.isDebugEnabled()){
366 logger.debug(testName + ": status = " + statusCode);
368 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
369 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
370 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
372 // Optionally output additional data about list members for debugging.
373 boolean iterateThroughList = true;
374 if(iterateThroughList && logger.isDebugEnabled()){
375 List<MovementsCommonList.MovementListItem> items =
376 list.getMovementListItem();
378 for(MovementsCommonList.MovementListItem item : items){
379 logger.debug(testName + ": list-item[" + i + "] csid=" +
381 logger.debug(testName + ": list-item[" + i + "] movementReferenceNumber=" +
382 item.getMovementReferenceNumber());
383 logger.debug(testName + ": list-item[" + i + "] locationDate=" +
384 item.getLocationDate());
385 logger.debug(testName + ": list-item[" + i + "] URI=" +
395 // ---------------------------------------------------------------
396 // CRUD tests : UPDATE tests
397 // ---------------------------------------------------------------
400 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
403 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
404 dependsOnMethods = {"read"})
405 public void update(String testName) throws Exception {
407 if (logger.isDebugEnabled()) {
408 logger.debug(testBanner(testName, CLASS_NAME));
413 // Retrieve the contents of a resource to update.
414 MovementClient client = new MovementClient();
415 ClientResponse<MultipartInput> res =
416 client.read(knownResourceId);
417 if(logger.isDebugEnabled()){
418 logger.debug(testName + ": read status = " + res.getStatus());
420 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
422 if(logger.isDebugEnabled()){
423 logger.debug("got object to update with ID: " + knownResourceId);
425 MultipartInput input = (MultipartInput) res.getEntity();
426 MovementsCommon movement = (MovementsCommon) extractPart(input,
427 client.getCommonPartName(), MovementsCommon.class);
428 Assert.assertNotNull(movement);
430 // Update the content of this resource.
431 movement.setMovementReferenceNumber("updated-" + movement.getMovementReferenceNumber());
432 movement.setMovementNote("updated movement note-" + movement.getMovementNote());
433 if(logger.isDebugEnabled()){
434 logger.debug("to be updated object");
435 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
437 // Submit the request to the service and store the response.
438 MultipartOutput output = new MultipartOutput();
439 OutputPart commonPart = output.addPart(movement, MediaType.APPLICATION_XML_TYPE);
440 commonPart.getHeaders().add("label", client.getCommonPartName());
442 res = client.update(knownResourceId, output);
443 int statusCode = res.getStatus();
444 // Check the status code of the response: does it match the expected response(s)?
445 if(logger.isDebugEnabled()){
446 logger.debug(testName + ": status = " + statusCode);
448 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
449 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
450 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
453 input = (MultipartInput) res.getEntity();
454 MovementsCommon updatedMovement =
455 (MovementsCommon) extractPart(input,
456 client.getCommonPartName(), MovementsCommon.class);
457 Assert.assertNotNull(updatedMovement);
459 Assert.assertEquals(updatedMovement.getMovementNote(),
460 movement.getMovementNote(),
461 "Data in updated object did not match submitted data.");
466 // Placeholders until the three tests below can be uncommented.
467 // See Issue CSPACE-401.
469 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
472 public void updateWithEmptyEntityBody(String testName) throws Exception{
473 //Should this really be empty?
477 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
480 public void updateWithMalformedXml(String testName) throws Exception {
481 //Should this really be empty?
485 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
488 public void updateWithWrongXmlSchema(String testName) throws Exception {
489 //Should this really be empty?
494 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
495 dependsOnMethods = {"create", "update", "testSubmitRequest"})
496 public void updateWithEmptyEntityBody(String testName) throws Exception {
498 if (logger.isDebugEnabled()) {
499 logger.debug(testBanner(testName, CLASS_NAME));
502 setupUpdateWithEmptyEntityBody();
504 // Submit the request to the service and store the response.
505 String method = REQUEST_TYPE.httpMethodName();
506 String url = getResourceURL(knownResourceId);
507 String mediaType = MediaType.APPLICATION_XML;
508 final String entity = "";
509 int statusCode = submitRequest(method, url, mediaType, entity);
511 // Check the status code of the response: does it match
512 // the expected response(s)?
513 if(logger.isDebugEnabled()){
514 logger.debug(testName + ": url=" + url +
515 " status=" + statusCode);
517 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
518 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
519 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
523 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
524 dependsOnMethods = {"create", "update", "testSubmitRequest"})
525 public void updateWithMalformedXml(String testName) throws Exception {
527 if (logger.isDebugEnabled()) {
528 logger.debug(testBanner(testName, CLASS_NAME));
531 setupUpdateWithMalformedXml();
533 // Submit the request to the service and store the response.
534 String method = REQUEST_TYPE.httpMethodName();
535 String url = getResourceURL(knownResourceId);
536 String mediaType = MediaType.APPLICATION_XML;
537 final String entity = MALFORMED_XML_DATA;
538 int statusCode = submitRequest(method, url, mediaType, entity);
540 // Check the status code of the response: does it match
541 // the expected response(s)?
542 if(logger.isDebugEnabled()){
543 logger.debug(testName + ": url=" + url +
544 " status=" + statusCode);
546 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
552 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
553 dependsOnMethods = {"create", "update", "testSubmitRequest"})
554 public void updateWithWrongXmlSchema(String testName) throws Exception {
556 if (logger.isDebugEnabled()) {
557 logger.debug(testBanner(testName, CLASS_NAME));
560 setupUpdateWithWrongXmlSchema();
562 // Submit the request to the service and store the response.
563 String method = REQUEST_TYPE.httpMethodName();
564 String url = getResourceURL(knownResourceId);
565 String mediaType = MediaType.APPLICATION_XML;
566 final String entity = WRONG_XML_SCHEMA_DATA;
567 int statusCode = submitRequest(method, url, mediaType, entity);
569 // Check the status code of the response: does it match
570 // the expected response(s)?
571 if(logger.isDebugEnabled()){
572 logger.debug(testName + ": url=" + url +
573 " status=" + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
582 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
585 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
586 dependsOnMethods = {"update", "testSubmitRequest"})
587 public void updateNonExistent(String testName) throws Exception {
589 if (logger.isDebugEnabled()) {
590 logger.debug(testBanner(testName, CLASS_NAME));
593 setupUpdateNonExistent();
595 // Submit the request to the service and store the response.
596 // Note: The ID used in this 'create' call may be arbitrary.
597 // The only relevant ID may be the one used in update(), below.
598 MovementClient client = new MovementClient();
599 MultipartOutput multipart = createMovementInstance(NON_EXISTENT_ID);
600 ClientResponse<MultipartInput> res =
601 client.update(NON_EXISTENT_ID, multipart);
602 int statusCode = res.getStatus();
604 // Check the status code of the response: does it match
605 // the expected response(s)?
606 if(logger.isDebugEnabled()){
607 logger.debug(testName + ": status = " + statusCode);
609 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
610 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
611 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614 // ---------------------------------------------------------------
615 // CRUD tests : DELETE tests
616 // ---------------------------------------------------------------
619 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
622 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
623 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
624 public void delete(String testName) throws Exception {
626 if (logger.isDebugEnabled()) {
627 logger.debug(testBanner(testName, CLASS_NAME));
632 // Submit the request to the service and store the response.
633 MovementClient client = new MovementClient();
634 ClientResponse<Response> res = client.delete(knownResourceId);
635 int statusCode = res.getStatus();
637 // Check the status code of the response: does it match
638 // the expected response(s)?
639 if(logger.isDebugEnabled()){
640 logger.debug(testName + ": status = " + statusCode);
642 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
649 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
652 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
653 dependsOnMethods = {"delete"})
654 public void deleteNonExistent(String testName) throws Exception {
656 if (logger.isDebugEnabled()) {
657 logger.debug(testBanner(testName, CLASS_NAME));
660 setupDeleteNonExistent();
662 // Submit the request to the service and store the response.
663 MovementClient client = new MovementClient();
664 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
665 int statusCode = res.getStatus();
667 // Check the status code of the response: does it match
668 // the expected response(s)?
669 if(logger.isDebugEnabled()){
670 logger.debug(testName + ": status = " + statusCode);
672 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
673 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
674 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 // ---------------------------------------------------------------
678 // Utility tests : tests of code used in tests above
679 // ---------------------------------------------------------------
681 * Tests the code for manually submitting data that is used by several
682 * of the methods above.
684 @Test(dependsOnMethods = {"create", "read"})
685 public void testSubmitRequest() {
687 // Expected status code: 200 OK
688 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
690 // Submit the request to the service and store the response.
691 String method = ServiceRequestType.READ.httpMethodName();
692 String url = getResourceURL(knownResourceId);
693 int statusCode = submitRequest(method, url);
695 // Check the status code of the response: does it match
696 // the expected response(s)?
697 if(logger.isDebugEnabled()){
698 logger.debug("testSubmitRequest: url=" + url +
699 " status=" + statusCode);
701 Assert.assertEquals(statusCode, EXPECTED_STATUS);
705 // ---------------------------------------------------------------
706 // Utility methods used by tests above
707 // ---------------------------------------------------------------
709 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
712 public String getServicePathComponent() {
713 return SERVICE_PATH_COMPONENT;
717 * Creates the movement instance.
719 * @param identifier the identifier
720 * @return the multipart output
722 private MultipartOutput createMovementInstance(String identifier) {
723 return createInstance("movementReferenceNumber-" + identifier);
727 * Creates an instance of a Movement record for testing.
729 * @param movementReferenceNumber A movement reference number.
730 * @return Multipart output suitable for use as a payload
731 * in a create or update request.
733 private MultipartOutput createInstance(String movementReferenceNumber) {
734 MovementsCommon movement = new MovementsCommon();
735 // FIXME: Values of currentLocation, normalLocation,
736 // and movementContact should be refNames.
737 movement.setCurrentLocation("currentLocation value");
738 movement.setCurrentLocationFitness("currentLocationFitness value");
739 movement.setCurrentLocationNote("currentLocationNote value");
740 movement.setLocationDate(timestampUTC());
741 movement.setNormalLocation("normalLocation value");
742 movement.setMovementContact("movementContact value");
743 MovementMethodsList movementMethodsList = new MovementMethodsList();
744 List<String> methods = movementMethodsList.getMovementMethod();
745 // @TODO Use properly formatted refNames for representative movement
746 // methods in this example record. The values below are placeholders.
747 String identifier = createIdentifier();
748 methods.add("First Movement Method-" + identifier);
749 methods.add("Second Movement Method-" + identifier);
750 movement.setMovementMethods(movementMethodsList);
751 movement.setMovementNote("movementNote value");
752 movement.setMovementReferenceNumber(movementReferenceNumber);
753 movement.setPlannedRemovalDate("plannedRemovalDate value");
754 movement.setRemovalDate("removalDate value");
755 movement.setReasonForMove("reasonForMove value");
756 MultipartOutput multipart = new MultipartOutput();
757 OutputPart commonPart =
758 multipart.addPart(movement, MediaType.APPLICATION_XML_TYPE);
759 commonPart.getHeaders().add("label", new MovementClient().getCommonPartName());
761 if(logger.isDebugEnabled()){
762 logger.debug("to be created, movement common");
763 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
769 // FIXME Should be moved to a common class, as these are general utilities.
770 // FIXME Should be refactored to become a convenience variant of a
771 // general method to return a current datestamp or timestamp in any
772 // provided time zone.
775 * Returns an ISO 8601 formatted timestamp of the
776 * current time instance in the UTC time zone.
778 public String datestampUTC() {
779 final String ISO_8601_DATE_FORMAT_PATTERN = "yyyy-MM-dd";
780 final DateFormat ISO_8601_DATE_FORMAT =
781 new SimpleDateFormat(ISO_8601_DATE_FORMAT_PATTERN);
783 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
784 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
786 Date timestamp = new Date();
787 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_DATE_FORMAT);
791 * Returns an ISO 8601 formatted timestamp of the
792 * current time instance in the UTC time zone.
794 public String timestampUTC() {
795 final String ISO_8601_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
796 final DateFormat ISO_8601_FORMAT =
797 new SimpleDateFormat(ISO_8601_FORMAT_PATTERN);
799 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
800 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
802 Date timestamp = new Date();
803 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_FORMAT);
807 * Formats a provided date using a provided date formatter,
808 * in the default system time zone.
810 * @param date A date to format.
811 * @param df A date formatter to apply.
812 * @return A formatted date string.
814 public String formatDate(Date date, DateFormat df) {
815 return formatDate(date, TimeZone.getDefault(), df);
818 // FIXME Add error handling.
821 * Formats a provided date using a provided date formatter,
822 * in a provided time zone.
824 * @param date A date to format.
825 * @param tz The time zone qualifier for the date to format.
826 * @param df A date formatter to apply.
828 * @return A formatted date string.
830 public String formatDate(Date date, TimeZone tz, DateFormat df) {
832 return df.format(date);