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;
73 private final static String TIMESTAMP_UTC = GregorianCalendarDateTimeUtils.timestampUTC();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79 protected CollectionSpaceClient getClientInstance() {
80 return new MovementClient();
84 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
87 protected AbstractCommonList getAbstractCommonList(
88 ClientResponse<AbstractCommonList> response) {
89 return response.getEntity(MovementsCommonList.class);
92 // ---------------------------------------------------------------
93 // CRUD tests : CREATE tests
94 // ---------------------------------------------------------------
97 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
101 public void create(String testName) throws Exception {
103 if (logger.isDebugEnabled()) {
104 logger.debug(testBanner(testName, CLASS_NAME));
106 // Perform setup, such as initializing the type of service request
107 // (e.g. CREATE, DELETE), its valid and expected status codes, and
108 // its associated HTTP method name (e.g. POST, DELETE).
111 // Submit the request to the service and store the response.
112 MovementClient client = new MovementClient();
113 String identifier = createIdentifier();
114 MultipartOutput multipart = createMovementInstance(identifier);
115 ClientResponse<Response> res = client.create(multipart);
117 int statusCode = res.getStatus();
119 // Check the status code of the response: does it match
120 // the expected response(s)?
123 // Does it fall within the set of valid status codes?
124 // Does it exactly match the expected status code?
125 if(logger.isDebugEnabled()){
126 logger.debug(testName + ": status = " + statusCode);
128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
130 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
132 // Store the ID returned from the first resource created
133 // for additional tests below.
134 if (knownResourceId == null){
135 knownResourceId = extractId(res);
136 if (logger.isDebugEnabled()) {
137 logger.debug(testName + ": knownResourceId=" + knownResourceId);
141 // Store the IDs from every resource created by tests,
142 // so they can be deleted after tests have been run.
143 allResourceIdsCreated.add(extractId(res));
147 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
150 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
151 dependsOnMethods = {"create"})
152 public void createList(String testName) throws Exception {
153 for(int i = 0; i < 3; i++){
159 // Placeholders until the three tests below can be uncommented.
160 // See Issue CSPACE-401.
162 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
165 public void createWithEmptyEntityBody(String testName) throws Exception {
166 //Should this really be empty?
170 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
173 public void createWithMalformedXml(String testName) throws Exception {
174 //Should this really be empty?
178 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
181 public void createWithWrongXmlSchema(String testName) throws Exception {
182 //Should this really be empty?
187 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
188 dependsOnMethods = {"create", "testSubmitRequest"})
189 public void createWithEmptyEntityBody(String testName) throws Exception {
191 if (logger.isDebugEnabled()) {
192 logger.debug(testBanner(testName, CLASS_NAME));
195 setupCreateWithEmptyEntityBody();
197 // Submit the request to the service and store the response.
198 String method = REQUEST_TYPE.httpMethodName();
199 String url = getServiceRootURL();
200 String mediaType = MediaType.APPLICATION_XML;
201 final String entity = "";
202 int statusCode = submitRequest(method, url, mediaType, entity);
204 // Check the status code of the response: does it match
205 // the expected response(s)?
206 if(logger.isDebugEnabled()){
207 logger.debug("createWithEmptyEntityBody url=" + url +
208 " status=" + statusCode);
210 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
211 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
212 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
216 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
217 dependsOnMethods = {"create", "testSubmitRequest"})
218 public void createWithMalformedXml(String testName) throws Exception {
220 if (logger.isDebugEnabled()) {
221 logger.debug(testBanner(testName, CLASS_NAME));
224 setupCreateWithMalformedXml();
226 // Submit the request to the service and store the response.
227 String method = REQUEST_TYPE.httpMethodName();
228 String url = getServiceRootURL();
229 String mediaType = MediaType.APPLICATION_XML;
230 final String entity = MALFORMED_XML_DATA; // Constant from base class.
231 int statusCode = submitRequest(method, url, mediaType, entity);
233 // Check the status code of the response: does it match
234 // the expected response(s)?
235 if(logger.isDebugEnabled()){
236 logger.debug(testName + ": url=" + url +
237 " status=" + statusCode);
239 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
240 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
241 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
245 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
246 dependsOnMethods = {"create", "testSubmitRequest"})
247 public void createWithWrongXmlSchema(String testName) throws Exception {
249 if (logger.isDebugEnabled()) {
250 logger.debug(testBanner(testName, CLASS_NAME));
253 setupCreateWithWrongXmlSchema();
255 // Submit the request to the service and store the response.
256 String method = REQUEST_TYPE.httpMethodName();
257 String url = getServiceRootURL();
258 String mediaType = MediaType.APPLICATION_XML;
259 final String entity = WRONG_XML_SCHEMA_DATA;
260 int statusCode = submitRequest(method, url, mediaType, entity);
262 // Check the status code of the response: does it match
263 // the expected response(s)?
264 if(logger.isDebugEnabled()){
265 logger.debug(testName + ": url=" + url +
266 " status=" + statusCode);
268 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
269 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
270 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
274 // ---------------------------------------------------------------
275 // CRUD tests : READ tests
276 // ---------------------------------------------------------------
279 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
282 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
283 dependsOnMethods = {"create"})
284 public void read(String testName) throws Exception {
286 if (logger.isDebugEnabled()) {
287 logger.debug(testBanner(testName, CLASS_NAME));
292 // Submit the request to the service and store the response.
293 MovementClient client = new MovementClient();
294 ClientResponse<MultipartInput> res = client.read(knownResourceId);
295 int statusCode = res.getStatus();
297 // Check the status code of the response: does it match
298 // the expected response(s)?
299 if(logger.isDebugEnabled()){
300 logger.debug(testName + ": status = " + statusCode);
302 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
303 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
304 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
306 MultipartInput input = (MultipartInput) res.getEntity();
307 MovementsCommon movement = (MovementsCommon) extractPart(input,
308 client.getCommonPartName(), MovementsCommon.class);
309 Assert.assertNotNull(movement);
311 // Check the values of one or more date/time fields
312 if (logger.isDebugEnabled()) {
313 logger.debug("locationDate=" + movement.getLocationDate());
314 logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC);
316 Assert.assertTrue(movement.getLocationDate().equals(TIMESTAMP_UTC));
317 Assert.assertTrue(movement.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
318 Assert.assertTrue(movement.getRemovalDate().equals(TIMESTAMP_UTC));
323 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
326 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
327 dependsOnMethods = {"read"})
328 public void readNonExistent(String testName) throws Exception {
330 if (logger.isDebugEnabled()) {
331 logger.debug(testBanner(testName, CLASS_NAME));
334 setupReadNonExistent();
336 // Submit the request to the service and store the response.
337 MovementClient client = new MovementClient();
338 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
339 int statusCode = res.getStatus();
341 // Check the status code of the response: does it match
342 // the expected response(s)?
343 if(logger.isDebugEnabled()){
344 logger.debug(testName + ": status = " + statusCode);
346 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
347 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
348 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
351 // ---------------------------------------------------------------
352 // CRUD tests : READ_LIST tests
353 // ---------------------------------------------------------------
356 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
359 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
360 dependsOnMethods = {"createList", "read"})
361 public void readList(String testName) throws Exception {
363 if (logger.isDebugEnabled()) {
364 logger.debug(testBanner(testName, CLASS_NAME));
369 // Submit the request to the service and store the response.
370 MovementClient client = new MovementClient();
371 ClientResponse<MovementsCommonList> res = client.readList();
372 MovementsCommonList list = res.getEntity();
373 int statusCode = res.getStatus();
375 // Check the status code of the response: does it match
376 // the expected response(s)?
377 if(logger.isDebugEnabled()){
378 logger.debug(testName + ": status = " + statusCode);
380 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
381 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
382 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
384 // Optionally output additional data about list members for debugging.
385 boolean iterateThroughList = true;
386 if(iterateThroughList && logger.isDebugEnabled()){
387 List<MovementsCommonList.MovementListItem> items =
388 list.getMovementListItem();
390 for(MovementsCommonList.MovementListItem item : items){
391 logger.debug(testName + ": list-item[" + i + "] csid=" +
393 logger.debug(testName + ": list-item[" + i + "] movementReferenceNumber=" +
394 item.getMovementReferenceNumber());
395 logger.debug(testName + ": list-item[" + i + "] locationDate=" +
396 item.getLocationDate());
397 logger.debug(testName + ": list-item[" + i + "] URI=" +
407 // ---------------------------------------------------------------
408 // CRUD tests : UPDATE tests
409 // ---------------------------------------------------------------
412 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
415 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
416 dependsOnMethods = {"read"})
417 public void update(String testName) throws Exception {
419 if (logger.isDebugEnabled()) {
420 logger.debug(testBanner(testName, CLASS_NAME));
425 // Retrieve the contents of a resource to update.
426 MovementClient client = new MovementClient();
427 ClientResponse<MultipartInput> res =
428 client.read(knownResourceId);
429 if(logger.isDebugEnabled()){
430 logger.debug(testName + ": read status = " + res.getStatus());
432 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
434 if(logger.isDebugEnabled()){
435 logger.debug("got object to update with ID: " + knownResourceId);
437 MultipartInput input = (MultipartInput) res.getEntity();
438 MovementsCommon movement = (MovementsCommon) extractPart(input,
439 client.getCommonPartName(), MovementsCommon.class);
440 Assert.assertNotNull(movement);
442 // Update the content of this resource.
443 movement.setMovementReferenceNumber("updated-" + movement.getMovementReferenceNumber());
444 movement.setMovementNote("updated movement note-" + movement.getMovementNote());
445 if(logger.isDebugEnabled()){
446 logger.debug("to be updated object");
447 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
449 // Submit the request to the service and store the response.
450 MultipartOutput output = new MultipartOutput();
451 OutputPart commonPart = output.addPart(movement, MediaType.APPLICATION_XML_TYPE);
452 commonPart.getHeaders().add("label", client.getCommonPartName());
454 res = client.update(knownResourceId, output);
455 int statusCode = res.getStatus();
456 // Check the status code of the response: does it match the expected response(s)?
457 if(logger.isDebugEnabled()){
458 logger.debug(testName + ": status = " + statusCode);
460 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
461 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
462 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
465 input = (MultipartInput) res.getEntity();
466 MovementsCommon updatedMovement =
467 (MovementsCommon) extractPart(input,
468 client.getCommonPartName(), MovementsCommon.class);
469 Assert.assertNotNull(updatedMovement);
471 Assert.assertEquals(updatedMovement.getMovementNote(),
472 movement.getMovementNote(),
473 "Data in updated object did not match submitted data.");
478 // Placeholders until the three tests below can be uncommented.
479 // See Issue CSPACE-401.
481 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
484 public void updateWithEmptyEntityBody(String testName) throws Exception{
485 //Should this really be empty?
489 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
492 public void updateWithMalformedXml(String testName) throws Exception {
493 //Should this really be empty?
497 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
500 public void updateWithWrongXmlSchema(String testName) throws Exception {
501 //Should this really be empty?
506 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
507 dependsOnMethods = {"create", "update", "testSubmitRequest"})
508 public void updateWithEmptyEntityBody(String testName) throws Exception {
510 if (logger.isDebugEnabled()) {
511 logger.debug(testBanner(testName, CLASS_NAME));
514 setupUpdateWithEmptyEntityBody();
516 // Submit the request to the service and store the response.
517 String method = REQUEST_TYPE.httpMethodName();
518 String url = getResourceURL(knownResourceId);
519 String mediaType = MediaType.APPLICATION_XML;
520 final String entity = "";
521 int statusCode = submitRequest(method, url, mediaType, entity);
523 // Check the status code of the response: does it match
524 // the expected response(s)?
525 if(logger.isDebugEnabled()){
526 logger.debug(testName + ": url=" + url +
527 " status=" + statusCode);
529 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
530 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
531 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
535 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
536 dependsOnMethods = {"create", "update", "testSubmitRequest"})
537 public void updateWithMalformedXml(String testName) throws Exception {
539 if (logger.isDebugEnabled()) {
540 logger.debug(testBanner(testName, CLASS_NAME));
543 setupUpdateWithMalformedXml();
545 // Submit the request to the service and store the response.
546 String method = REQUEST_TYPE.httpMethodName();
547 String url = getResourceURL(knownResourceId);
548 String mediaType = MediaType.APPLICATION_XML;
549 final String entity = MALFORMED_XML_DATA;
550 int statusCode = submitRequest(method, url, mediaType, entity);
552 // Check the status code of the response: does it match
553 // the expected response(s)?
554 if(logger.isDebugEnabled()){
555 logger.debug(testName + ": url=" + url +
556 " status=" + statusCode);
558 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
559 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
560 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
564 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
565 dependsOnMethods = {"create", "update", "testSubmitRequest"})
566 public void updateWithWrongXmlSchema(String testName) throws Exception {
568 if (logger.isDebugEnabled()) {
569 logger.debug(testBanner(testName, CLASS_NAME));
572 setupUpdateWithWrongXmlSchema();
574 // Submit the request to the service and store the response.
575 String method = REQUEST_TYPE.httpMethodName();
576 String url = getResourceURL(knownResourceId);
577 String mediaType = MediaType.APPLICATION_XML;
578 final String entity = WRONG_XML_SCHEMA_DATA;
579 int statusCode = submitRequest(method, url, mediaType, entity);
581 // Check the status code of the response: does it match
582 // the expected response(s)?
583 if(logger.isDebugEnabled()){
584 logger.debug(testName + ": url=" + url +
585 " status=" + statusCode);
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
597 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
598 dependsOnMethods = {"update", "testSubmitRequest"})
599 public void updateNonExistent(String testName) throws Exception {
601 if (logger.isDebugEnabled()) {
602 logger.debug(testBanner(testName, CLASS_NAME));
605 setupUpdateNonExistent();
607 // Submit the request to the service and store the response.
608 // Note: The ID used in this 'create' call may be arbitrary.
609 // The only relevant ID may be the one used in update(), below.
610 MovementClient client = new MovementClient();
611 MultipartOutput multipart = createMovementInstance(NON_EXISTENT_ID);
612 ClientResponse<MultipartInput> res =
613 client.update(NON_EXISTENT_ID, multipart);
614 int statusCode = res.getStatus();
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
626 // ---------------------------------------------------------------
627 // CRUD tests : DELETE tests
628 // ---------------------------------------------------------------
631 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
634 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
635 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
636 public void delete(String testName) throws Exception {
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
644 // Submit the request to the service and store the response.
645 MovementClient client = new MovementClient();
646 ClientResponse<Response> res = client.delete(knownResourceId);
647 int statusCode = res.getStatus();
649 // Check the status code of the response: does it match
650 // the expected response(s)?
651 if(logger.isDebugEnabled()){
652 logger.debug(testName + ": status = " + statusCode);
654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
661 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
664 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
665 dependsOnMethods = {"delete"})
666 public void deleteNonExistent(String testName) throws Exception {
668 if (logger.isDebugEnabled()) {
669 logger.debug(testBanner(testName, CLASS_NAME));
672 setupDeleteNonExistent();
674 // Submit the request to the service and store the response.
675 MovementClient client = new MovementClient();
676 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
677 int statusCode = res.getStatus();
679 // Check the status code of the response: does it match
680 // the expected response(s)?
681 if(logger.isDebugEnabled()){
682 logger.debug(testName + ": status = " + statusCode);
684 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
685 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
686 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
689 // ---------------------------------------------------------------
690 // Utility tests : tests of code used in tests above
691 // ---------------------------------------------------------------
693 * Tests the code for manually submitting data that is used by several
694 * of the methods above.
696 @Test(dependsOnMethods = {"create", "read"})
697 public void testSubmitRequest() {
699 // Expected status code: 200 OK
700 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
702 // Submit the request to the service and store the response.
703 String method = ServiceRequestType.READ.httpMethodName();
704 String url = getResourceURL(knownResourceId);
705 int statusCode = submitRequest(method, url);
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if(logger.isDebugEnabled()){
710 logger.debug("testSubmitRequest: url=" + url +
711 " status=" + statusCode);
713 Assert.assertEquals(statusCode, EXPECTED_STATUS);
717 // ---------------------------------------------------------------
718 // Utility methods used by tests above
719 // ---------------------------------------------------------------
721 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
724 public String getServicePathComponent() {
725 return SERVICE_PATH_COMPONENT;
729 * Creates the movement instance.
731 * @param identifier the identifier
732 * @return the multipart output
734 private MultipartOutput createMovementInstance(String identifier) {
735 return createInstance("movementReferenceNumber-" + identifier);
739 * Creates an instance of a Movement record for testing.
741 * @param movementReferenceNumber A movement reference number.
742 * @return Multipart output suitable for use as a payload
743 * in a create or update request.
745 private MultipartOutput createInstance(String movementReferenceNumber) {
746 MovementsCommon movement = new MovementsCommon();
747 // FIXME: Values of currentLocation, normalLocation,
748 // and movementContact should be refNames.
749 movement.setCurrentLocation("currentLocation value");
750 movement.setCurrentLocationFitness("currentLocationFitness value");
751 movement.setCurrentLocationNote("currentLocationNote value");
752 movement.setLocationDate(TIMESTAMP_UTC);
753 movement.setNormalLocation("normalLocation value");
754 movement.setMovementContact("movementContact value");
755 MovementMethodsList movementMethodsList = new MovementMethodsList();
756 List<String> methods = movementMethodsList.getMovementMethod();
757 // @TODO Use properly formatted refNames for representative movement
758 // methods in this example record. The values below are placeholders.
759 String identifier = createIdentifier();
760 methods.add("First Movement Method-" + identifier);
761 methods.add("Second Movement Method-" + identifier);
762 movement.setMovementMethods(movementMethodsList);
763 movement.setMovementNote("movementNote value");
764 movement.setMovementReferenceNumber(movementReferenceNumber);
765 movement.setPlannedRemovalDate(TIMESTAMP_UTC);
766 movement.setRemovalDate(TIMESTAMP_UTC);
767 movement.setReasonForMove("reasonForMove value");
768 MultipartOutput multipart = new MultipartOutput();
769 OutputPart commonPart =
770 multipart.addPart(movement, MediaType.APPLICATION_XML_TYPE);
771 commonPart.getHeaders().add("label", new MovementClient().getCommonPartName());
773 if(logger.isDebugEnabled()){
774 logger.debug("to be created, movement common");
775 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
781 // FIXME Should be moved to a common class, as these are general utilities.
782 // FIXME Should be refactored to become a convenience variant of a
783 // general method to return a current datestamp or timestamp in any
784 // provided time zone.
787 * Returns an ISO 8601 formatted timestamp of the
788 * current time instance in the UTC time zone.
790 public String datestampUTC() {
791 final String ISO_8601_DATE_FORMAT_PATTERN = "yyyy-MM-dd";
792 final DateFormat ISO_8601_DATE_FORMAT =
793 new SimpleDateFormat(ISO_8601_DATE_FORMAT_PATTERN);
795 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
796 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
798 Date timestamp = new Date();
799 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_DATE_FORMAT);
803 * Returns an ISO 8601 formatted timestamp of the
804 * current time instance in the UTC time zone.
806 public String timestampUTC() {
807 final String ISO_8601_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
808 final DateFormat ISO_8601_FORMAT =
809 new SimpleDateFormat(ISO_8601_FORMAT_PATTERN);
811 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
812 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
814 Date timestamp = new Date();
815 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_FORMAT);
819 * Formats a provided date using a provided date formatter,
820 * in the default system time zone.
822 * @param date A date to format.
823 * @param df A date formatter to apply.
824 * @return A formatted date string.
826 public String formatDate(Date date, DateFormat df) {
827 return formatDate(date, TimeZone.getDefault(), df);
830 // FIXME Add error handling.
833 * Formats a provided date using a provided date formatter,
834 * in a provided time zone.
836 * @param date A date to format.
837 * @param tz The time zone qualifier for the date to format.
838 * @param df A date formatter to apply.
840 * @return A formatted date string.
842 public String formatDate(Date date, TimeZone tz, DateFormat df) {
844 return df.format(date);