]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b7c8b226626f23f5e234ca531475775de6dc7677
[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 import java.util.List;
28
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.DimensionClient;
31 import org.collectionspace.services.client.DimensionFactory;
32 import org.collectionspace.services.client.PoxPayloadOut;
33 import org.collectionspace.services.dimension.DimensionsCommon;
34 import org.collectionspace.services.dimension.DimensionsCommonList;
35
36 import org.testng.Assert;
37 //import org.testng.annotations.AfterClass;
38 import org.testng.annotations.Test;
39
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * DimensionServiceTest, carries out tests against a
45  * deployed and running Dimension Service.
46  *
47  * $LastChangedRevision: 917 $
48  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
49  */
50 public class DimensionServiceTest extends AbstractPoxServiceTestImpl<DimensionsCommonList, DimensionsCommon> {
51
52     /** The logger. */
53     private final String CLASS_NAME = DimensionServiceTest.class.getName();
54     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
55
56     // Instance variables specific to this test.
57     /** The SERVIC e_ pat h_ component. */
58     private final String DIMENSION_VALUE = "78.306";
59
60     @Override
61     protected Logger getLogger() {
62         return this.logger;
63     }
64     
65         @Override
66         protected String getServiceName() {
67                 return DimensionClient.SERVICE_NAME;
68         }
69     
70     /* (non-Javadoc)
71      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
72      */
73     @Override
74     protected CollectionSpaceClient getClientInstance() {
75         return new DimensionClient();
76     }
77
78     @Override
79     protected Class<DimensionsCommonList> getCommonListType() {
80         return DimensionsCommonList.class;
81     }
82
83     /*
84      * This method gets called by the parent's method public void readList(String testName)
85      */
86     protected void printList(String testName, DimensionsCommonList list) {
87         // Optionally output additional data about list members for debugging.
88         boolean iterateThroughList = false;
89         if (iterateThroughList && logger.isDebugEnabled()) {
90             List<DimensionsCommonList.DimensionListItem> items =
91                     list.getDimensionListItem();
92             int i = 0;
93             for (DimensionsCommonList.DimensionListItem item : items) {
94                 logger.debug(testName + ": list-item[" + i + "] csid="
95                         + item.getCsid());
96                 logger.debug(testName + ": list-item[" + i + "] objectNumber="
97                         + item.getDimension());
98                 logger.debug(testName + ": list-item[" + i + "] URI="
99                         + item.getUri());
100                 i++;
101             }
102         }
103     }
104     
105     protected void compareInstances(DimensionsCommon original, DimensionsCommon updated) throws Exception {
106         Assert.assertEquals(original.getValueDate(),
107                         updated.getValueDate(),
108                 "Data in updated object did not match submitted data.");
109     }
110     
111     @Override
112     protected DimensionsCommon updateInstance(DimensionsCommon dimensionsCommon) {
113         DimensionsCommon result = new DimensionsCommon();
114         
115         // Update the content of this resource.
116         result.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
117         result.setValueDate("updated-" + dimensionsCommon.getValueDate());
118         
119         return result;
120     }
121     
122     // ---------------------------------------------------------------
123     // Utility methods used by tests above
124     // ---------------------------------------------------------------
125     /* (non-Javadoc)
126      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
127      */
128     @Override
129     public String getServicePathComponent() {
130         return DimensionClient.SERVICE_PATH_COMPONENT;
131     }
132
133     @Override
134     protected PoxPayloadOut createInstance(String identifier) {
135         DimensionClient client = new DimensionClient();
136         return createInstance(client.getCommonPartName(), identifier);
137     }
138     
139     /**
140      * Creates the dimension instance.
141      *
142      * @param identifier the identifier
143      * @return the multipart output
144      */
145     @Override
146     protected PoxPayloadOut createInstance(String commonPartName, String identifier) {
147         return createDimensionInstance(commonPartName, 
148                 "dimensionType-" + identifier,
149                 DIMENSION_VALUE,
150                 "entryDate-" + identifier);
151     }
152
153     /**
154      * Creates the dimension instance.
155      *
156      * @param dimensionType the dimension type
157      * @param entryNumber the entry number
158      * @param entryDate the entry date
159      * @return the multipart output
160      */
161     private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
162         DimensionsCommon dimensionsCommon = new DimensionsCommon();
163         dimensionsCommon.setDimension(dimensionType);
164         dimensionsCommon.setValue(new BigDecimal(dimensionValue));
165         dimensionsCommon.setValueDate(entryDate);
166         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
167                 commonPartName, dimensionsCommon);
168
169         if (logger.isDebugEnabled()) {
170             logger.debug("to be created, dimension common");
171             logger.debug(objectAsXmlString(dimensionsCommon,
172                     DimensionsCommon.class));
173         }
174
175         return multipart;
176     }
177             
178     // Placeholders until the three tests below can be uncommented.
179     // See Issue CSPACE-401.
180
181     /* (non-Javadoc)
182      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
183      */
184     @Override
185     public void createWithMalformedXml(String testName) throws Exception {
186         //Should this really be empty?
187     }
188
189     /* (non-Javadoc)
190      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
191      */
192     @Override
193     public void createWithWrongXmlSchema(String testName) throws Exception {
194         //Should this really be empty?
195     }
196     
197         @Override
198         public void createWithEmptyEntityBody(String testName) throws Exception {
199         //FIXME: Should this test really be empty?
200         }
201     @Override
202     public void updateWithEmptyEntityBody(String testName) throws Exception {
203         //Should this really be empty?
204     }
205
206     /* (non-Javadoc)
207      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
208      */
209     @Override
210     public void updateWithMalformedXml(String testName) throws Exception {
211         //Should this really be empty?
212     }
213
214     /* (non-Javadoc)
215      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
216      */
217     @Override
218     public void updateWithWrongXmlSchema(String testName) throws Exception {
219         //Should this really be empty?
220     }
221
222         @Override
223         protected void compareUpdatedInstances(DimensionsCommon original,
224                         DimensionsCommon updated) throws Exception {
225                 //Check the dimension value to see if the update happened correctly
226                 BigDecimal expectedValue = original.getValue();
227                 BigDecimal actualValue = updated.getValue();
228                 Assert.assertTrue(actualValue.compareTo(expectedValue) == 0);
229                 
230                 //Next, check the date value to see if it was updated
231                 String expectedDate = original.getValueDate();
232                 String actualDate = updated.getValueDate();
233                 Assert.assertEquals(actualDate, expectedDate);
234         }
235
236     /*
237      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
238      * refer to this method in their @Test annotation declarations.
239      */
240     @Override
241     @Test(dataProvider = "testName",
242                 dependsOnMethods = {
243                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
244     public void CRUDTests(String testName) {
245         // Do nothing.  Simply here to for a TestNG execution order for our tests
246     }   
247
248     /*
249     @Override
250     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
251     dependsOnMethods = {"create", "testSubmitRequest"})
252     public void createWithEmptyEntityBody(String testName) throws Exception {
253
254         if (logger.isDebugEnabled()) {
255             logger.debug(testBanner(testName, CLASS_NAME));
256         }
257         // Perform setup.
258         setupCreateWithEmptyEntityBody(testName, logger);
259
260         // Submit the request to the service and store the response.
261         String method = REQUEST_TYPE.httpMethodName();
262         String url = getServiceRootURL();
263         String mediaType = MediaType.APPLICATION_XML;
264         final String entity = "";
265         int statusCode = submitRequest(method, url, mediaType, entity);
266
267         // Check the status code of the response: does it match
268         // the expected response(s)?
269         if(logger.isDebugEnabled()){
270         logger.debug("createWithEmptyEntityBody url=" + url +
271         " status=" + statusCode);
272         }
273         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
274         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
275         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276     }
277
278     @Override
279     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
280     dependsOnMethods = {"create", "testSubmitRequest"})
281     public void createWithMalformedXml(String testName) throws Exception {
282
283         if (logger.isDebugEnabled()) {
284             logger.debug(testBanner(testName, CLASS_NAME));
285         }
286         // Perform setup.
287         setupCreateWithMalformedXml();
288
289         // Submit the request to the service and store the response.
290         String method = REQUEST_TYPE.httpMethodName();
291         String url = getServiceRootURL();
292         String mediaType = MediaType.APPLICATION_XML;
293         final String entity = MALFORMED_XML_DATA; // Constant from base class.
294         int statusCode = submitRequest(method, url, mediaType, entity);
295
296         // Check the status code of the response: does it match
297         // the expected response(s)?
298         if(logger.isDebugEnabled()){
299         logger.debug(testName + ": url=" + url +
300         " status=" + statusCode);
301         }
302         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
303         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
304         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
305     }
306
307     @Override
308     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
309     dependsOnMethods = {"create", "testSubmitRequest"})
310     public void createWithWrongXmlSchema(String testName) throws Exception {
311
312         if (logger.isDebugEnabled()) {
313             logger.debug(testBanner(testName, CLASS_NAME));
314         }
315         // Perform setup.
316         setupCreateWithWrongXmlSchema();
317
318         // Submit the request to the service and store the response.
319         String method = REQUEST_TYPE.httpMethodName();
320         String url = getServiceRootURL();
321         String mediaType = MediaType.APPLICATION_XML;
322         final String entity = WRONG_XML_SCHEMA_DATA;
323         int statusCode = submitRequest(method, url, mediaType, entity);
324
325         // Check the status code of the response: does it match
326         // the expected response(s)?
327         if(logger.isDebugEnabled()){
328         logger.debug(testName + ": url=" + url +
329         " status=" + statusCode);
330         }
331         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
332         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
333         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
334     }
335 */    
336     /*
337     @Override
338     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
339     dependsOnMethods = {"create", "update", "testSubmitRequest"})
340     public void updateWithEmptyEntityBody(String testName) throws Exception {
341
342         if (logger.isDebugEnabled()) {
343             logger.debug(testBanner(testName, CLASS_NAME));
344         }
345         // Perform setup.
346         setupUpdateWithEmptyEntityBody();
347
348         // Submit the request to the service and store the response.
349         String method = REQUEST_TYPE.httpMethodName();
350         String url = getResourceURL(knownResourceId);
351         String mediaType = MediaType.APPLICATION_XML;
352         final String entity = "";
353         int statusCode = submitRequest(method, url, mediaType, entity);
354
355         // Check the status code of the response: does it match
356         // the expected response(s)?
357         if(logger.isDebugEnabled()){
358         logger.debug(testName + ": url=" + url +
359         " status=" + statusCode);
360         }
361         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
362         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
363         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
364     }
365
366     @Override
367     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
368     dependsOnMethods = {"create", "update", "testSubmitRequest"})
369     public void updateWithMalformedXml(String testName) throws Exception {
370
371         if (logger.isDebugEnabled()) {
372             logger.debug(testBanner(testName, CLASS_NAME));
373         }
374         // Perform setup.
375         setupUpdateWithMalformedXml(testName, logger);
376
377         // Submit the request to the service and store the response.
378         String method = REQUEST_TYPE.httpMethodName();
379         String url = getResourceURL(knownResourceId);
380         String mediaType = MediaType.APPLICATION_XML;
381         final String entity = MALFORMED_XML_DATA;
382         int statusCode = submitRequest(method, url, mediaType, entity);
383
384         // Check the status code of the response: does it match
385         // the expected response(s)?
386         if(logger.isDebugEnabled()){
387         logger.debug(testName + ": url=" + url +
388         " status=" + statusCode);
389         }
390         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
391         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
392         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
393     }
394
395     @Override
396     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
397     dependsOnMethods = {"create", "update", "testSubmitRequest"})
398     public void updateWithWrongXmlSchema(String testName) throws Exception {
399
400         if (logger.isDebugEnabled()) {
401             logger.debug(testBanner(testName, CLASS_NAME));
402         }
403         // Perform setup.
404         setupUpdateWithWrongXmlSchema(testName, logger);
405
406         // Submit the request to the service and store the response.
407         String method = REQUEST_TYPE.httpMethodName();
408         String url = getResourceURL(knownResourceId);
409         String mediaType = MediaType.APPLICATION_XML;
410         final String entity = WRONG_XML_SCHEMA_DATA;
411         int statusCode = submitRequest(method, url, mediaType, entity);
412
413         // Check the status code of the response: does it match
414         // the expected response(s)?
415         if(logger.isDebugEnabled()){
416         logger.debug(testName + ": url=" + url +
417         " status=" + statusCode);
418         }
419         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
420         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
421         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
422     }
423 */
424 }