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.ArrayList;
26 import java.math.BigDecimal;
28 import org.collectionspace.services.client.CollectionSpaceClient;
29 import org.collectionspace.services.client.DimensionClient;
30 import org.collectionspace.services.client.DimensionFactory;
31 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.dimension.DimensionsCommon;
33 import org.collectionspace.services.jaxb.AbstractCommonList;
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * DimensionServiceTest, carries out tests against a
42 * deployed and running Dimension Service.
44 * $LastChangedRevision: 917 $
45 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
47 public class DimensionServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, DimensionsCommon> {
50 private final String CLASS_NAME = DimensionServiceTest.class.getName();
51 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
53 // Instance variables specific to this test.
54 /** The SERVIC e_ pat h_ component. */
55 private final String DIMENSION_VALUE = "78.306";
58 protected Logger getLogger() {
63 protected String getServiceName() {
64 return DimensionClient.SERVICE_NAME;
68 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71 protected CollectionSpaceClient getClientInstance() {
72 return new DimensionClient();
76 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
77 return new DimensionClient(clientPropertiesFilename);
80 protected void compareInstances(DimensionsCommon original, DimensionsCommon updated) throws Exception {
81 Assert.assertEquals(original.getValueDate(),
82 updated.getValueDate(),
83 "Data in updated object did not match submitted data.");
87 protected DimensionsCommon updateInstance(DimensionsCommon dimensionsCommon) {
88 DimensionsCommon result = new DimensionsCommon();
90 // Update the content of this resource.
91 result.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
92 result.setValueDate("updated-" + dimensionsCommon.getValueDate());
97 // ---------------------------------------------------------------
98 // Utility methods used by tests above
99 // ---------------------------------------------------------------
101 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
104 public String getServicePathComponent() {
105 return DimensionClient.SERVICE_PATH_COMPONENT;
109 protected PoxPayloadOut createInstance(String identifier) {
110 DimensionClient client = new DimensionClient();
111 return createInstance(client.getCommonPartName(), identifier);
115 * Creates the dimension instance.
117 * @param identifier the identifier
118 * @return the multipart output
121 protected PoxPayloadOut createInstance(String commonPartName, String identifier) {
122 return createDimensionInstance(commonPartName,
123 "dimensionType-" + identifier,
125 "entryDate-" + identifier);
129 * Creates the dimension instance.
131 * @param dimensionType the dimension type
132 * @param entryNumber the entry number
133 * @param entryDate the entry date
134 * @return the multipart output
136 private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
137 DimensionsCommon dimensionsCommon = new DimensionsCommon();
138 dimensionsCommon.setDimension(dimensionType);
139 dimensionsCommon.setValue(new BigDecimal(dimensionValue));
140 dimensionsCommon.setValueDate(entryDate);
141 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
142 commonPartName, dimensionsCommon);
144 if (logger.isDebugEnabled()) {
145 logger.debug("to be created, dimension common");
146 logger.debug(objectAsXmlString(dimensionsCommon,
147 DimensionsCommon.class));
153 // Placeholders until the three tests below can be uncommented.
154 // See Issue CSPACE-401.
157 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
160 public void createWithMalformedXml(String testName) throws Exception {
161 //Should this really be empty?
165 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
168 public void createWithWrongXmlSchema(String testName) throws Exception {
169 //Should this really be empty?
173 public void createWithEmptyEntityBody(String testName) throws Exception {
174 //FIXME: Should this test really be empty?
177 public void updateWithEmptyEntityBody(String testName) throws Exception {
178 //Should this really be empty?
182 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
185 public void updateWithMalformedXml(String testName) throws Exception {
186 //Should this really be empty?
190 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
193 public void updateWithWrongXmlSchema(String testName) throws Exception {
194 //Should this really be empty?
198 protected void compareUpdatedInstances(DimensionsCommon original,
199 DimensionsCommon updated) throws Exception {
200 //Check the dimension value to see if the update happened correctly
201 BigDecimal expectedValue = original.getValue();
202 BigDecimal actualValue = updated.getValue();
203 Assert.assertTrue(actualValue.compareTo(expectedValue) == 0);
205 //Next, check the date value to see if it was updated
206 String expectedDate = original.getValueDate();
207 String actualDate = updated.getValueDate();
208 Assert.assertEquals(actualDate, expectedDate);
212 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
213 * refer to this method in their @Test annotation declarations.
216 @Test(dataProvider = "testName",
218 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
219 public void CRUDTests(String testName) {
220 // Do nothing. Simply here to for a TestNG execution order for our tests
225 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
226 dependsOnMethods = {"create", "testSubmitRequest"})
227 public void createWithEmptyEntityBody(String testName) throws Exception {
229 if (logger.isDebugEnabled()) {
230 logger.debug(testBanner(testName, CLASS_NAME));
233 setupCreateWithEmptyEntityBody(testName, logger);
235 // Submit the request to the service and store the response.
236 String method = REQUEST_TYPE.httpMethodName();
237 String url = getServiceRootURL();
238 String mediaType = MediaType.APPLICATION_XML;
239 final String entity = "";
240 int statusCode = submitRequest(method, url, mediaType, entity);
242 // Check the status code of the response: does it match
243 // the expected response(s)?
244 if(logger.isDebugEnabled()){
245 logger.debug("createWithEmptyEntityBody url=" + url +
246 " status=" + statusCode);
248 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
249 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
250 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
255 dependsOnMethods = {"create", "testSubmitRequest"})
256 public void createWithMalformedXml(String testName) throws Exception {
258 if (logger.isDebugEnabled()) {
259 logger.debug(testBanner(testName, CLASS_NAME));
262 setupCreateWithMalformedXml();
264 // Submit the request to the service and store the response.
265 String method = REQUEST_TYPE.httpMethodName();
266 String url = getServiceRootURL();
267 String mediaType = MediaType.APPLICATION_XML;
268 final String entity = MALFORMED_XML_DATA; // Constant from base class.
269 int statusCode = submitRequest(method, url, mediaType, entity);
271 // Check the status code of the response: does it match
272 // the expected response(s)?
273 if(logger.isDebugEnabled()){
274 logger.debug(testName + ": url=" + url +
275 " status=" + statusCode);
277 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
278 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
279 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
283 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
284 dependsOnMethods = {"create", "testSubmitRequest"})
285 public void createWithWrongXmlSchema(String testName) throws Exception {
287 if (logger.isDebugEnabled()) {
288 logger.debug(testBanner(testName, CLASS_NAME));
291 setupCreateWithWrongXmlSchema();
293 // Submit the request to the service and store the response.
294 String method = REQUEST_TYPE.httpMethodName();
295 String url = getServiceRootURL();
296 String mediaType = MediaType.APPLICATION_XML;
297 final String entity = WRONG_XML_SCHEMA_DATA;
298 int statusCode = submitRequest(method, url, mediaType, entity);
300 // Check the status code of the response: does it match
301 // the expected response(s)?
302 if(logger.isDebugEnabled()){
303 logger.debug(testName + ": url=" + url +
304 " status=" + statusCode);
306 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
307 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
308 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
313 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
314 dependsOnMethods = {"create", "update", "testSubmitRequest"})
315 public void updateWithEmptyEntityBody(String testName) throws Exception {
317 if (logger.isDebugEnabled()) {
318 logger.debug(testBanner(testName, CLASS_NAME));
321 setupUpdateWithEmptyEntityBody();
323 // Submit the request to the service and store the response.
324 String method = REQUEST_TYPE.httpMethodName();
325 String url = getResourceURL(knownResourceId);
326 String mediaType = MediaType.APPLICATION_XML;
327 final String entity = "";
328 int statusCode = submitRequest(method, url, mediaType, entity);
330 // Check the status code of the response: does it match
331 // the expected response(s)?
332 if(logger.isDebugEnabled()){
333 logger.debug(testName + ": url=" + url +
334 " status=" + statusCode);
336 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
337 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
338 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
342 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
343 dependsOnMethods = {"create", "update", "testSubmitRequest"})
344 public void updateWithMalformedXml(String testName) throws Exception {
346 if (logger.isDebugEnabled()) {
347 logger.debug(testBanner(testName, CLASS_NAME));
350 setupUpdateWithMalformedXml(testName, logger);
352 // Submit the request to the service and store the response.
353 String method = REQUEST_TYPE.httpMethodName();
354 String url = getResourceURL(knownResourceId);
355 String mediaType = MediaType.APPLICATION_XML;
356 final String entity = MALFORMED_XML_DATA;
357 int statusCode = submitRequest(method, url, mediaType, entity);
359 // Check the status code of the response: does it match
360 // the expected response(s)?
361 if(logger.isDebugEnabled()){
362 logger.debug(testName + ": url=" + url +
363 " status=" + statusCode);
365 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
371 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
372 dependsOnMethods = {"create", "update", "testSubmitRequest"})
373 public void updateWithWrongXmlSchema(String testName) throws Exception {
375 if (logger.isDebugEnabled()) {
376 logger.debug(testBanner(testName, CLASS_NAME));
379 setupUpdateWithWrongXmlSchema(testName, logger);
381 // Submit the request to the service and store the response.
382 String method = REQUEST_TYPE.httpMethodName();
383 String url = getResourceURL(knownResourceId);
384 String mediaType = MediaType.APPLICATION_XML;
385 final String entity = WRONG_XML_SCHEMA_DATA;
386 int statusCode = submitRequest(method, url, mediaType, entity);
388 // Check the status code of the response: does it match
389 // the expected response(s)?
390 if(logger.isDebugEnabled()){
391 logger.debug(testName + ": url=" + url +
392 " status=" + statusCode);
394 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);