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.datetime.GregorianCalendarDateTimeUtils;
35 import org.collectionspace.services.client.CollectionSpaceClient;
36 import org.collectionspace.services.client.MovementClient;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.movement.MovementsCommon;
39 import org.collectionspace.services.movement.MovementsCommonList;
40 import org.collectionspace.services.movement.MovementMethodsList;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
46 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
47 import org.testng.Assert;
48 import org.testng.annotations.Test;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
54 * MovementServiceTest, carries out tests against a
55 * deployed and running Movement Service.
57 * $LastChangedRevision$
60 public class MovementServiceTest extends AbstractServiceTestImpl {
63 private final String CLASS_NAME = MovementServiceTest.class.getName();
64 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
66 // Instance variables specific to this test.
67 /** The service path component. */
68 final String SERVICE_PATH_COMPONENT = "movements";
70 /** The known resource id. */
71 private String knownResourceId = null;
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
77 protected CollectionSpaceClient getClientInstance() {
78 return new MovementClient();
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
85 protected AbstractCommonList getAbstractCommonList(
86 ClientResponse<AbstractCommonList> response) {
87 return response.getEntity(MovementsCommonList.class);
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
95 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
98 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
99 public void create(String testName) throws Exception {
101 if (logger.isDebugEnabled()) {
102 logger.debug(testBanner(testName, CLASS_NAME));
104 // Perform setup, such as initializing the type of service request
105 // (e.g. CREATE, DELETE), its valid and expected status codes, and
106 // its associated HTTP method name (e.g. POST, DELETE).
109 // Submit the request to the service and store the response.
110 MovementClient client = new MovementClient();
111 String identifier = createIdentifier();
112 MultipartOutput multipart = createMovementInstance(identifier);
113 ClientResponse<Response> res = client.create(multipart);
115 int statusCode = res.getStatus();
117 // Check the status code of the response: does it match
118 // the expected response(s)?
121 // Does it fall within the set of valid status codes?
122 // Does it exactly match the expected status code?
123 if(logger.isDebugEnabled()){
124 logger.debug(testName + ": status = " + statusCode);
126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
130 // Store the ID returned from the first resource created
131 // for additional tests below.
132 if (knownResourceId == null){
133 knownResourceId = extractId(res);
134 if (logger.isDebugEnabled()) {
135 logger.debug(testName + ": knownResourceId=" + knownResourceId);
139 // Store the IDs from every resource created by tests,
140 // so they can be deleted after tests have been run.
141 allResourceIdsCreated.add(extractId(res));
145 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
148 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
149 dependsOnMethods = {"create"})
150 public void createList(String testName) throws Exception {
151 for(int i = 0; i < 3; i++){
157 // Placeholders until the three tests below can be uncommented.
158 // See Issue CSPACE-401.
160 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
163 public void createWithEmptyEntityBody(String testName) throws Exception {
164 //Should this really be empty?
168 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
171 public void createWithMalformedXml(String testName) throws Exception {
172 //Should this really be empty?
176 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
179 public void createWithWrongXmlSchema(String testName) throws Exception {
180 //Should this really be empty?
185 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
186 dependsOnMethods = {"create", "testSubmitRequest"})
187 public void createWithEmptyEntityBody(String testName) throws Exception {
189 if (logger.isDebugEnabled()) {
190 logger.debug(testBanner(testName, CLASS_NAME));
193 setupCreateWithEmptyEntityBody();
195 // Submit the request to the service and store the response.
196 String method = REQUEST_TYPE.httpMethodName();
197 String url = getServiceRootURL();
198 String mediaType = MediaType.APPLICATION_XML;
199 final String entity = "";
200 int statusCode = submitRequest(method, url, mediaType, entity);
202 // Check the status code of the response: does it match
203 // the expected response(s)?
204 if(logger.isDebugEnabled()){
205 logger.debug("createWithEmptyEntityBody url=" + url +
206 " status=" + statusCode);
208 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
209 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
210 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
214 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
215 dependsOnMethods = {"create", "testSubmitRequest"})
216 public void createWithMalformedXml(String testName) throws Exception {
218 if (logger.isDebugEnabled()) {
219 logger.debug(testBanner(testName, CLASS_NAME));
222 setupCreateWithMalformedXml();
224 // Submit the request to the service and store the response.
225 String method = REQUEST_TYPE.httpMethodName();
226 String url = getServiceRootURL();
227 String mediaType = MediaType.APPLICATION_XML;
228 final String entity = MALFORMED_XML_DATA; // Constant from base class.
229 int statusCode = submitRequest(method, url, mediaType, entity);
231 // Check the status code of the response: does it match
232 // the expected response(s)?
233 if(logger.isDebugEnabled()){
234 logger.debug(testName + ": url=" + url +
235 " status=" + statusCode);
237 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
238 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
239 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
243 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
244 dependsOnMethods = {"create", "testSubmitRequest"})
245 public void createWithWrongXmlSchema(String testName) throws Exception {
247 if (logger.isDebugEnabled()) {
248 logger.debug(testBanner(testName, CLASS_NAME));
251 setupCreateWithWrongXmlSchema();
253 // Submit the request to the service and store the response.
254 String method = REQUEST_TYPE.httpMethodName();
255 String url = getServiceRootURL();
256 String mediaType = MediaType.APPLICATION_XML;
257 final String entity = WRONG_XML_SCHEMA_DATA;
258 int statusCode = submitRequest(method, url, mediaType, entity);
260 // Check the status code of the response: does it match
261 // the expected response(s)?
262 if(logger.isDebugEnabled()){
263 logger.debug(testName + ": url=" + url +
264 " status=" + statusCode);
266 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
267 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
268 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
272 // ---------------------------------------------------------------
273 // CRUD tests : READ tests
274 // ---------------------------------------------------------------
277 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
280 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
281 dependsOnMethods = {"create"})
282 public void read(String testName) throws Exception {
284 if (logger.isDebugEnabled()) {
285 logger.debug(testBanner(testName, CLASS_NAME));
290 // Submit the request to the service and store the response.
291 MovementClient client = new MovementClient();
292 ClientResponse<MultipartInput> res = client.read(knownResourceId);
293 int statusCode = res.getStatus();
295 // Check the status code of the response: does it match
296 // the expected response(s)?
297 if(logger.isDebugEnabled()){
298 logger.debug(testName + ": status = " + statusCode);
300 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
301 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
302 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
304 MultipartInput input = (MultipartInput) res.getEntity();
305 MovementsCommon movement = (MovementsCommon) extractPart(input,
306 client.getCommonPartName(), MovementsCommon.class);
307 Assert.assertNotNull(movement);
312 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
315 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
316 dependsOnMethods = {"read"})
317 public void readNonExistent(String testName) throws Exception {
319 if (logger.isDebugEnabled()) {
320 logger.debug(testBanner(testName, CLASS_NAME));
323 setupReadNonExistent();
325 // Submit the request to the service and store the response.
326 MovementClient client = new MovementClient();
327 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
328 int statusCode = res.getStatus();
330 // Check the status code of the response: does it match
331 // the expected response(s)?
332 if(logger.isDebugEnabled()){
333 logger.debug(testName + ": status = " + statusCode);
335 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
336 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
337 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
340 // ---------------------------------------------------------------
341 // CRUD tests : READ_LIST tests
342 // ---------------------------------------------------------------
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
348 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349 dependsOnMethods = {"createList", "read"})
350 public void readList(String testName) throws Exception {
352 if (logger.isDebugEnabled()) {
353 logger.debug(testBanner(testName, CLASS_NAME));
358 // Submit the request to the service and store the response.
359 MovementClient client = new MovementClient();
360 ClientResponse<MovementsCommonList> res = client.readList();
361 MovementsCommonList list = res.getEntity();
362 int statusCode = res.getStatus();
364 // Check the status code of the response: does it match
365 // the expected response(s)?
366 if(logger.isDebugEnabled()){
367 logger.debug(testName + ": status = " + statusCode);
369 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
370 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
371 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
373 // Optionally output additional data about list members for debugging.
374 boolean iterateThroughList = true;
375 if(iterateThroughList && logger.isDebugEnabled()){
376 List<MovementsCommonList.MovementListItem> items =
377 list.getMovementListItem();
379 for(MovementsCommonList.MovementListItem item : items){
380 logger.debug(testName + ": list-item[" + i + "] csid=" +
382 logger.debug(testName + ": list-item[" + i + "] movementReferenceNumber=" +
383 item.getMovementReferenceNumber());
384 logger.debug(testName + ": list-item[" + i + "] locationDate=" +
385 item.getLocationDate());
386 logger.debug(testName + ": list-item[" + i + "] URI=" +
396 // ---------------------------------------------------------------
397 // CRUD tests : UPDATE tests
398 // ---------------------------------------------------------------
401 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
404 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
405 dependsOnMethods = {"read"})
406 public void update(String testName) throws Exception {
408 if (logger.isDebugEnabled()) {
409 logger.debug(testBanner(testName, CLASS_NAME));
414 // Retrieve the contents of a resource to update.
415 MovementClient client = new MovementClient();
416 ClientResponse<MultipartInput> res =
417 client.read(knownResourceId);
418 if(logger.isDebugEnabled()){
419 logger.debug(testName + ": read status = " + res.getStatus());
421 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
423 if(logger.isDebugEnabled()){
424 logger.debug("got object to update with ID: " + knownResourceId);
426 MultipartInput input = (MultipartInput) res.getEntity();
427 MovementsCommon movement = (MovementsCommon) extractPart(input,
428 client.getCommonPartName(), MovementsCommon.class);
429 Assert.assertNotNull(movement);
431 // Update the content of this resource.
432 movement.setMovementReferenceNumber("updated-" + movement.getMovementReferenceNumber());
433 movement.setMovementNote("updated movement note-" + movement.getMovementNote());
434 if(logger.isDebugEnabled()){
435 logger.debug("to be updated object");
436 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
438 // Submit the request to the service and store the response.
439 MultipartOutput output = new MultipartOutput();
440 OutputPart commonPart = output.addPart(movement, MediaType.APPLICATION_XML_TYPE);
441 commonPart.getHeaders().add("label", client.getCommonPartName());
443 res = client.update(knownResourceId, output);
444 int statusCode = res.getStatus();
445 // Check the status code of the response: does it match the expected response(s)?
446 if(logger.isDebugEnabled()){
447 logger.debug(testName + ": status = " + statusCode);
449 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
450 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
451 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
454 input = (MultipartInput) res.getEntity();
455 MovementsCommon updatedMovement =
456 (MovementsCommon) extractPart(input,
457 client.getCommonPartName(), MovementsCommon.class);
458 Assert.assertNotNull(updatedMovement);
460 Assert.assertEquals(updatedMovement.getMovementNote(),
461 movement.getMovementNote(),
462 "Data in updated object did not match submitted data.");
467 // Placeholders until the three tests below can be uncommented.
468 // See Issue CSPACE-401.
470 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
473 public void updateWithEmptyEntityBody(String testName) throws Exception{
474 //Should this really be empty?
478 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
481 public void updateWithMalformedXml(String testName) throws Exception {
482 //Should this really be empty?
486 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
489 public void updateWithWrongXmlSchema(String testName) throws Exception {
490 //Should this really be empty?
495 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
496 dependsOnMethods = {"create", "update", "testSubmitRequest"})
497 public void updateWithEmptyEntityBody(String testName) throws Exception {
499 if (logger.isDebugEnabled()) {
500 logger.debug(testBanner(testName, CLASS_NAME));
503 setupUpdateWithEmptyEntityBody();
505 // Submit the request to the service and store the response.
506 String method = REQUEST_TYPE.httpMethodName();
507 String url = getResourceURL(knownResourceId);
508 String mediaType = MediaType.APPLICATION_XML;
509 final String entity = "";
510 int statusCode = submitRequest(method, url, mediaType, entity);
512 // Check the status code of the response: does it match
513 // the expected response(s)?
514 if(logger.isDebugEnabled()){
515 logger.debug(testName + ": url=" + url +
516 " status=" + statusCode);
518 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
519 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
520 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
524 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
525 dependsOnMethods = {"create", "update", "testSubmitRequest"})
526 public void updateWithMalformedXml(String testName) throws Exception {
528 if (logger.isDebugEnabled()) {
529 logger.debug(testBanner(testName, CLASS_NAME));
532 setupUpdateWithMalformedXml();
534 // Submit the request to the service and store the response.
535 String method = REQUEST_TYPE.httpMethodName();
536 String url = getResourceURL(knownResourceId);
537 String mediaType = MediaType.APPLICATION_XML;
538 final String entity = MALFORMED_XML_DATA;
539 int statusCode = submitRequest(method, url, mediaType, entity);
541 // Check the status code of the response: does it match
542 // the expected response(s)?
543 if(logger.isDebugEnabled()){
544 logger.debug(testName + ": url=" + url +
545 " status=" + statusCode);
547 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
548 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
549 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
553 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
554 dependsOnMethods = {"create", "update", "testSubmitRequest"})
555 public void updateWithWrongXmlSchema(String testName) throws Exception {
557 if (logger.isDebugEnabled()) {
558 logger.debug(testBanner(testName, CLASS_NAME));
561 setupUpdateWithWrongXmlSchema();
563 // Submit the request to the service and store the response.
564 String method = REQUEST_TYPE.httpMethodName();
565 String url = getResourceURL(knownResourceId);
566 String mediaType = MediaType.APPLICATION_XML;
567 final String entity = WRONG_XML_SCHEMA_DATA;
568 int statusCode = submitRequest(method, url, mediaType, entity);
570 // Check the status code of the response: does it match
571 // the expected response(s)?
572 if(logger.isDebugEnabled()){
573 logger.debug(testName + ": url=" + url +
574 " status=" + statusCode);
576 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
577 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
578 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
583 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
586 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
587 dependsOnMethods = {"update", "testSubmitRequest"})
588 public void updateNonExistent(String testName) throws Exception {
590 if (logger.isDebugEnabled()) {
591 logger.debug(testBanner(testName, CLASS_NAME));
594 setupUpdateNonExistent();
596 // Submit the request to the service and store the response.
597 // Note: The ID used in this 'create' call may be arbitrary.
598 // The only relevant ID may be the one used in update(), below.
599 MovementClient client = new MovementClient();
600 MultipartOutput multipart = createMovementInstance(NON_EXISTENT_ID);
601 ClientResponse<MultipartInput> res =
602 client.update(NON_EXISTENT_ID, multipart);
603 int statusCode = res.getStatus();
605 // Check the status code of the response: does it match
606 // the expected response(s)?
607 if(logger.isDebugEnabled()){
608 logger.debug(testName + ": status = " + statusCode);
610 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
615 // ---------------------------------------------------------------
616 // CRUD tests : DELETE tests
617 // ---------------------------------------------------------------
620 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
624 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
625 public void delete(String testName) throws Exception {
627 if (logger.isDebugEnabled()) {
628 logger.debug(testBanner(testName, CLASS_NAME));
633 // Submit the request to the service and store the response.
634 MovementClient client = new MovementClient();
635 ClientResponse<Response> res = client.delete(knownResourceId);
636 int statusCode = res.getStatus();
638 // Check the status code of the response: does it match
639 // the expected response(s)?
640 if(logger.isDebugEnabled()){
641 logger.debug(testName + ": status = " + statusCode);
643 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
644 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
645 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
653 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
654 dependsOnMethods = {"delete"})
655 public void deleteNonExistent(String testName) throws Exception {
657 if (logger.isDebugEnabled()) {
658 logger.debug(testBanner(testName, CLASS_NAME));
661 setupDeleteNonExistent();
663 // Submit the request to the service and store the response.
664 MovementClient client = new MovementClient();
665 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
666 int statusCode = res.getStatus();
668 // Check the status code of the response: does it match
669 // the expected response(s)?
670 if(logger.isDebugEnabled()){
671 logger.debug(testName + ": status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 // ---------------------------------------------------------------
679 // Utility tests : tests of code used in tests above
680 // ---------------------------------------------------------------
682 * Tests the code for manually submitting data that is used by several
683 * of the methods above.
685 @Test(dependsOnMethods = {"create", "read"})
686 public void testSubmitRequest() {
688 // Expected status code: 200 OK
689 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
691 // Submit the request to the service and store the response.
692 String method = ServiceRequestType.READ.httpMethodName();
693 String url = getResourceURL(knownResourceId);
694 int statusCode = submitRequest(method, url);
696 // Check the status code of the response: does it match
697 // the expected response(s)?
698 if(logger.isDebugEnabled()){
699 logger.debug("testSubmitRequest: url=" + url +
700 " status=" + statusCode);
702 Assert.assertEquals(statusCode, EXPECTED_STATUS);
706 // ---------------------------------------------------------------
707 // Utility methods used by tests above
708 // ---------------------------------------------------------------
710 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
713 public String getServicePathComponent() {
714 return SERVICE_PATH_COMPONENT;
718 * Creates the movement instance.
720 * @param identifier the identifier
721 * @return the multipart output
723 private MultipartOutput createMovementInstance(String identifier) {
724 return createInstance("movementReferenceNumber-" + identifier);
728 * Creates an instance of a Movement record for testing.
730 * @param movementReferenceNumber A movement reference number.
731 * @return Multipart output suitable for use as a payload
732 * in a create or update request.
734 private MultipartOutput createInstance(String movementReferenceNumber) {
735 MovementsCommon movement = new MovementsCommon();
736 String timestampUTC = GregorianCalendarDateTimeUtils.timestampUTC();
737 // FIXME: Values of currentLocation, normalLocation,
738 // and movementContact should be refNames.
739 movement.setCurrentLocation("currentLocation value");
740 movement.setCurrentLocationFitness("currentLocationFitness value");
741 movement.setCurrentLocationNote("currentLocationNote value");
742 movement.setLocationDate(timestampUTC);
743 movement.setNormalLocation("normalLocation value");
744 movement.setMovementContact("movementContact value");
745 MovementMethodsList movementMethodsList = new MovementMethodsList();
746 List<String> methods = movementMethodsList.getMovementMethod();
747 // @TODO Use properly formatted refNames for representative movement
748 // methods in this example record. The values below are placeholders.
749 String identifier = createIdentifier();
750 methods.add("First Movement Method-" + identifier);
751 methods.add("Second Movement Method-" + identifier);
752 movement.setMovementMethods(movementMethodsList);
753 movement.setMovementNote("movementNote value");
754 movement.setMovementReferenceNumber(movementReferenceNumber);
755 movement.setPlannedRemovalDate(timestampUTC);
756 movement.setRemovalDate(timestampUTC);
757 movement.setReasonForMove("reasonForMove value");
758 MultipartOutput multipart = new MultipartOutput();
759 OutputPart commonPart =
760 multipart.addPart(movement, MediaType.APPLICATION_XML_TYPE);
761 commonPart.getHeaders().add("label", new MovementClient().getCommonPartName());
763 if(logger.isDebugEnabled()){
764 logger.debug("to be created, movement common");
765 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
771 // FIXME Should be moved to a common class, as these are general utilities.
772 // FIXME Should be refactored to become a convenience variant of a
773 // general method to return a current datestamp or timestamp in any
774 // provided time zone.
777 * Returns an ISO 8601 formatted timestamp of the
778 * current time instance in the UTC time zone.
780 public String datestampUTC() {
781 final String ISO_8601_DATE_FORMAT_PATTERN = "yyyy-MM-dd";
782 final DateFormat ISO_8601_DATE_FORMAT =
783 new SimpleDateFormat(ISO_8601_DATE_FORMAT_PATTERN);
785 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
786 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
788 Date timestamp = new Date();
789 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_DATE_FORMAT);
793 * Returns an ISO 8601 formatted timestamp of the
794 * current time instance in the UTC time zone.
796 public String timestampUTC() {
797 final String ISO_8601_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
798 final DateFormat ISO_8601_FORMAT =
799 new SimpleDateFormat(ISO_8601_FORMAT_PATTERN);
801 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
802 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
804 Date timestamp = new Date();
805 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_FORMAT);
809 * Formats a provided date using a provided date formatter,
810 * in the default system time zone.
812 * @param date A date to format.
813 * @param df A date formatter to apply.
814 * @return A formatted date string.
816 public String formatDate(Date date, DateFormat df) {
817 return formatDate(date, TimeZone.getDefault(), df);
820 // FIXME Add error handling.
823 * Formats a provided date using a provided date formatter,
824 * in a provided time zone.
826 * @param date A date to format.
827 * @param tz The time zone qualifier for the date to format.
828 * @param df A date formatter to apply.
830 * @return A formatted date string.
832 public String formatDate(Date date, TimeZone tz, DateFormat df) {
834 return df.format(date);