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.Collator;
26 import java.util.ArrayList;
27 import java.util.Comparator;
28 import java.util.List;
29 import java.util.Locale;
31 import javax.ws.rs.core.Response;
33 import org.collectionspace.services.MovementJAXBSchema;
34 import org.collectionspace.services.client.AbstractCommonListUtils;
35 import org.collectionspace.services.client.CollectionSpaceClient;
36 import org.collectionspace.services.client.MovementClient;
37 import org.collectionspace.services.client.PayloadInputPart;
38 import org.collectionspace.services.client.PayloadOutputPart;
39 import org.collectionspace.services.client.PoxPayloadIn;
40 import org.collectionspace.services.client.PoxPayloadOut;
41 import org.collectionspace.services.movement.MovementsCommon;
42 import org.collectionspace.services.jaxb.AbstractCommonList;
44 import org.testng.Assert;
45 import org.testng.annotations.AfterClass;
46 import org.testng.annotations.DataProvider;
47 import org.testng.annotations.Test;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * MovementSortByTest, tests sorting of summary lists by fields
53 * of various datatypes.
55 * $LastChangedRevision: 2562 $
56 * $LastChangedDate: 2010-06-22 23:26:51 -0700 (Tue, 22 Jun 2010) $
58 public class MovementSortByTest extends BaseServiceTest<AbstractCommonList> {
60 private final String CLASS_NAME = MovementSortByTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 final String SERVICE_NAME = "movements";
64 // Instance variables specific to this test.
65 private final String DELIMITER_SCHEMA_AND_FIELD = ":";
66 private final String KEYWORD_DESCENDING_SEARCH = "DESC";
67 private final String SERVICE_PATH_COMPONENT = "movements";
68 private final String TEST_SPECIFIC_KEYWORD = "msotebstpfscn";
69 private List<String> movementIdsCreated = new ArrayList<String>();
70 private final String SORT_FIELD_SEPARATOR = ", ";
71 private final Locale LOCALE = Locale.US;
72 private final String LOCATION_DATE_EL_NAME = "locationDate";
73 private final Comparator<String> CASE_INSENSITIVE_STRING_COMPARATOR =
74 String.CASE_INSENSITIVE_ORDER;
75 private final Collator LOCALE_SPECIFIC_COLLATOR = Collator.getInstance(LOCALE);
80 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
83 protected CollectionSpaceClient getClientInstance() {
84 throw new UnsupportedOperationException(); //method not supported (or needed) in this test class
88 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
89 throw new UnsupportedOperationException(); //method not supported (or needed) in this test class
93 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
96 protected AbstractCommonList getCommonList(Response response) {
97 throw new UnsupportedOperationException(); //method not supported (or needed) in this test class
100 // ---------------------------------------------------------------
102 // ---------------------------------------------------------------
107 * Tests whether a list of records, sorted by a String field in
108 * ascending order, is returned in the expected order.
110 @Test(dataProvider = "testName",
111 dependsOnMethods = {"createList"})
112 public void sortByStringFieldAscending(String testName) throws Exception {
113 String sortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE);
114 if (logger.isDebugEnabled()) {
115 logger.debug("Sorting on field name=" + sortFieldName);
117 AbstractCommonList list = readSortedList(sortFieldName);
118 List<AbstractCommonList.ListItem> items =
121 ArrayList<String> values = new ArrayList<String>();
123 for (AbstractCommonList.ListItem item : items) {
124 // Because movementNote is not currently a summary field
125 // (returned in summary list items), we will need to verify
126 // sort order by using the IDs provided in the summary list
127 // items to retrieve full records, and then obtaining
128 // the value of that field from each of those records.
129 MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item));
130 values.add(i, movement.getMovementNote());
131 if (logger.isTraceEnabled()) {
132 logger.trace("list-item[" + i + "] movementNote=" + values.get(i));
134 // Verify that the value of the specified field in the current record
135 // is equal to or greater than its value in the previous record.
137 // (Note: when used with certain text, this test case could potentially
138 // reflect inconsistencies, if any, between Java's collator and the
139 // collator used for ordering by the database. To help avoid this,
140 // it might be useful to keep test strings fairly generic.)
141 if (i > 0 && values.get(i) != null && values.get(i - 1) != null) {
142 if (logger.isDebugEnabled()) {
143 logger.debug("Comparing " + values.get(i) + " with previous value " + values.get(i - 1) + "...");
145 Assert.assertTrue(LOCALE_SPECIFIC_COLLATOR.compare(values.get(i), values.get(i - 1)) >= 0);
153 * Tests whether a list of records, obtained by a keyword search, and
154 * sorted by a String field in ascending order, is returned in the expected order.
156 * This verifies that summary list results from keyword searches, in
157 * addition to 'read list' requests, can be returned in sorted order.
159 @Test(dataProvider = "testName",
160 dependsOnMethods = {"createList"})
161 public void sortKeywordSearchResultsByStringFieldAscending(String testName) throws Exception {
162 String sortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE);
163 if (logger.isDebugEnabled()) {
164 logger.debug("Sorting on field name=" + sortFieldName);
166 AbstractCommonList list = keywordSearchSortedBy(TEST_SPECIFIC_KEYWORD, sortFieldName);
167 List<AbstractCommonList.ListItem> items =
170 ArrayList<String> values = new ArrayList<String>();
172 for (AbstractCommonList.ListItem item : items) {
173 // Because movementNote is not currently a summary field
174 // (returned in summary list items), we will need to verify
175 // sort order by using the IDs provided in the summary list
176 // items to retrieve full records, and then obtaining
177 // the value of that field from each of those records.
178 MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item));
179 values.add(i, movement.getMovementNote());
180 if (logger.isTraceEnabled()) {
181 logger.trace("list-item[" + i + "] movementNote=" + values.get(i));
183 // Verify that the value of the specified field in the current record
184 // is equal to or greater than its value in the previous record.
186 // (Note: when used with certain text, this test case could potentially
187 // reflect inconsistencies, if any, between Java's collator and the
188 // collator used for ordering by the database. To help avoid this,
189 // it might be useful to keep test strings fairly generic.)
190 if (i > 0 && values.get(i) != null && values.get(i - 1) != null) {
191 if (logger.isDebugEnabled()) {
192 logger.debug("Comparing " + values.get(i) + " with previous value " + values.get(i - 1) + "...");
194 Assert.assertTrue(LOCALE_SPECIFIC_COLLATOR.compare(values.get(i), values.get(i - 1)) >= 0);
202 * Tests whether a list of records, sorted by a String field in
203 * descending order, is returned in the expected order.
205 @Test(dataProvider = "testName",
206 dependsOnMethods = {"createList"})
207 public void sortByStringFieldDescending(String testName) throws Exception {
208 String sortFieldName =
209 asDescendingSort(qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE));
210 if (logger.isDebugEnabled()) {
211 logger.debug("Sorting on field name=" + sortFieldName);
213 AbstractCommonList list = readSortedList(sortFieldName);
214 List<AbstractCommonList.ListItem> items =
217 ArrayList<String> values = new ArrayList<String>();
219 for (AbstractCommonList.ListItem item : items) {
220 // Because movementNote is not currently a summary field
221 // (returned in summary list items), we will need to verify
222 // sort order by using the IDs provided in the summary list
223 // items to retrieve full records, and then obtaining
224 // the value of that field from each of those records.
225 MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item));
226 values.add(i, movement.getMovementNote());
227 if (logger.isTraceEnabled()) {
228 logger.trace("list-item[" + i + "] movementNote=" + values.get(i));
230 // Verify that the value of the specified field in the current record
231 // is less than or equal to than its value in the previous record.
233 // (Note: when used with certain text, this test case could potentially
234 // reflect inconsistencies, if any, between Java's comparator or collator,
235 // and the collator used for ordering by the database. To help avoid this,
236 // it might be useful to keep test strings fairly generic.)
237 if (i > 0 && values.get(i) != null && values.get(i - 1) != null) {
238 if (logger.isDebugEnabled()) {
239 logger.debug("Comparing " + values.get(i) + " with previous value " + values.get(i - 1) + "...");
241 Assert.assertTrue(LOCALE_SPECIFIC_COLLATOR.compare(values.get(i), values.get(i - 1)) <= 0);
249 * Tests whether a list of records, sorted by a dateTime field in
250 * ascending order, is returned in the expected order.
252 @Test(dataProvider = "testName",
253 dependsOnMethods = {"createList"})
254 public void sortByDateTimeFieldAscending(String testName) throws Exception {
255 String sortFieldName = qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE);
256 if (logger.isDebugEnabled()) {
257 logger.debug("Sorting on field name=" + sortFieldName);
259 AbstractCommonList list = readSortedList(sortFieldName);
260 List<AbstractCommonList.ListItem> items =
263 ArrayList<String> values = new ArrayList<String>();
265 for (AbstractCommonList.ListItem item : items) {
267 AbstractCommonListUtils.ListItemGetElementValue(item, LOCATION_DATE_EL_NAME);
268 values.add(i, locDate);
269 if (logger.isTraceEnabled()) {
270 logger.trace("list-item[" + i + "] locationDate=" + values.get(i));
272 // Verify that the value of the specified field in the current record
273 // is equal to or greater than its value in the previous record.
274 if (i > 0 && values.get(i) != null && values.get(i - 1) != null) {
275 if (logger.isDebugEnabled()) {
276 logger.debug("Comparing " + values.get(i) + " with previous value " + values.get(i - 1) + "...");
278 Assert.assertTrue(CASE_INSENSITIVE_STRING_COMPARATOR.compare(values.get(i), values.get(i - 1)) >= 0);
285 * Tests whether a list of records, sorted by a dateTime field in
286 * descending order, is returned in the expected order.
288 @Test(dataProvider = "testName",
289 dependsOnMethods = {"createList"})
290 public void sortByDateTimeFieldDescending(String testName) throws Exception {
291 String sortFieldName =
292 asDescendingSort(qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE));
293 if (logger.isDebugEnabled()) {
294 logger.debug("Sorting on field name=" + sortFieldName);
296 AbstractCommonList list = readSortedList(sortFieldName);
297 List<AbstractCommonList.ListItem> items =
300 ArrayList<String> values = new ArrayList<String>();
302 for (AbstractCommonList.ListItem item : items) {
304 AbstractCommonListUtils.ListItemGetElementValue(item, LOCATION_DATE_EL_NAME);
305 values.add(i, locDate);
306 if (logger.isTraceEnabled()) {
307 logger.trace("list-item[" + i + "] locationDate=" + values.get(i));
309 // Verify that the value of the specified field in the current record
310 // is less than or equal to its value in the previous record.
311 if (i > 0 && values.get(i) != null && values.get(i - 1) != null) {
312 if (logger.isDebugEnabled()) {
313 logger.debug("Comparing " + values.get(i) + " with previous value " + values.get(i - 1) + "...");
315 Assert.assertTrue(CASE_INSENSITIVE_STRING_COMPARATOR.compare(values.get(i), values.get(i - 1)) <= 0);
322 * Tests whether a list of records, sorted by two different fields in
323 * ascending order, is returned in the expected order.
325 @Test(dataProvider = "testName",
326 dependsOnMethods = {"createList"})
327 public void sortByTwoFieldsAscending(String testName) throws Exception {
328 String firstSortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE);
329 String secondSortFieldName = qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE);
330 if (logger.isDebugEnabled()) {
331 logger.debug("Sorting on field names=" + firstSortFieldName + " and " + secondSortFieldName);
333 String sortExpression = firstSortFieldName + SORT_FIELD_SEPARATOR + secondSortFieldName;
334 AbstractCommonList list = readSortedList(sortExpression);
335 List<AbstractCommonList.ListItem> items =
338 ArrayList<String> firstFieldValues = new ArrayList<String>();
339 ArrayList<String> secondFieldValues = new ArrayList<String>();
341 for (AbstractCommonList.ListItem item : items) {
342 // Because movementNote is not currently a summary field
343 // (returned in summary list items), we will need to verify
344 // sort order by using the IDs provided in the summary list
345 // items to retrieve full records, and then obtaining
346 // the value of that field from each of those records.
347 MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item));
348 firstFieldValues.add(i, movement.getMovementNote());
349 secondFieldValues.add(i, movement.getLocationDate());
350 if (logger.isDebugEnabled()) {
351 logger.debug("list-item[" + i + "] movementNote=" + firstFieldValues.get(i));
352 logger.debug("list-item[" + i + "] locationDate=" + secondFieldValues.get(i));
354 // Verify that the value of the specified field in the current record
355 // is less than or greater than its value in the previous record.
356 if (i > 0 && firstFieldValues.get(i) != null && firstFieldValues.get(i - 1) != null) {
357 Assert.assertTrue(LOCALE_SPECIFIC_COLLATOR.compare(firstFieldValues.get(i), firstFieldValues.get(i - 1)) >= 0);
358 // If the value of the first sort field in the current record is identical to
359 // its value in the previous record, verify that the value of the second sort
360 // field is equal to or greater than its value in the previous record.
361 if (LOCALE_SPECIFIC_COLLATOR.compare(firstFieldValues.get(i), firstFieldValues.get(i - 1)) == 0) {
362 if (i > 0 && secondFieldValues.get(i) != null && secondFieldValues.get(i - 1) != null) {
363 Assert.assertTrue(CASE_INSENSITIVE_STRING_COMPARATOR.compare(secondFieldValues.get(i), secondFieldValues.get(i - 1)) >= 0);
372 * Tests whether a list of records, sorted by one different fields in
373 * descending order and a second field in ascending order, is returned in the expected order.
375 @Test(dataProvider = "testName",
376 dependsOnMethods = {"createList"})
377 public void sortByOneFieldAscendingOneFieldDescending(String testName) throws Exception {
378 String firstSortFieldName =
379 asDescendingSort(qualifySortFieldName(MovementJAXBSchema.LOCATION_DATE));
380 String secondSortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE);
381 if (logger.isDebugEnabled()) {
382 logger.debug("Sorting on field names=" + firstSortFieldName + " and " + secondSortFieldName);
384 String sortExpression = firstSortFieldName + SORT_FIELD_SEPARATOR + secondSortFieldName;
385 AbstractCommonList list = readSortedList(sortExpression);
386 List<AbstractCommonList.ListItem> items =
389 ArrayList<String> firstFieldValues = new ArrayList<String>();
390 ArrayList<String> secondFieldValues = new ArrayList<String>();
392 for (AbstractCommonList.ListItem item : items) {
393 // Because movementNote is not currently a summary field
394 // (returned in summary list items), we will need to verify
395 // sort order by using the IDs provided in the summary list
396 // items to retrieve full records, and then obtaining
397 // the value of that field from each of those records.
398 MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item));
399 firstFieldValues.add(i, movement.getLocationDate());
400 secondFieldValues.add(i, movement.getMovementNote());
401 if (logger.isDebugEnabled()) {
402 logger.debug("list-item[" + i + "] locationDate=" + firstFieldValues.get(i));
403 logger.debug("list-item[" + i + "] movementNote=" + secondFieldValues.get(i));
405 // Verify that the value of the specified field in the current record
406 // is less than or equal to than its value in the previous record.
407 if (i > 0 && firstFieldValues.get(i) != null && firstFieldValues.get(i - 1) != null) {
408 Assert.assertTrue(CASE_INSENSITIVE_STRING_COMPARATOR.compare(firstFieldValues.get(i), firstFieldValues.get(i - 1)) <= 0);
409 // If the value of the first sort field in the current record is identical to
410 // its value in the previous record, verify that the value of the second sort
411 // field is equal to or greater than its value in the previous record,
412 // using a locale-specific collator.
413 if (CASE_INSENSITIVE_STRING_COMPARATOR.compare(firstFieldValues.get(i), firstFieldValues.get(i - 1)) == 0) {
414 if (i > 0 && secondFieldValues.get(i) != null && secondFieldValues.get(i - 1) != null) {
415 Assert.assertTrue(LOCALE_SPECIFIC_COLLATOR.compare(secondFieldValues.get(i), secondFieldValues.get(i - 1)) >= 0);
425 * Tests whether a request to sort by an empty field name is handled
426 * as expected: the query parameter is simply ignored, and a list
427 * of records is returned, unsorted, with a success result.
429 @Test(dataProvider = "testName")
430 public void sortWithEmptySortFieldName(String testName) throws Exception {
431 testSetup(STATUS_OK, ServiceRequestType.READ);
433 // Submit the request to the service and store the response.
434 MovementClient client = new MovementClient();
435 final String EMPTY_SORT_FIELD_NAME = "";
436 Response res = client.readListSortedBy(EMPTY_SORT_FIELD_NAME);
438 assertStatusCode(res, testName);
449 * Tests whether a request to sort by an unqualified field name is
450 * handled as expected. The field name provided in this test is valid,
451 * but has not been qualified by being prefixed by a schema name and delimiter.
453 @Test(dataProvider = "testName")
454 public void sortWithUnqualifiedFieldName(String testName) throws Exception {
455 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.READ);
457 // Submit the request to the service and store the response.
458 MovementClient client = new MovementClient();
459 Response res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE);
461 assertStatusCode(res, testName);
470 * Tests whether a request to sort by an invalid identifier for the
471 * sort order (ascending or descending) is handled as expected.
473 @Test(dataProvider = "testName")
474 public void sortWithInvalidSortOrderIdentifier(String testName) throws Exception {
475 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.READ);
477 // Submit the request to the service and store the response.
478 MovementClient client = new MovementClient();
479 final String INVALID_SORT_ORDER_IDENTIFIER = "NO_DIRECTION";
480 Response res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE
481 + " " + INVALID_SORT_ORDER_IDENTIFIER);
483 assertStatusCode(res, testName);
491 // ---------------------------------------------------------------
492 // Cleanup of resources created during testing
493 // ---------------------------------------------------------------
495 * Deletes all resources created by tests, after all tests have been run.
497 * This cleanup method will always be run, even if one or more tests fail.
498 * For this reason, it attempts to remove all resources created
499 * at any point during testing, even if some of those resources
500 * may be expected to be deleted by certain tests.
502 @AfterClass(alwaysRun = true)
503 public void cleanUp() {
504 String noTest = System.getProperty("noTestCleanup");
505 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
506 if (logger.isDebugEnabled()) {
507 logger.debug("Skipping Cleanup phase ...");
511 if (logger.isDebugEnabled()) {
512 logger.debug("Cleaning up temporary resources created for testing ...");
514 // Delete all Movement resource(s) created during this test.
515 MovementClient movementClient = new MovementClient();
516 for (String resourceId : movementIdsCreated) {
517 // Note: Any non-success responses are ignored and not reported.
518 movementClient.delete(resourceId).close();
522 // ---------------------------------------------------------------
523 // Utility methods used by tests above
524 // ---------------------------------------------------------------
527 protected String getServiceName() {
532 public String getServicePathComponent() {
533 return SERVICE_PATH_COMPONENT;
536 private String getCommonSchemaName() {
537 // FIXME: While this convention - appending a suffix to the name of
538 // the service's first unique URL path component - works, it would
539 // be preferable to get the common schema name from configuration.
541 // Such configuration is provided for example, on the services side, in
542 // org.collectionspace.services.common.context.AbstractServiceContextImpl
543 return getServicePathComponent() + "_" + "common";
546 public String qualifySortFieldName(String fieldName) {
547 return getCommonSchemaName() + DELIMITER_SCHEMA_AND_FIELD + fieldName;
550 public String asDescendingSort(String qualifiedFieldName) {
551 return qualifiedFieldName + " " + KEYWORD_DESCENDING_SEARCH;
555 * A data provider that provides a set of unsorted values, which are
556 * to be used in populating (seeding) values in test records.
558 * Data elements provided for each test record consist of:
559 * * An integer, reflecting expected sort order.
560 * * US English text, to populate the value of a free text (String) field.
561 * * An ISO 8601 timestamp, to populate the value of a calendar date (dateTime) field.
563 @DataProvider(name = "unsortedValues")
564 public Object[][] unsortedValues() {
565 // FIXME: ADR Add a test record-specific string so we have the option of
566 // constraining tests to only test records, in list or search results.
567 final String TEST_RECORD_SPECIFIC_STRING = CLASS_NAME + " " + TEST_SPECIFIC_KEYWORD;
568 return new Object[][]{
569 {1, "aardvark and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2009-01-29T00:00:05Z"},
570 {10, "zounds! " + TEST_RECORD_SPECIFIC_STRING, "2010-08-31T00:00:00Z"},
571 {3, "aardvark and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2010-08-30T00:00:00Z"},
572 {7, "bat fling off wall. " + TEST_RECORD_SPECIFIC_STRING, "2010-08-30T00:00:00Z"},
573 {4, "aardvarks and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2009-01-29T08:00:00Z"},
574 {5, "aardvarks and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2009-05-29T00:00:00Z"},
575 {2, "aardvark and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2009-05-29T00:00:00Z"},
576 {9, "zounds! " + TEST_RECORD_SPECIFIC_STRING, "2009-05-29T00:00:00Z"}, // Identical to next record
577 {8, "zounds! " + TEST_RECORD_SPECIFIC_STRING, "2009-05-29T00:00:00Z"},
578 {6, "bat flies off ball. " + TEST_RECORD_SPECIFIC_STRING, "2009-05-29T00:00:00Z"}
583 * Create multiple test records, initially in unsorted order,
584 * using values for various fields obtained from the data provider.
586 @Test(dataProvider = "unsortedValues")
587 public void createList(int expectedSortOrder, String movementNote,
588 String locationDate) throws Exception {
590 String testName = "createList";
591 if (logger.isDebugEnabled()) {
592 logger.debug(getTestBanner(testName, CLASS_NAME));
594 testSetup(STATUS_CREATED, ServiceRequestType.CREATE);
596 // Iterates through the sets of values returned by the data provider,
597 // and creates a corresponding test record for each set of values.
598 create(movementNote, locationDate);
601 private void create(String movementNote, String locationDate) throws Exception {
602 String result = null;
604 String testName = "create";
605 testSetup(STATUS_CREATED, ServiceRequestType.CREATE);
607 // Submit the request to the service and store the response.
608 PoxPayloadOut multipart = createMovementInstance(createIdentifier(),
609 movementNote, locationDate);
610 MovementClient client = new MovementClient();
611 Response res = client.create(multipart);
613 assertStatusCode(res, testName);
614 // Store the IDs from every resource created by tests,
615 // so they can be deleted after tests have been run.
616 result = extractId(res);
623 if (result != null) {
624 movementIdsCreated.add(result);
628 private MovementsCommon read(String csid) throws Exception {
629 String testName = "read";
630 testSetup(STATUS_OK, ServiceRequestType.READ);
632 // Submit the request to the service and store the response.
633 MovementClient client = new MovementClient();
634 Response res = client.read(csid);
635 MovementsCommon movementCommon = null;
637 assertStatusCode(res, testName);
638 // Extract and return the common part of the record.
639 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
640 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
641 if (payloadInputPart != null) {
642 movementCommon = (MovementsCommon) payloadInputPart.getBody();
650 return movementCommon;
653 private PoxPayloadOut createMovementInstance(
654 String movementReferenceNumber,
656 String locationDate) {
657 MovementsCommon movementCommon = new MovementsCommon();
658 movementCommon.setMovementReferenceNumber(movementReferenceNumber);
659 movementCommon.setMovementNote(movementNote);
660 movementCommon.setLocationDate(locationDate);
662 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
663 PayloadOutputPart commonPart =
664 multipart.addPart(new MovementClient().getCommonPartName(), movementCommon);
665 if (logger.isDebugEnabled()) {
666 logger.debug("to be created, movement common");
667 logger.debug(objectAsXmlString(movementCommon, MovementsCommon.class));
673 private AbstractCommonList readSortedList(String sortFieldName) throws Exception {
674 String testName = "readSortedList";
675 testSetup(STATUS_OK, ServiceRequestType.READ);
677 // Submit the request to the service and store the response.
678 MovementClient client = new MovementClient();
680 Response res = client.readListSortedBy(sortFieldName);
681 AbstractCommonList list = null;
683 assertStatusCode(res, testName);
684 list = res.readEntity(AbstractCommonList.class);
695 private AbstractCommonList keywordSearchSortedBy(String keywords,
696 String sortFieldName) throws Exception {
697 AbstractCommonList result = null;
699 String testName = "keywordSearchSortedBy";
700 testSetup(STATUS_OK, ServiceRequestType.READ);
702 // Submit the request to the service and store the response.
703 MovementClient client = new MovementClient();
705 Response res = client.keywordSearchSortedBy(keywords, sortFieldName);
706 AbstractCommonList list = null;
708 assertStatusCode(res, testName);
709 list = res.readEntity(AbstractCommonList.class);