2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.text.DateFormat;
26 import java.text.SimpleDateFormat;
27 import java.util.Calendar;
28 import java.util.Date;
29 import java.util.List;
30 import java.util.TimeZone;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response;
34 import org.collectionspace.services.common.AbstractCommonListUtils;
35 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
36 import org.collectionspace.services.client.CollectionSpaceClient;
37 import org.collectionspace.services.client.MovementClient;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.movement.MovementsCommon;
40 import org.collectionspace.services.movement.MovementMethodsList;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.collectionspace.services.client.PayloadInputPart;
45 import org.collectionspace.services.client.PayloadOutputPart;
46 import org.collectionspace.services.client.PoxPayloadIn;
47 import org.collectionspace.services.client.PoxPayloadOut;
48 import org.testng.Assert;
49 import org.testng.annotations.Test;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
55 * MovementServiceTest, carries out tests against a
56 * deployed and running Movement Service.
58 * $LastChangedRevision$
61 public class MovementServiceTest extends AbstractServiceTestImpl {
64 private final String CLASS_NAME = MovementServiceTest.class.getName();
65 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
67 final String SERVICE_NAME = "movements";
68 final String SERVICE_PATH_COMPONENT = "movements";
70 // Instance variables specific to this test.
71 private String knownResourceId = null;
72 private final static String TIMESTAMP_UTC =
73 GregorianCalendarDateTimeUtils.timestampUTC();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79 protected CollectionSpaceClient getClientInstance() {
80 return new MovementClient();
83 // ---------------------------------------------------------------
84 // CRUD tests : CREATE tests
85 // ---------------------------------------------------------------
88 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
91 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
92 public void create(String testName) throws Exception {
94 if (logger.isDebugEnabled()) {
95 logger.debug(testBanner(testName, CLASS_NAME));
97 // Perform setup, such as initializing the type of service request
98 // (e.g. CREATE, DELETE), its valid and expected status codes, and
99 // its associated HTTP method name (e.g. POST, DELETE).
102 // Submit the request to the service and store the response.
103 MovementClient client = new MovementClient();
104 String identifier = createIdentifier();
105 PoxPayloadOut multipart = createMovementInstance(identifier);
106 ClientResponse<Response> res = client.create(multipart);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if(logger.isDebugEnabled()){
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
123 // Store the ID returned from the first resource created
124 // for additional tests below.
125 if (knownResourceId == null){
126 knownResourceId = extractId(res);
127 if (logger.isDebugEnabled()) {
128 logger.debug(testName + ": knownResourceId=" + knownResourceId);
132 // Store the IDs from every resource created by tests,
133 // so they can be deleted after tests have been run.
134 allResourceIdsCreated.add(extractId(res));
138 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
141 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
142 dependsOnMethods = {"create"})
143 public void createList(String testName) throws Exception {
144 for(int i = 0; i < 3; i++){
150 // Placeholders until the three tests below can be uncommented.
151 // See Issue CSPACE-401.
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
156 public void createWithEmptyEntityBody(String testName) throws Exception {
157 //Should this really be empty?
161 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
164 public void createWithMalformedXml(String testName) throws Exception {
165 //Should this really be empty?
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
172 public void createWithWrongXmlSchema(String testName) throws Exception {
173 //Should this really be empty?
178 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
179 dependsOnMethods = {"create", "testSubmitRequest"})
180 public void createWithEmptyEntityBody(String testName) throws Exception {
182 if (logger.isDebugEnabled()) {
183 logger.debug(testBanner(testName, CLASS_NAME));
186 setupCreateWithEmptyEntityBody();
188 // Submit the request to the service and store the response.
189 String method = REQUEST_TYPE.httpMethodName();
190 String url = getServiceRootURL();
191 String mediaType = MediaType.APPLICATION_XML;
192 final String entity = "";
193 int statusCode = submitRequest(method, url, mediaType, entity);
195 // Check the status code of the response: does it match
196 // the expected response(s)?
197 if(logger.isDebugEnabled()){
198 logger.debug("createWithEmptyEntityBody url=" + url +
199 " status=" + statusCode);
201 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
202 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
203 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
207 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
208 dependsOnMethods = {"create", "testSubmitRequest"})
209 public void createWithMalformedXml(String testName) throws Exception {
211 if (logger.isDebugEnabled()) {
212 logger.debug(testBanner(testName, CLASS_NAME));
215 setupCreateWithMalformedXml();
217 // Submit the request to the service and store the response.
218 String method = REQUEST_TYPE.httpMethodName();
219 String url = getServiceRootURL();
220 String mediaType = MediaType.APPLICATION_XML;
221 final String entity = MALFORMED_XML_DATA; // Constant from base class.
222 int statusCode = submitRequest(method, url, mediaType, entity);
224 // Check the status code of the response: does it match
225 // the expected response(s)?
226 if(logger.isDebugEnabled()){
227 logger.debug(testName + ": url=" + url +
228 " status=" + statusCode);
230 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
231 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
232 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
237 dependsOnMethods = {"create", "testSubmitRequest"})
238 public void createWithWrongXmlSchema(String testName) throws Exception {
240 if (logger.isDebugEnabled()) {
241 logger.debug(testBanner(testName, CLASS_NAME));
244 setupCreateWithWrongXmlSchema();
246 // Submit the request to the service and store the response.
247 String method = REQUEST_TYPE.httpMethodName();
248 String url = getServiceRootURL();
249 String mediaType = MediaType.APPLICATION_XML;
250 final String entity = WRONG_XML_SCHEMA_DATA;
251 int statusCode = submitRequest(method, url, mediaType, entity);
253 // Check the status code of the response: does it match
254 // the expected response(s)?
255 if(logger.isDebugEnabled()){
256 logger.debug(testName + ": url=" + url +
257 " status=" + statusCode);
259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265 // ---------------------------------------------------------------
266 // CRUD tests : READ tests
267 // ---------------------------------------------------------------
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
273 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
274 dependsOnMethods = {"create"})
275 public void read(String testName) throws Exception {
277 if (logger.isDebugEnabled()) {
278 logger.debug(testBanner(testName, CLASS_NAME));
283 // Submit the request to the service and store the response.
284 MovementClient client = new MovementClient();
285 ClientResponse<String> res = client.read(knownResourceId);
286 int statusCode = res.getStatus();
288 // Check the status code of the response: does it match
289 // the expected response(s)?
290 if(logger.isDebugEnabled()){
291 logger.debug(testName + ": status = " + statusCode);
293 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
294 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
295 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
297 // Get the common part of the response and verify that it is not null.
298 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
299 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
300 MovementsCommon movementCommon = null;
301 if (payloadInputPart != null) {
302 movementCommon = (MovementsCommon) payloadInputPart.getBody();
304 Assert.assertNotNull(movementCommon);
306 // Check selected fields.
308 // Check the values of one or more date/time fields.
309 if (logger.isDebugEnabled()) {
310 logger.debug("locationDate=" + movementCommon.getLocationDate());
311 logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC);
313 Assert.assertTrue(movementCommon.getLocationDate().equals(TIMESTAMP_UTC));
314 Assert.assertTrue(movementCommon.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
315 Assert.assertNull(movementCommon.getRemovalDate());
317 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
318 if(logger.isDebugEnabled()){
319 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
320 + "UTF-8 data received=" + movementCommon.getMovementNote());
322 Assert.assertEquals(movementCommon.getMovementNote(), getUTF8DataFragment(),
323 "UTF-8 data retrieved '" + movementCommon.getMovementNote()
324 + "' does not match expected data '" + getUTF8DataFragment());
330 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
333 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
334 dependsOnMethods = {"read"})
335 public void readNonExistent(String testName) throws Exception {
337 if (logger.isDebugEnabled()) {
338 logger.debug(testBanner(testName, CLASS_NAME));
341 setupReadNonExistent();
343 // Submit the request to the service and store the response.
344 MovementClient client = new MovementClient();
345 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
346 int statusCode = res.getStatus();
348 // Check the status code of the response: does it match
349 // the expected response(s)?
350 if(logger.isDebugEnabled()){
351 logger.debug(testName + ": status = " + statusCode);
353 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
354 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
355 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
358 // ---------------------------------------------------------------
359 // CRUD tests : READ_LIST tests
360 // ---------------------------------------------------------------
363 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
366 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
367 dependsOnMethods = {"createList", "read"})
368 public void readList(String testName) throws Exception {
370 if (logger.isDebugEnabled()) {
371 logger.debug(testBanner(testName, CLASS_NAME));
376 // Submit the request to the service and store the response.
377 MovementClient client = new MovementClient();
378 ClientResponse<AbstractCommonList> res = client.readList();
379 AbstractCommonList list = res.getEntity();
380 int statusCode = res.getStatus();
382 // Check the status code of the response: does it match
383 // the expected response(s)?
384 if(logger.isDebugEnabled()){
385 logger.debug(testName + ": status = " + statusCode);
387 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
388 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
389 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
391 // Optionally output additional data about list members for debugging.
392 if(logger.isTraceEnabled()){
393 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
399 // ---------------------------------------------------------------
400 // CRUD tests : UPDATE tests
401 // ---------------------------------------------------------------
404 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
407 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
408 dependsOnMethods = {"read"})
409 public void update(String testName) throws Exception {
411 if (logger.isDebugEnabled()) {
412 logger.debug(testBanner(testName, CLASS_NAME));
417 // Retrieve the contents of a resource to update.
418 MovementClient client = new MovementClient();
419 ClientResponse<String> res = client.read(knownResourceId);
420 if(logger.isDebugEnabled()){
421 logger.debug(testName + ": read status = " + res.getStatus());
423 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
424 if(logger.isDebugEnabled()){
425 logger.debug("got object to update with ID: " + knownResourceId);
428 // Extract the common part from the response.
429 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
430 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
431 MovementsCommon movementCommon = null;
432 if (payloadInputPart != null) {
433 movementCommon = (MovementsCommon) payloadInputPart.getBody();
435 Assert.assertNotNull(movementCommon);
437 // Update its content.
438 movementCommon.setMovementReferenceNumber("updated-" + movementCommon.getMovementReferenceNumber());
439 movementCommon.setMovementNote("updated movement note-" + movementCommon.getMovementNote());
440 movementCommon.setNormalLocation(""); // Test deletion of existing string value
442 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
443 movementCommon.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value
444 movementCommon.setRemovalDate(currentTimestamp);
446 if(logger.isDebugEnabled()){
447 logger.debug("to be updated object");
448 logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));
451 // Submit the request to the service and store the response.
452 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
453 PayloadOutputPart commonPart = output.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE);
454 commonPart.setLabel(client.getCommonPartName());
455 res = client.update(knownResourceId, output);
457 // Check the status code of the response: does it match the expected response(s)?
458 int statusCode = res.getStatus();
459 if(logger.isDebugEnabled()){
460 logger.debug(testName + ": status = " + statusCode);
462 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
463 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
464 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466 // Extract the updated common part from the response.
467 input = new PoxPayloadIn(res.getEntity());
468 payloadInputPart = input.getPart(client.getCommonPartName());
469 MovementsCommon updatedMovementCommon = null;
470 if (payloadInputPart != null) {
471 updatedMovementCommon = (MovementsCommon) payloadInputPart.getBody();
473 Assert.assertNotNull(movementCommon);
474 if(logger.isDebugEnabled()){
475 logger.debug("updated object");
476 logger.debug(objectAsXmlString(updatedMovementCommon, MovementsCommon.class));
479 // Check selected fields in the updated common part.
481 // By submitting an empty string in the update payload, the value of this field
482 // in the object created from the response payload will be null.
483 Assert.assertNull(updatedMovementCommon.getNormalLocation(), "Data in updated object did not match submitted data.");
484 if(logger.isDebugEnabled()){
485 logger.debug("Normal location after update=|" + updatedMovementCommon.getNormalLocation() + "|");
488 Assert.assertEquals(updatedMovementCommon.getMovementReferenceNumber(),
489 movementCommon.getMovementReferenceNumber(),
490 "Data in updated object did not match submitted data.");
491 Assert.assertEquals(updatedMovementCommon.getMovementNote(),
492 movementCommon.getMovementNote(),
493 "Data in updated object did not match submitted data.");
494 Assert.assertNull(updatedMovementCommon.getPlannedRemovalDate());
495 Assert.assertEquals(updatedMovementCommon.getRemovalDate(),
496 movementCommon.getRemovalDate(),
497 "Data in updated object did not match submitted data.");
499 if(logger.isDebugEnabled()){
500 logger.debug("UTF-8 data sent=" + movementCommon.getMovementNote() + "\n"
501 + "UTF-8 data received=" + updatedMovementCommon.getMovementNote());
503 Assert.assertTrue(updatedMovementCommon.getMovementNote().contains(getUTF8DataFragment()),
504 "UTF-8 data retrieved '" + updatedMovementCommon.getMovementNote()
505 + "' does not contain expected data '" + getUTF8DataFragment());
506 Assert.assertEquals(updatedMovementCommon.getMovementNote(),
507 movementCommon.getMovementNote(),
508 "Data in updated object did not match submitted data.");
513 // Placeholders until the three tests below can be uncommented.
514 // See Issue CSPACE-401.
516 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
519 public void updateWithEmptyEntityBody(String testName) throws Exception{
520 //Should this really be empty?
524 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
527 public void updateWithMalformedXml(String testName) throws Exception {
528 //Should this really be empty?
532 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
535 public void updateWithWrongXmlSchema(String testName) throws Exception {
536 //Should this really be empty?
541 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
542 dependsOnMethods = {"create", "update", "testSubmitRequest"})
543 public void updateWithEmptyEntityBody(String testName) throws Exception {
545 if (logger.isDebugEnabled()) {
546 logger.debug(testBanner(testName, CLASS_NAME));
549 setupUpdateWithEmptyEntityBody();
551 // Submit the request to the service and store the response.
552 String method = REQUEST_TYPE.httpMethodName();
553 String url = getResourceURL(knownResourceId);
554 String mediaType = MediaType.APPLICATION_XML;
555 final String entity = "";
556 int statusCode = submitRequest(method, url, mediaType, entity);
558 // Check the status code of the response: does it match
559 // the expected response(s)?
560 if(logger.isDebugEnabled()){
561 logger.debug(testName + ": url=" + url +
562 " status=" + statusCode);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
570 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
571 dependsOnMethods = {"create", "update", "testSubmitRequest"})
572 public void updateWithMalformedXml(String testName) throws Exception {
574 if (logger.isDebugEnabled()) {
575 logger.debug(testBanner(testName, CLASS_NAME));
578 setupUpdateWithMalformedXml();
580 // Submit the request to the service and store the response.
581 String method = REQUEST_TYPE.httpMethodName();
582 String url = getResourceURL(knownResourceId);
583 String mediaType = MediaType.APPLICATION_XML;
584 final String entity = MALFORMED_XML_DATA;
585 int statusCode = submitRequest(method, url, mediaType, entity);
587 // Check the status code of the response: does it match
588 // the expected response(s)?
589 if(logger.isDebugEnabled()){
590 logger.debug(testName + ": url=" + url +
591 " status=" + statusCode);
593 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
594 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
595 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
599 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
600 dependsOnMethods = {"create", "update", "testSubmitRequest"})
601 public void updateWithWrongXmlSchema(String testName) throws Exception {
603 if (logger.isDebugEnabled()) {
604 logger.debug(testBanner(testName, CLASS_NAME));
607 setupUpdateWithWrongXmlSchema();
609 // Submit the request to the service and store the response.
610 String method = REQUEST_TYPE.httpMethodName();
611 String url = getResourceURL(knownResourceId);
612 String mediaType = MediaType.APPLICATION_XML;
613 final String entity = WRONG_XML_SCHEMA_DATA;
614 int statusCode = submitRequest(method, url, mediaType, entity);
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": url=" + url +
620 " status=" + statusCode);
622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
632 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
633 dependsOnMethods = {"update", "testSubmitRequest"})
634 public void updateNonExistent(String testName) throws Exception {
636 if (logger.isDebugEnabled()) {
637 logger.debug(testBanner(testName, CLASS_NAME));
640 setupUpdateNonExistent();
642 // Submit the request to the service and store the response.
643 // Note: The ID used in this 'create' call may be arbitrary.
644 // The only relevant ID may be the one used in update(), below.
645 MovementClient client = new MovementClient();
646 PoxPayloadOut multipart = createMovementInstance(NON_EXISTENT_ID);
647 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
648 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match
651 // the expected response(s)?
652 if(logger.isDebugEnabled()){
653 logger.debug(testName + ": status = " + statusCode);
655 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
660 // ---------------------------------------------------------------
661 // CRUD tests : DELETE tests
662 // ---------------------------------------------------------------
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
669 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
670 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
671 public void delete(String testName) throws Exception {
673 if (logger.isDebugEnabled()) {
674 logger.debug(testBanner(testName, CLASS_NAME));
680 // Submit the request to the service and store the response.
681 MovementClient client = new MovementClient();
682 ClientResponse<Response> res = client.delete(knownResourceId);
683 int statusCode = res.getStatus();
685 // Check the status code of the response: does it match
686 // the expected response(s)?
687 if(logger.isDebugEnabled()){
688 logger.debug(testName + ": status = " + statusCode);
690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
700 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
703 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
704 dependsOnMethods = {"delete"})
705 public void deleteNonExistent(String testName) throws Exception {
707 if (logger.isDebugEnabled()) {
708 logger.debug(testBanner(testName, CLASS_NAME));
711 setupDeleteNonExistent();
713 // Submit the request to the service and store the response.
714 MovementClient client = new MovementClient();
715 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
716 int statusCode = res.getStatus();
718 // Check the status code of the response: does it match
719 // the expected response(s)?
720 if(logger.isDebugEnabled()){
721 logger.debug(testName + ": status = " + statusCode);
723 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
724 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
725 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
728 // ---------------------------------------------------------------
729 // Utility tests : tests of code used in tests above
730 // ---------------------------------------------------------------
732 * Tests the code for manually submitting data that is used by several
733 * of the methods above.
735 @Test(dependsOnMethods = {"create", "read"})
736 public void testSubmitRequest() {
738 // Expected status code: 200 OK
739 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
741 // Submit the request to the service and store the response.
742 String method = ServiceRequestType.READ.httpMethodName();
743 String url = getResourceURL(knownResourceId);
744 int statusCode = submitRequest(method, url);
746 // Check the status code of the response: does it match
747 // the expected response(s)?
748 if(logger.isDebugEnabled()){
749 logger.debug("testSubmitRequest: url=" + url +
750 " status=" + statusCode);
752 Assert.assertEquals(statusCode, EXPECTED_STATUS);
756 // ---------------------------------------------------------------
757 // Utility methods used by tests above
758 // ---------------------------------------------------------------
761 protected String getServiceName() {
766 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
769 public String getServicePathComponent() {
770 return SERVICE_PATH_COMPONENT;
774 * Creates the movement instance.
776 * @param identifier the identifier
777 * @return the multipart output
779 private PoxPayloadOut createMovementInstance(String identifier) {
780 return createInstance("movementReferenceNumber-" + identifier);
784 * Creates an instance of a Movement record for testing.
786 * @param movementReferenceNumber A movement reference number.
787 * @return Multipart output suitable for use as a payload
788 * in a create or update request.
791 public PoxPayloadOut createInstance(String movementReferenceNumber) {
792 MovementsCommon movementCommon = new MovementsCommon();
793 // FIXME: Values of currentLocation, normalLocation,
794 // and movementContact should be refNames.
795 movementCommon.setCurrentLocation("currentLocation value");
796 movementCommon.setCurrentLocationFitness("currentLocationFitness value");
797 movementCommon.setCurrentLocationNote("currentLocationNote value");
798 movementCommon.setLocationDate(TIMESTAMP_UTC);
799 movementCommon.setNormalLocation("normalLocation value");
800 movementCommon.setMovementContact("movementContact value");
801 MovementMethodsList movementMethodsList = new MovementMethodsList();
802 List<String> methods = movementMethodsList.getMovementMethod();
803 // @TODO Use properly formatted refNames for representative movement
804 // methods in this example record. The values below are placeholders.
805 String identifier = createIdentifier();
806 methods.add("First Movement Method-" + identifier);
807 methods.add("Second Movement Method-" + identifier);
808 movementCommon.setMovementMethods(movementMethodsList);
809 movementCommon.setMovementNote(getUTF8DataFragment());
810 movementCommon.setMovementReferenceNumber(movementReferenceNumber);
811 movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC);
812 movementCommon.setRemovalDate(""); // Test empty date value
813 movementCommon.setReasonForMove("reasonForMove value");
815 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
816 PayloadOutputPart commonPart =
817 multipart.addPart(movementCommon, MediaType.APPLICATION_XML_TYPE);
818 commonPart.setLabel(new MovementClient().getCommonPartName());
820 if(logger.isDebugEnabled()){
821 logger.debug("to be created, movement common");
822 logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));