]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8f48f2fa19f8b1ee309bbf1d415659aeb5de6d28
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.List;
26
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;
35
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * MovementServiceTest, carries out tests against a deployed and running
43  * Movement Service.
44  * 
45  * $LastChangedRevision$ $LastChangedDate: 2011-11-14 23:26:36 -0800
46  * (Mon, 14 Nov 2011) $
47  */
48 public class MovementServiceTest extends
49                 AbstractPoxServiceTestImpl<AbstractCommonList, MovementsCommon> {
50
51         /** The logger. */
52         private final String CLASS_NAME = MovementServiceTest.class.getName();
53         private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
54
55         final String SERVICE_NAME = "movements";
56         final String SERVICE_PATH_COMPONENT = "movements";
57
58         private final static String TIMESTAMP_UTC =
59                         GregorianCalendarDateTimeUtils.timestampUTC();
60         /*
61          * (non-Javadoc)
62          * 
63          * @see
64          * org.collectionspace.services.client.test.BaseServiceTest#getClientInstance
65          * ()
66          */
67         @Override
68         protected CollectionSpaceClient getClientInstance() {
69                 return new MovementClient();
70         }
71
72         // ---------------------------------------------------------------
73         // Utility methods used by tests above
74         // ---------------------------------------------------------------
75
76         @Override
77         protected String getServiceName() {
78                 return SERVICE_NAME;
79         }
80
81         /*
82          * (non-Javadoc)
83          * 
84          * @see org.collectionspace.services.client.test.BaseServiceTest#
85          * getServicePathComponent()
86          */
87         @Override
88         public String getServicePathComponent() {
89                 return SERVICE_PATH_COMPONENT;
90         }
91
92         /**
93          * Creates the movement instance.
94          * 
95          * @param identifier
96          *            the identifier
97          * @return the multipart output
98          */
99         private PoxPayloadOut createMovementInstance(String identifier) {
100                 return createInstance("movementReferenceNumber-" + identifier);
101         }
102
103         @Override
104         protected PoxPayloadOut createInstance(String commonPartName,
105                         String identifier) {
106                 PoxPayloadOut result = createMovementInstance(identifier);
107                 return result;
108         }
109
110         /**
111          * Creates an instance of a Movement record for testing.
112          * 
113          * @param movementReferenceNumber
114          *            A movement reference number.
115          * @return Multipart output suitable for use as a payload in a create or
116          *         update request.
117          */
118         @Override
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");
124                 movementCommon
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");
143
144                 PoxPayloadOut multipart = new PoxPayloadOut(
145                                 this.getServicePathComponent());
146                 PayloadOutputPart commonPart = multipart.addPart(
147                                 new MovementClient().getCommonPartName(), movementCommon);
148
149                 if (logger.isDebugEnabled()) {
150                         logger.debug("to be created, movement common");
151                         logger.debug(objectAsXmlString(movementCommon,
152                                         MovementsCommon.class));
153                 }
154
155                 return multipart;
156         }
157
158         @Override
159         protected MovementsCommon updateInstance(MovementsCommon movementsCommon) {
160                 MovementsCommon result = new MovementsCommon();
161                 
162                 result.setMovementReferenceNumber("updated-"
163                                 + movementsCommon.getMovementReferenceNumber());
164                 result.setMovementNote("updated movement note-"
165                                 + movementsCommon.getMovementNote());
166                 result.setNormalLocation(""); // Test deletion of existing
167                                                                                                 // string value
168
169                 String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC();
170                 result.setPlannedRemovalDate(""); // Test deletion of existing
171                                                                                                         // date or date/time value
172                 result.setRemovalDate(currentTimestamp);
173                 
174                 return result;
175         }
176
177         @Override
178         protected void compareUpdatedInstances(MovementsCommon original,
179                         MovementsCommon updated) throws Exception {
180                 // By submitting an empty string in the update payload, the value of
181                 // this field
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() + "|");
188                 }
189
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.");
200
201                 if (logger.isDebugEnabled()) {
202                         logger.debug("UTF-8 data sent=" + original.getMovementNote()
203                                         + "\n" + "UTF-8 data received="
204                                         + updated.getMovementNote());
205                 }
206                 Assert.assertTrue(
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.");
215         }
216
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);
223                 }
224                 Assert.assertTrue(fromRead.getLocationDate().equals(TIMESTAMP_UTC));
225                 Assert.assertTrue(fromRead.getPlannedRemovalDate().equals(TIMESTAMP_UTC));
226                 Assert.assertNull(fromRead.getRemovalDate());
227
228                 // Check the values of fields containing Unicode UTF-8 (non-Latin-1)
229                 // characters.
230                 if (logger.isDebugEnabled()) {
231                         logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
232                                         + "UTF-8 data received=" + fromRead.getMovementNote());
233                 }
234                 Assert.assertEquals(fromRead.getMovementNote(),
235                                 getUTF8DataFragment(), "UTF-8 data retrieved '"
236                                                 + fromRead.getMovementNote()
237                                                 + "' does not match expected data '"
238                                                 + getUTF8DataFragment());
239         }
240
241         /*
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.
245          */
246         @Override
247         @Test(dataProvider = "testName", dependsOnMethods = { "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests" })
248         public void CRUDTests(String testName) {
249                 // TODO Auto-generated method stub
250         }
251
252         @Override
253         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
254                 // TODO Auto-generated method stub
255                 return null;
256         }
257 }