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;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.MovementClient;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.movement.MovementsCommon;
34 import org.collectionspace.services.movement.MovementMethodsList;
36 import org.jboss.resteasy.client.ClientResponse;
38 import org.collectionspace.services.client.AbstractCommonListUtils;
39 import org.collectionspace.services.client.PayloadInputPart;
40 import org.collectionspace.services.client.PayloadOutputPart;
41 import org.collectionspace.services.client.PoxPayloadIn;
42 import org.collectionspace.services.client.PoxPayloadOut;
43 import org.testng.Assert;
44 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * MovementServiceTest, carries out tests against a deployed and running
53 * $LastChangedRevision$ $LastChangedDate: 2011-11-14 23:26:36 -0800
54 * (Mon, 14 Nov 2011) $
56 public class MovementServiceTest extends
57 AbstractPoxServiceTestImpl<AbstractCommonList, MovementsCommon> {
60 private final String CLASS_NAME = MovementServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
63 final String SERVICE_NAME = "movements";
64 final String SERVICE_PATH_COMPONENT = "movements";
66 private final static String TIMESTAMP_UTC = GregorianCalendarDateTimeUtils
73 * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance
77 protected CollectionSpaceClient getClientInstance() {
78 return new MovementClient();
81 // ---------------------------------------------------------------
82 // Utility methods used by tests above
83 // ---------------------------------------------------------------
86 protected String getServiceName() {
93 * @see org.collectionspace.services.client.test.BaseServiceTest#
94 * getServicePathComponent()
97 public String getServicePathComponent() {
98 return SERVICE_PATH_COMPONENT;
102 * Creates the movement instance.
106 * @return the multipart output
108 private PoxPayloadOut createMovementInstance(String identifier) {
109 return createInstance("movementReferenceNumber-" + identifier);
113 protected PoxPayloadOut createInstance(String commonPartName,
115 PoxPayloadOut result = createMovementInstance(identifier);
120 * Creates an instance of a Movement record for testing.
122 * @param movementReferenceNumber
123 * A movement reference number.
124 * @return Multipart output suitable for use as a payload in a create or
128 protected PoxPayloadOut createInstance(String movementReferenceNumber) {
129 MovementsCommon movementCommon = new MovementsCommon();
130 // FIXME: Values of currentLocation, normalLocation,
131 // and movementContact should be refNames.
132 movementCommon.setCurrentLocation("currentLocation value");
134 .setCurrentLocationFitness("currentLocationFitness value");
135 movementCommon.setCurrentLocationNote("currentLocationNote value");
136 movementCommon.setLocationDate(TIMESTAMP_UTC);
137 movementCommon.setNormalLocation("normalLocation value");
138 movementCommon.setMovementContact("movementContact value");
139 MovementMethodsList movementMethodsList = new MovementMethodsList();
140 List<String> methods = movementMethodsList.getMovementMethod();
141 // @TODO Use properly formatted refNames for representative movement
142 // methods in this example record. The values below are placeholders.
143 String identifier = createIdentifier();
144 methods.add("First Movement Method-" + identifier);
145 methods.add("Second Movement Method-" + identifier);
146 movementCommon.setMovementMethods(movementMethodsList);
147 movementCommon.setMovementNote(getUTF8DataFragment());
148 movementCommon.setMovementReferenceNumber(movementReferenceNumber);
149 movementCommon.setPlannedRemovalDate(TIMESTAMP_UTC);
150 movementCommon.setRemovalDate(""); // Test empty date value
151 movementCommon.setReasonForMove("reasonForMove value");
153 PoxPayloadOut multipart = new PoxPayloadOut(
154 this.getServicePathComponent());
155 PayloadOutputPart commonPart = multipart.addPart(
156 new MovementClient().getCommonPartName(), movementCommon);
158 if (logger.isDebugEnabled()) {
159 logger.debug("to be created, movement common");
160 logger.debug(objectAsXmlString(movementCommon,
161 MovementsCommon.class));
168 protected MovementsCommon updateInstance(MovementsCommon movementsCommon) {
169 MovementsCommon result = new MovementsCommon();
171 result.setMovementReferenceNumber("updated-"
172 + movementsCommon.getMovementReferenceNumber());
173 result.setMovementNote("updated movement note-"
174 + movementsCommon.getMovementNote());
175 result.setNormalLocation(""); // Test deletion of existing
178 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
179 result.setPlannedRemovalDate(""); // Test deletion of existing
180 // date or date/time value
181 result.setRemovalDate(currentTimestamp);
187 protected void compareUpdatedInstances(MovementsCommon original,
188 MovementsCommon updated) throws Exception {
189 // By submitting an empty string in the update payload, the value of
191 // in the object created from the response payload will be null.
192 Assert.assertNull(updated.getNormalLocation(),
193 "Normal location in updated object did not match submitted data.");
194 if (logger.isDebugEnabled()) {
195 logger.debug("Normal location after update=|"
196 + updated.getNormalLocation() + "|");
199 Assert.assertEquals(updated.getMovementReferenceNumber(),
200 original.getMovementReferenceNumber(),
201 "Movement reference number in updated object did not match submitted data.");
202 Assert.assertEquals(updated.getMovementNote(),
203 original.getMovementNote(),
204 "Movement note in updated object did not match submitted data.");
205 Assert.assertNull(updated.getPlannedRemovalDate());
206 Assert.assertEquals(updated.getRemovalDate(),
207 original.getRemovalDate(),
208 "Removal date in updated object did not match submitted data.");
210 if (logger.isDebugEnabled()) {
211 logger.debug("UTF-8 data sent=" + original.getMovementNote()
212 + "\n" + "UTF-8 data received="
213 + updated.getMovementNote());
216 updated.getMovementNote().contains(
217 getUTF8DataFragment()), "UTF-8 data retrieved '"
218 + updated.getMovementNote()
219 + "' does not contain expected data '"
220 + getUTF8DataFragment());
221 Assert.assertEquals(updated.getMovementNote(),
222 original.getMovementNote(),
223 "Movement note in updated object did not match submitted data.");
226 protected void compareReadInstances(MovementsCommon original,
227 MovementsCommon fromRead) throws Exception {
228 // Check the values of one or more date/time fields.
229 if (logger.isDebugEnabled()) {
230 logger.debug("locationDate=" + fromRead.getLocationDate());
231 logger.debug("TIMESTAMP_UTC=" + TIMESTAMP_UTC);
233 Assert.assertTrue(fromRead.getLocationDate().equals(TIMESTAMP_UTC));
234 Assert.assertTrue(fromRead.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
235 Assert.assertNull(fromRead.getRemovalDate());
237 // Check the values of fields containing Unicode UTF-8 (non-Latin-1)
239 if (logger.isDebugEnabled()) {
240 logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
241 + "UTF-8 data received=" + fromRead.getMovementNote());
243 Assert.assertEquals(fromRead.getMovementNote(),
244 getUTF8DataFragment(), "UTF-8 data retrieved '"
245 + fromRead.getMovementNote()
246 + "' does not match expected data '"
247 + getUTF8DataFragment());
251 * For convenience and terseness, this test method is the base of the test
252 * execution dependency chain. Other test methods may refer to this method
253 * in their @Test annotation declarations.
256 @Test(dataProvider = "testName", dependsOnMethods = { "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests" })
257 public void CRUDTests(String testName) {
258 // TODO Auto-generated method stub