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.util.List;
27 import org.collectionspace.services.client.CollectionSpaceClient;
28 import org.collectionspace.services.client.MovementClient;
29 import org.collectionspace.services.client.PayloadOutputPart;
30 import org.collectionspace.services.jaxb.AbstractCommonList;
31 import org.collectionspace.services.movement.MovementsCommon;
32 import org.collectionspace.services.movement.MovementMethodsList;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * MovementServiceTest, carries out tests against a deployed and running
45 * $LastChangedRevision$ $LastChangedDate: 2011-11-14 23:26:36 -0800
46 * (Mon, 14 Nov 2011) $
48 public class MovementServiceTest extends
49 AbstractPoxServiceTestImpl<AbstractCommonList, MovementsCommon> {
52 private final String CLASS_NAME = MovementServiceTest.class.getName();
53 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
55 final String SERVICE_NAME = "movements";
56 final String SERVICE_PATH_COMPONENT = "movements";
58 private final static String TIMESTAMP_UTC =
59 GregorianCalendarDateTimeUtils.timestampUTC();
64 * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance
68 protected CollectionSpaceClient getClientInstance() {
69 return new MovementClient();
72 // ---------------------------------------------------------------
73 // Utility methods used by tests above
74 // ---------------------------------------------------------------
77 protected String getServiceName() {
84 * @see org.collectionspace.services.client.test.BaseServiceTest#
85 * getServicePathComponent()
88 public String getServicePathComponent() {
89 return SERVICE_PATH_COMPONENT;
93 * Creates the movement instance.
97 * @return the multipart output
99 private PoxPayloadOut createMovementInstance(String identifier) {
100 return createInstance("movementReferenceNumber-" + identifier);
104 protected PoxPayloadOut createInstance(String commonPartName,
106 PoxPayloadOut result = createMovementInstance(identifier);
111 * Creates an instance of a Movement record for testing.
113 * @param movementReferenceNumber
114 * A movement reference number.
115 * @return Multipart output suitable for use as a payload in a create or
119 protected PoxPayloadOut createInstance(String movementReferenceNumber) {
120 MovementsCommon movementCommon = new MovementsCommon();
121 // FIXME: Values of currentLocation, normalLocation,
122 // and movementContact should be refNames.
123 movementCommon.setCurrentLocation("currentLocation value");
125 .setCurrentLocationFitness("currentLocationFitness value");
126 movementCommon.setCurrentLocationNote("currentLocationNote value");
127 movementCommon.setLocationDate(TIMESTAMP_UTC);
128 movementCommon.setNormalLocation("normalLocation value");
129 movementCommon.setMovementContact("movementContact value");
130 MovementMethodsList movementMethodsList = new MovementMethodsList();
131 List<String> methods = movementMethodsList.getMovementMethod();
132 // @TODO Use properly formatted refNames for representative movement
133 // methods in this example record. The values below are placeholders.
134 String identifier = createIdentifier();
135 methods.add("First Movement Method-" + identifier);
136 methods.add("Second Movement Method-" + identifier);
137 movementCommon.setMovementMethods(movementMethodsList);
138 movementCommon.setMovementNote(getUTF8DataFragment());
139 movementCommon.setMovementReferenceNumber(movementReferenceNumber);
140 movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC);
141 movementCommon.setRemovalDate(""); // Test empty date value
142 movementCommon.setReasonForMove("reasonForMove value");
144 PoxPayloadOut multipart = new PoxPayloadOut(
145 this.getServicePathComponent());
146 PayloadOutputPart commonPart = multipart.addPart(
147 new MovementClient().getCommonPartName(), movementCommon);
149 if (logger.isDebugEnabled()) {
150 logger.debug("to be created, movement common");
151 logger.debug(objectAsXmlString(movementCommon,
152 MovementsCommon.class));
159 protected MovementsCommon updateInstance(MovementsCommon movementsCommon) {
160 MovementsCommon result = new MovementsCommon();
162 result.setMovementReferenceNumber("updated-"
163 + movementsCommon.getMovementReferenceNumber());
164 result.setMovementNote("updated movement note-"
165 + movementsCommon.getMovementNote());
166 result.setNormalLocation(""); // Test deletion of existing
169 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
170 result.setPlannedRemovalDate(""); // Test deletion of existing
171 // date or date/time value
172 result.setRemovalDate(currentTimestamp);
178 protected void compareUpdatedInstances(MovementsCommon original,
179 MovementsCommon updated) throws Exception {
180 // By submitting an empty string in the update payload, the value of
182 // in the object created from the response payload will be null.
183 Assert.assertNull(updated.getNormalLocation(),
184 "Normal location in updated object did not match submitted data.");
185 if (logger.isDebugEnabled()) {
186 logger.debug("Normal location after update=|"
187 + updated.getNormalLocation() + "|");
190 Assert.assertEquals(updated.getMovementReferenceNumber(),
191 original.getMovementReferenceNumber(),
192 "Movement reference number in updated object did not match submitted data.");
193 Assert.assertEquals(updated.getMovementNote(),
194 original.getMovementNote(),
195 "Movement note in updated object did not match submitted data.");
196 Assert.assertNull(updated.getPlannedRemovalDate());
197 Assert.assertEquals(updated.getRemovalDate(),
198 original.getRemovalDate(),
199 "Removal date in updated object did not match submitted data.");
201 if (logger.isDebugEnabled()) {
202 logger.debug("UTF-8 data sent=" + original.getMovementNote()
203 + "\n" + "UTF-8 data received="
204 + updated.getMovementNote());
207 updated.getMovementNote().contains(
208 getUTF8DataFragment()), "UTF-8 data retrieved '"
209 + updated.getMovementNote()
210 + "' does not contain expected data '"
211 + getUTF8DataFragment());
212 Assert.assertEquals(updated.getMovementNote(),
213 original.getMovementNote(),
214 "Movement note in updated object did not match submitted data.");
217 protected void compareReadInstances(MovementsCommon original,
218 MovementsCommon fromRead) throws Exception {
219 // Check the values of one or more date/time fields.
220 if (logger.isDebugEnabled()) {
221 logger.debug("locationDate=" + fromRead.getLocationDate());
222 logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC);
224 Assert.assertTrue(fromRead.getLocationDate().equals(TIMESTAMP_UTC));
225 Assert.assertTrue(fromRead.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
226 Assert.assertNull(fromRead.getRemovalDate());
228 // Check the values of fields containing Unicode UTF-8 (non-Latin-1)
230 if (logger.isDebugEnabled()) {
231 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
232 + "UTF-8 data received=" + fromRead.getMovementNote());
234 Assert.assertEquals(fromRead.getMovementNote(),
235 getUTF8DataFragment(), "UTF-8 data retrieved '"
236 + fromRead.getMovementNote()
237 + "' does not match expected data '"
238 + getUTF8DataFragment());
242 * For convenience and terseness, this test method is the base of the test
243 * execution dependency chain. Other test methods may refer to this method
244 * in their @Test annotation declarations.
247 @Test(dataProvider = "testName", dependsOnMethods = { "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests" })
248 public void CRUDTests(String testName) {
249 // TODO Auto-generated method stub
253 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
254 // TODO Auto-generated method stub