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.assertNull(movement.getRemovalDate());
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 movement.setNormalLocation(""); // Test deletion of existing string value
447 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
448 movement.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value
449 movement.setRemovalDate(currentTimestamp);
451 if(logger.isDebugEnabled()){
452 logger.debug("to be updated object");
453 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
456 // Submit the request to the service and store the response.
457 MultipartOutput output = new MultipartOutput();
458 OutputPart commonPart = output.addPart(movement, MediaType.APPLICATION_XML_TYPE);
459 commonPart.getHeaders().add("label", client.getCommonPartName());
461 res = client.update(knownResourceId, output);
462 int statusCode = res.getStatus();
463 // Check the status code of the response: does it match the expected response(s)?
464 if(logger.isDebugEnabled()){
465 logger.debug(testName + ": status = " + statusCode);
467 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
468 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
469 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
471 input = (MultipartInput) res.getEntity();
472 MovementsCommon updatedMovement =
473 (MovementsCommon) extractPart(input,
474 client.getCommonPartName(), MovementsCommon.class);
475 Assert.assertNotNull(updatedMovement);
477 if(logger.isDebugEnabled()){
478 logger.debug("updated object");
479 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
482 Assert.assertEquals(updatedMovement.getNormalLocation(),
483 movement.getNormalLocation(), "Data in updated object did not match submitted data.");
484 if(logger.isDebugEnabled()){
485 logger.debug("Normal location after update=|" + updatedMovement.getNormalLocation() + "|");
488 Assert.assertEquals(updatedMovement.getMovementReferenceNumber(),
489 movement.getMovementReferenceNumber(),
490 "Data in updated object did not match submitted data.");
491 Assert.assertEquals(updatedMovement.getMovementNote(),
492 movement.getMovementNote(),
493 "Data in updated object did not match submitted data.");
494 Assert.assertNull(updatedMovement.getPlannedRemovalDate());
495 Assert.assertEquals(updatedMovement.getRemovalDate(),
496 movement.getRemovalDate(),
497 "Data in updated object did not match submitted data.");
502 // Placeholders until the three tests below can be uncommented.
503 // See Issue CSPACE-401.
505 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
508 public void updateWithEmptyEntityBody(String testName) throws Exception{
509 //Should this really be empty?
513 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
516 public void updateWithMalformedXml(String testName) throws Exception {
517 //Should this really be empty?
521 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
524 public void updateWithWrongXmlSchema(String testName) throws Exception {
525 //Should this really be empty?
530 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
531 dependsOnMethods = {"create", "update", "testSubmitRequest"})
532 public void updateWithEmptyEntityBody(String testName) throws Exception {
534 if (logger.isDebugEnabled()) {
535 logger.debug(testBanner(testName, CLASS_NAME));
538 setupUpdateWithEmptyEntityBody();
540 // Submit the request to the service and store the response.
541 String method = REQUEST_TYPE.httpMethodName();
542 String url = getResourceURL(knownResourceId);
543 String mediaType = MediaType.APPLICATION_XML;
544 final String entity = "";
545 int statusCode = submitRequest(method, url, mediaType, entity);
547 // Check the status code of the response: does it match
548 // the expected response(s)?
549 if(logger.isDebugEnabled()){
550 logger.debug(testName + ": url=" + url +
551 " status=" + statusCode);
553 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
559 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
560 dependsOnMethods = {"create", "update", "testSubmitRequest"})
561 public void updateWithMalformedXml(String testName) throws Exception {
563 if (logger.isDebugEnabled()) {
564 logger.debug(testBanner(testName, CLASS_NAME));
567 setupUpdateWithMalformedXml();
569 // Submit the request to the service and store the response.
570 String method = REQUEST_TYPE.httpMethodName();
571 String url = getResourceURL(knownResourceId);
572 String mediaType = MediaType.APPLICATION_XML;
573 final String entity = MALFORMED_XML_DATA;
574 int statusCode = submitRequest(method, url, mediaType, entity);
576 // Check the status code of the response: does it match
577 // the expected response(s)?
578 if(logger.isDebugEnabled()){
579 logger.debug(testName + ": url=" + url +
580 " status=" + statusCode);
582 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
589 dependsOnMethods = {"create", "update", "testSubmitRequest"})
590 public void updateWithWrongXmlSchema(String testName) throws Exception {
592 if (logger.isDebugEnabled()) {
593 logger.debug(testBanner(testName, CLASS_NAME));
596 setupUpdateWithWrongXmlSchema();
598 // Submit the request to the service and store the response.
599 String method = REQUEST_TYPE.httpMethodName();
600 String url = getResourceURL(knownResourceId);
601 String mediaType = MediaType.APPLICATION_XML;
602 final String entity = WRONG_XML_SCHEMA_DATA;
603 int statusCode = submitRequest(method, url, mediaType, entity);
605 // Check the status code of the response: does it match
606 // the expected response(s)?
607 if(logger.isDebugEnabled()){
608 logger.debug(testName + ": url=" + url +
609 " status=" + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
618 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
621 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
622 dependsOnMethods = {"update", "testSubmitRequest"})
623 public void updateNonExistent(String testName) throws Exception {
625 if (logger.isDebugEnabled()) {
626 logger.debug(testBanner(testName, CLASS_NAME));
629 setupUpdateNonExistent();
631 // Submit the request to the service and store the response.
632 // Note: The ID used in this 'create' call may be arbitrary.
633 // The only relevant ID may be the one used in update(), below.
634 MovementClient client = new MovementClient();
635 MultipartOutput multipart = createMovementInstance(NON_EXISTENT_ID);
636 ClientResponse<MultipartInput> res =
637 client.update(NON_EXISTENT_ID, multipart);
638 int statusCode = res.getStatus();
640 // Check the status code of the response: does it match
641 // the expected response(s)?
642 if(logger.isDebugEnabled()){
643 logger.debug(testName + ": status = " + statusCode);
645 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 // ---------------------------------------------------------------
651 // CRUD tests : DELETE tests
652 // ---------------------------------------------------------------
655 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
659 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
660 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
661 public void delete(String testName) throws Exception {
663 if (logger.isDebugEnabled()) {
664 logger.debug(testBanner(testName, CLASS_NAME));
670 // Submit the request to the service and store the response.
671 MovementClient client = new MovementClient();
672 ClientResponse<Response> res = client.delete(knownResourceId);
673 int statusCode = res.getStatus();
675 // Check the status code of the response: does it match
676 // the expected response(s)?
677 if(logger.isDebugEnabled()){
678 logger.debug(testName + ": status = " + statusCode);
680 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
690 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
693 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
694 dependsOnMethods = {"delete"})
695 public void deleteNonExistent(String testName) throws Exception {
697 if (logger.isDebugEnabled()) {
698 logger.debug(testBanner(testName, CLASS_NAME));
701 setupDeleteNonExistent();
703 // Submit the request to the service and store the response.
704 MovementClient client = new MovementClient();
705 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
706 int statusCode = res.getStatus();
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if(logger.isDebugEnabled()){
711 logger.debug(testName + ": status = " + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
718 // ---------------------------------------------------------------
719 // Utility tests : tests of code used in tests above
720 // ---------------------------------------------------------------
722 * Tests the code for manually submitting data that is used by several
723 * of the methods above.
725 @Test(dependsOnMethods = {"create", "read"})
726 public void testSubmitRequest() {
728 // Expected status code: 200 OK
729 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
731 // Submit the request to the service and store the response.
732 String method = ServiceRequestType.READ.httpMethodName();
733 String url = getResourceURL(knownResourceId);
734 int statusCode = submitRequest(method, url);
736 // Check the status code of the response: does it match
737 // the expected response(s)?
738 if(logger.isDebugEnabled()){
739 logger.debug("testSubmitRequest: url=" + url +
740 " status=" + statusCode);
742 Assert.assertEquals(statusCode, EXPECTED_STATUS);
746 // ---------------------------------------------------------------
747 // Utility methods used by tests above
748 // ---------------------------------------------------------------
750 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
753 public String getServicePathComponent() {
754 return SERVICE_PATH_COMPONENT;
758 * Creates the movement instance.
760 * @param identifier the identifier
761 * @return the multipart output
763 private MultipartOutput createMovementInstance(String identifier) {
764 return createInstance("movementReferenceNumber-" + identifier);
768 * Creates an instance of a Movement record for testing.
770 * @param movementReferenceNumber A movement reference number.
771 * @return Multipart output suitable for use as a payload
772 * in a create or update request.
774 private MultipartOutput createInstance(String movementReferenceNumber) {
775 MovementsCommon movement = new MovementsCommon();
776 // FIXME: Values of currentLocation, normalLocation,
777 // and movementContact should be refNames.
778 movement.setCurrentLocation("currentLocation value");
779 movement.setCurrentLocationFitness("currentLocationFitness value");
780 movement.setCurrentLocationNote("currentLocationNote value");
781 movement.setLocationDate(TIMESTAMP_UTC);
782 movement.setNormalLocation("normalLocation value");
783 movement.setMovementContact("movementContact value");
784 MovementMethodsList movementMethodsList = new MovementMethodsList();
785 List<String> methods = movementMethodsList.getMovementMethod();
786 // @TODO Use properly formatted refNames for representative movement
787 // methods in this example record. The values below are placeholders.
788 String identifier = createIdentifier();
789 methods.add("First Movement Method-" + identifier);
790 methods.add("Second Movement Method-" + identifier);
791 movement.setMovementMethods(movementMethodsList);
792 movement.setMovementNote("movementNote value");
793 movement.setMovementReferenceNumber(movementReferenceNumber);
794 movement.setPlannedRemovalDate(TIMESTAMP_UTC);
795 movement.setRemovalDate(""); // Test empty date value
796 movement.setReasonForMove("reasonForMove value");
797 MultipartOutput multipart = new MultipartOutput();
798 OutputPart commonPart =
799 multipart.addPart(movement, MediaType.APPLICATION_XML_TYPE);
800 commonPart.getHeaders().add("label", new MovementClient().getCommonPartName());
802 if(logger.isDebugEnabled()){
803 logger.debug("to be created, movement common");
804 logger.debug(objectAsXmlString(movement, MovementsCommon.class));
810 // FIXME Should be moved to a common class, as these are general utilities.
811 // FIXME Should be refactored to become a convenience variant of a
812 // general method to return a current datestamp or timestamp in any
813 // provided time zone.
816 * Returns an ISO 8601 formatted timestamp of the
817 * current time instance in the UTC time zone.
819 public String datestampUTC() {
820 final String ISO_8601_DATE_FORMAT_PATTERN = "yyyy-MM-dd";
821 final DateFormat ISO_8601_DATE_FORMAT =
822 new SimpleDateFormat(ISO_8601_DATE_FORMAT_PATTERN);
824 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
825 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
827 Date timestamp = new Date();
828 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_DATE_FORMAT);
832 * Returns an ISO 8601 formatted timestamp of the
833 * current time instance in the UTC time zone.
835 public String timestampUTC() {
836 final String ISO_8601_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
837 final DateFormat ISO_8601_FORMAT =
838 new SimpleDateFormat(ISO_8601_FORMAT_PATTERN);
840 final String UTC_TIMEZONE_IDENTIFIER = "UTC";
841 final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone(UTC_TIMEZONE_IDENTIFIER);
843 Date timestamp = new Date();
844 return formatDate(timestamp, UTC_TIMEZONE, ISO_8601_FORMAT);
848 * Formats a provided date using a provided date formatter,
849 * in the default system time zone.
851 * @param date A date to format.
852 * @param df A date formatter to apply.
853 * @return A formatted date string.
855 public String formatDate(Date date, DateFormat df) {
856 return formatDate(date, TimeZone.getDefault(), df);
859 // FIXME Add error handling.
862 * Formats a provided date using a provided date formatter,
863 * in a provided time zone.
865 * @param date A date to format.
866 * @param tz The time zone qualifier for the date to format.
867 * @param df A date formatter to apply.
869 * @return A formatted date string.
871 public String formatDate(Date date, TimeZone tz, DateFormat df) {
873 return df.format(date);