]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
3958bd9194ec02de12d2ab3b43eb83a3cb6c03ca
[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.ArrayList;
26 import java.math.BigDecimal;
27
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;
34
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * DimensionServiceTest, carries out tests against a
42  * deployed and running Dimension Service.
43  *
44  * $LastChangedRevision: 917 $
45  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
46  */
47 public class DimensionServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, DimensionsCommon> {
48
49     /** The logger. */
50     private final String CLASS_NAME = DimensionServiceTest.class.getName();
51     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
52
53     // Instance variables specific to this test.
54     /** The SERVIC e_ pat h_ component. */
55     private final String DIMENSION_VALUE = "78.306";
56
57     @Override
58     protected Logger getLogger() {
59         return this.logger;
60     }
61     
62         @Override
63         protected String getServiceName() {
64                 return DimensionClient.SERVICE_NAME;
65         }
66     
67     /* (non-Javadoc)
68      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
69      */
70     @Override
71     protected CollectionSpaceClient getClientInstance() {
72         return new DimensionClient();
73     }
74
75         @Override
76         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
77         return new DimensionClient(clientPropertiesFilename);
78         }       
79     
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.");
84     }
85     
86     @Override
87     protected DimensionsCommon updateInstance(DimensionsCommon dimensionsCommon) {
88         DimensionsCommon result = new DimensionsCommon();
89         
90         // Update the content of this resource.
91         result.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
92         result.setValueDate("updated-" + dimensionsCommon.getValueDate());
93         
94         return result;
95     }
96     
97     // ---------------------------------------------------------------
98     // Utility methods used by tests above
99     // ---------------------------------------------------------------
100     /* (non-Javadoc)
101      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
102      */
103     @Override
104     public String getServicePathComponent() {
105         return DimensionClient.SERVICE_PATH_COMPONENT;
106     }
107
108     @Override
109     protected PoxPayloadOut createInstance(String identifier) {
110         DimensionClient client = new DimensionClient();
111         return createInstance(client.getCommonPartName(), identifier);
112     }
113     
114     /**
115      * Creates the dimension instance.
116      *
117      * @param identifier the identifier
118      * @return the multipart output
119      */
120     @Override
121     protected PoxPayloadOut createInstance(String commonPartName, String identifier) {
122         return createDimensionInstance(commonPartName, 
123                 "dimensionType-" + identifier,
124                 DIMENSION_VALUE,
125                 "entryDate-" + identifier);
126     }
127
128     /**
129      * Creates the dimension instance.
130      *
131      * @param dimensionType the dimension type
132      * @param entryNumber the entry number
133      * @param entryDate the entry date
134      * @return the multipart output
135      */
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);
143
144         if (logger.isDebugEnabled()) {
145             logger.debug("to be created, dimension common");
146             logger.debug(objectAsXmlString(dimensionsCommon,
147                     DimensionsCommon.class));
148         }
149
150         return multipart;
151     }
152             
153     // Placeholders until the three tests below can be uncommented.
154     // See Issue CSPACE-401.
155
156     /* (non-Javadoc)
157      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
158      */
159     @Override
160     public void createWithMalformedXml(String testName) throws Exception {
161         //Should this really be empty?
162     }
163
164     /* (non-Javadoc)
165      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
166      */
167     @Override
168     public void createWithWrongXmlSchema(String testName) throws Exception {
169         //Should this really be empty?
170     }
171     
172         @Override
173         public void createWithEmptyEntityBody(String testName) throws Exception {
174         //FIXME: Should this test really be empty?
175         }
176     @Override
177     public void updateWithEmptyEntityBody(String testName) throws Exception {
178         //Should this really be empty?
179     }
180
181     /* (non-Javadoc)
182      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
183      */
184     @Override
185     public void updateWithMalformedXml(String testName) throws Exception {
186         //Should this really be empty?
187     }
188
189     /* (non-Javadoc)
190      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
191      */
192     @Override
193     public void updateWithWrongXmlSchema(String testName) throws Exception {
194         //Should this really be empty?
195     }
196
197         @Override
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);
204                 
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);
209         }
210
211     /*
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.
214      */
215     @Override
216     @Test(dataProvider = "testName",
217                 dependsOnMethods = {
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
221     }
222
223     /*
224     @Override
225     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
226     dependsOnMethods = {"create", "testSubmitRequest"})
227     public void createWithEmptyEntityBody(String testName) throws Exception {
228
229         if (logger.isDebugEnabled()) {
230             logger.debug(testBanner(testName, CLASS_NAME));
231         }
232         // Perform setup.
233         setupCreateWithEmptyEntityBody(testName, logger);
234
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);
241
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);
247         }
248         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
249         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
250         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
251     }
252
253     @Override
254     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
255     dependsOnMethods = {"create", "testSubmitRequest"})
256     public void createWithMalformedXml(String testName) throws Exception {
257
258         if (logger.isDebugEnabled()) {
259             logger.debug(testBanner(testName, CLASS_NAME));
260         }
261         // Perform setup.
262         setupCreateWithMalformedXml();
263
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);
270
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);
276         }
277         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
278         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
279         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
280     }
281
282     @Override
283     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
284     dependsOnMethods = {"create", "testSubmitRequest"})
285     public void createWithWrongXmlSchema(String testName) throws Exception {
286
287         if (logger.isDebugEnabled()) {
288             logger.debug(testBanner(testName, CLASS_NAME));
289         }
290         // Perform setup.
291         setupCreateWithWrongXmlSchema();
292
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);
299
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);
305         }
306         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
307         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
308         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
309     }
310 */    
311     /*
312     @Override
313     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
314     dependsOnMethods = {"create", "update", "testSubmitRequest"})
315     public void updateWithEmptyEntityBody(String testName) throws Exception {
316
317         if (logger.isDebugEnabled()) {
318             logger.debug(testBanner(testName, CLASS_NAME));
319         }
320         // Perform setup.
321         setupUpdateWithEmptyEntityBody();
322
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);
329
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);
335         }
336         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
337         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
338         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
339     }
340
341     @Override
342     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
343     dependsOnMethods = {"create", "update", "testSubmitRequest"})
344     public void updateWithMalformedXml(String testName) throws Exception {
345
346         if (logger.isDebugEnabled()) {
347             logger.debug(testBanner(testName, CLASS_NAME));
348         }
349         // Perform setup.
350         setupUpdateWithMalformedXml(testName, logger);
351
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);
358
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);
364         }
365         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
368     }
369
370     @Override
371     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
372     dependsOnMethods = {"create", "update", "testSubmitRequest"})
373     public void updateWithWrongXmlSchema(String testName) throws Exception {
374
375         if (logger.isDebugEnabled()) {
376             logger.debug(testBanner(testName, CLASS_NAME));
377         }
378         // Perform setup.
379         setupUpdateWithWrongXmlSchema(testName, logger);
380
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);
387
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);
393         }
394         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
397     }
398 */
399 }