From 36668b93105ad9ed643e0b396bc7d7d0f4655d51 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 21 Jul 2010 02:27:35 +0000 Subject: [PATCH] CSPACE-2508: Added a negative test for an unrecognized sort order identifier (not 'ASC' or 'DESC') provided as a query parameter value. --- .../services/client/MovementProxy.java | 29 ++++++++----- .../client/test/MovementSortByTest.java | 42 ++++++++++++++++++- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java index 3bd9e3443..19ac2b65e 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java @@ -1,18 +1,25 @@ /** - * This document is a part of the source code and related artifacts - * for CollectionSpace, an open source collections management system - * for museums and related institutions: + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: * - * http://www.collectionspace.org - * http://wiki.collectionspace.org + * http://www.collectionspace.org + * http://wiki.collectionspace.org * - * Copyright © 2009 Regents of the University of California + * Copyright © 2009 Regents of the University of California * - * Licensed under the Educational Community License (ECL), Version 2.0. - * You may not use this file except in compliance with this License. + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. * - * You may obtain a copy of the ECL 2.0 License at - * https://source.collectionspace.org/collection-space/LICENSE.txt + * You may obtain a copy of the ECL 2.0 License at + * + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.collectionspace.services.client; @@ -36,7 +43,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; /** - * MovementClient.java + * MovementProxy.java * * $LastChangedRevision$ * $LastChangedDate$ diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java index 7602981da..dbf260259 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java @@ -385,6 +385,38 @@ public class MovementSortByTest extends BaseServiceTest { } + /* + * Tests whether a request to sort by an invalid identifier for the + * sort order (ascending or descending) is handled as expected. + */ + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void sortWithInvalidSortOrderIdentifier(String testName) throws Exception { + + if (logger.isDebugEnabled()) { + logger.debug(testBanner(testName, CLASS_NAME)); + } + // FIXME: Ultimately, this should return a BAD_REQUEST status. + testSetup(STATUS_INTERNAL_SERVER_ERROR, ServiceRequestType.READ); + + // Submit the request to the service and store the response. + MovementClient client = new MovementClient(); + final String INVALID_SORT_ORDER_IDENTIFIER = "NO_DIRECTION"; + ClientResponse res = + client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE + + " " + INVALID_SORT_ORDER_IDENTIFIER); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + } + /* * Tests whether a request to sort by a malformed field name is * handled as expected. @@ -450,6 +482,9 @@ public class MovementSortByTest extends BaseServiceTest { // FIXME: While this convention - appending a suffix to the name of // the service's first unique URL path component - works, it would // be preferable to get the common schema name from configuration. + // + // Such configuration is provided for example, on the services side, in + // org.collectionspace.services.common.context.AbstractServiceContextImpl return getServicePathComponent() + "_" + "common"; } @@ -484,6 +519,10 @@ public class MovementSortByTest extends BaseServiceTest { }; } + /* + * Create multiple test records, initially in unsorted order, + * using values for various fields obtained from the data provider. + */ @Test(dataProvider = "unsortedValues") public void createList(int expectedSortOrder, String movementNote, String locationDate) throws Exception { @@ -494,7 +533,8 @@ public class MovementSortByTest extends BaseServiceTest { } testSetup(STATUS_CREATED, ServiceRequestType.CREATE); - // Create each unsorted record provided by the data provider. + // Iterates through the sets of values returned by the data provider, + // and creates a corresponding test record for each set of values. create(movementNote, locationDate); } -- 2.47.3