]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
866dff8ee558abc80c258c5fe7b24aee48e93b87
[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 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.DimensionClient;
33 import org.collectionspace.services.client.DimensionFactory;
34 import org.collectionspace.services.client.PayloadInputPart;
35 import org.collectionspace.services.client.PayloadOutputPart;
36 import org.collectionspace.services.client.PoxPayloadIn;
37 import org.collectionspace.services.client.PoxPayloadOut;
38 import org.collectionspace.services.client.workflow.WorkflowClient;
39 import org.collectionspace.services.dimension.DimensionsCommon;
40 import org.collectionspace.services.dimension.DimensionsCommonList;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.workflow.WorkflowCommon;
43
44 import org.jboss.resteasy.client.ClientResponse;
45
46 import org.testng.Assert;
47 //import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
49
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52
53 /**
54  * DimensionServiceTest, carries out tests against a
55  * deployed and running Dimension Service.
56  *
57  * $LastChangedRevision: 917 $
58  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
59  */
60 public class DimensionServiceTest extends AbstractServiceTestImpl {
61
62     /** The logger. */
63     private final String CLASS_NAME = DimensionServiceTest.class.getName();
64     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
65
66     // Instance variables specific to this test.
67     /** The SERVIC e_ pat h_ component. */
68     /** The known resource id. */
69     private String knownResourceId = null;
70     private final String DIMENSION_VALUE = "78.306";
71
72         @Override
73         protected String getServiceName() {
74                 return DimensionClient.SERVICE_NAME;
75         }
76     
77     /* (non-Javadoc)
78      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79      */
80     @Override
81     protected CollectionSpaceClient getClientInstance() {
82         return new DimensionClient();
83     }
84
85     /* (non-Javadoc)
86      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
87      */
88     @Override
89     protected AbstractCommonList getAbstractCommonList(
90             ClientResponse<AbstractCommonList> response) {
91         return response.getEntity(DimensionsCommonList.class);
92     }
93
94     // ---------------------------------------------------------------
95     // CRUD tests : CREATE tests
96     // ---------------------------------------------------------------
97     // Success outcomes
98     /* (non-Javadoc)
99      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100      */
101     @Override
102     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
103     public void create(String testName) throws Exception {
104
105         if (logger.isDebugEnabled()) {
106             logger.debug(testBanner(testName, CLASS_NAME));
107         }
108         // Perform setup, such as initializing the type of service request
109         // (e.g. CREATE, DELETE), its valid and expected status codes, and
110         // its associated HTTP method name (e.g. POST, DELETE).
111         setupCreate();
112
113         // Submit the request to the service and store the response.
114         DimensionClient client = new DimensionClient();
115         String identifier = createIdentifier();
116         PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
117                 identifier);
118         ClientResponse<Response> res = client.create(multipart);
119
120         int statusCode = res.getStatus();
121
122         // Check the status code of the response: does it match
123         // the expected response(s)?
124         //
125         // Specifically:
126         // Does it fall within the set of valid status codes?
127         // Does it exactly match the expected status code?
128         if (logger.isDebugEnabled()) {
129             logger.debug(testName + ": status = " + statusCode);
130         }
131         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
132                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
133         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
134
135         // Store the ID returned from the first resource created
136         // for additional tests below.
137         if (knownResourceId == null) {
138             knownResourceId = extractId(res);
139             if (logger.isDebugEnabled()) {
140                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
141             }
142         }
143
144         // Store the IDs from every resource created by tests,
145         // so they can be deleted after tests have been run.
146         allResourceIdsCreated.add(extractId(res));
147     }
148
149     /* (non-Javadoc)
150      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
151      */
152     @Override
153     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
154     dependsOnMethods = {"create"})
155     public void createList(String testName) throws Exception {
156         for (int i = 0; i < 3; i++) {
157             create(testName);
158         }
159     }
160
161     // Failure outcomes
162     // Placeholders until the three tests below can be uncommented.
163     // See Issue CSPACE-401.
164     /* (non-Javadoc)
165      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
166      */
167     @Override
168     public void createWithEmptyEntityBody(String testName) throws Exception {
169         //Should this really be empty?
170     }
171
172     /* (non-Javadoc)
173      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
174      */
175     @Override
176     public void createWithMalformedXml(String testName) throws Exception {
177         //Should this really be empty?
178     }
179
180     /* (non-Javadoc)
181      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
182      */
183     @Override
184     public void createWithWrongXmlSchema(String testName) throws Exception {
185         //Should this really be empty?
186     }
187
188     /*
189     @Override
190     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
191     dependsOnMethods = {"create", "testSubmitRequest"})
192     public void createWithEmptyEntityBody(String testName) throws Exception {
193
194         if (logger.isDebugEnabled()) {
195             logger.debug(testBanner(testName, CLASS_NAME));
196         }
197         // Perform setup.
198         setupCreateWithEmptyEntityBody(testName, logger);
199
200         // Submit the request to the service and store the response.
201         String method = REQUEST_TYPE.httpMethodName();
202         String url = getServiceRootURL();
203         String mediaType = MediaType.APPLICATION_XML;
204         final String entity = "";
205         int statusCode = submitRequest(method, url, mediaType, entity);
206
207         // Check the status code of the response: does it match
208         // the expected response(s)?
209         if(logger.isDebugEnabled()){
210         logger.debug("createWithEmptyEntityBody url=" + url +
211         " status=" + statusCode);
212         }
213         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
216     }
217
218     @Override
219     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
220     dependsOnMethods = {"create", "testSubmitRequest"})
221     public void createWithMalformedXml(String testName) throws Exception {
222
223         if (logger.isDebugEnabled()) {
224             logger.debug(testBanner(testName, CLASS_NAME));
225         }
226         // Perform setup.
227         setupCreateWithMalformedXml();
228
229         // Submit the request to the service and store the response.
230         String method = REQUEST_TYPE.httpMethodName();
231         String url = getServiceRootURL();
232         String mediaType = MediaType.APPLICATION_XML;
233         final String entity = MALFORMED_XML_DATA; // Constant from base class.
234         int statusCode = submitRequest(method, url, mediaType, entity);
235
236         // Check the status code of the response: does it match
237         // the expected response(s)?
238         if(logger.isDebugEnabled()){
239         logger.debug(testName + ": url=" + url +
240         " status=" + statusCode);
241         }
242         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
243         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
244         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
245     }
246
247     @Override
248     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
249     dependsOnMethods = {"create", "testSubmitRequest"})
250     public void createWithWrongXmlSchema(String testName) throws Exception {
251
252         if (logger.isDebugEnabled()) {
253             logger.debug(testBanner(testName, CLASS_NAME));
254         }
255         // Perform setup.
256         setupCreateWithWrongXmlSchema();
257
258         // Submit the request to the service and store the response.
259         String method = REQUEST_TYPE.httpMethodName();
260         String url = getServiceRootURL();
261         String mediaType = MediaType.APPLICATION_XML;
262         final String entity = WRONG_XML_SCHEMA_DATA;
263         int statusCode = submitRequest(method, url, mediaType, entity);
264
265         // Check the status code of the response: does it match
266         // the expected response(s)?
267         if(logger.isDebugEnabled()){
268         logger.debug(testName + ": url=" + url +
269         " status=" + statusCode);
270         }
271         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
272         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
273         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
274     }
275      */
276     // ---------------------------------------------------------------
277     // CRUD tests : READ tests
278     // ---------------------------------------------------------------
279     // Success outcomes
280     /* (non-Javadoc)
281      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
282      */
283     @Override
284     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
285     dependsOnMethods = {"create"})
286     public void read(String testName) throws Exception {
287
288         if (logger.isDebugEnabled()) {
289             logger.debug(testBanner(testName, CLASS_NAME));
290         }
291         // Perform setup.
292         setupRead();
293
294         // Submit the request to the service and store the response.
295         DimensionClient client = new DimensionClient();
296         ClientResponse<String> res = client.read(knownResourceId);
297         int statusCode = res.getStatus();
298
299         // Check the status code of the response: does it match
300         // the expected response(s)?
301         if (logger.isDebugEnabled()) {
302             logger.debug(testName + ": status = " + statusCode);
303         }
304         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
305                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
306         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
307
308         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
309         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
310         DimensionsCommon dimensionsCommon = null;
311         if (payloadInputPart != null) {
312                 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
313         }
314         Assert.assertNotNull(dimensionsCommon);
315     }
316
317     // Failure outcomes
318     /* (non-Javadoc)
319      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
320      */
321     @Override
322     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
323     dependsOnMethods = {"read"})
324     public void readNonExistent(String testName) throws Exception {
325
326         if (logger.isDebugEnabled()) {
327             logger.debug(testBanner(testName, CLASS_NAME));
328         }
329         // Perform setup.
330         setupReadNonExistent();
331
332         // Submit the request to the service and store the response.
333         DimensionClient client = new DimensionClient();
334         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
335         int statusCode = res.getStatus();
336
337         // Check the status code of the response: does it match
338         // the expected response(s)?
339         if (logger.isDebugEnabled()) {
340             logger.debug(testName + ": status = " + statusCode);
341         }
342         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
343                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
344         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
345     }
346
347     // ---------------------------------------------------------------
348     // CRUD tests : READ_LIST tests
349     // ---------------------------------------------------------------
350     // Success outcomes
351     /* (non-Javadoc)
352      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
353      */
354     @Override
355     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
356     dependsOnMethods = {"read"})
357     public void readList(String testName) throws Exception {
358
359         if (logger.isDebugEnabled()) {
360             logger.debug(testBanner(testName, CLASS_NAME));
361         }
362         // Perform setup.
363         setupReadList();
364
365         // Submit the request to the service and store the response.
366         DimensionClient client = new DimensionClient();
367         ClientResponse<DimensionsCommonList> res = client.readList();
368         DimensionsCommonList list = res.getEntity();
369         int statusCode = res.getStatus();
370
371         // Check the status code of the response: does it match
372         // the expected response(s)?
373         if (logger.isDebugEnabled()) {
374             logger.debug(testName + ": status = " + statusCode);
375         }
376         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
379
380         // Optionally output additional data about list members for debugging.
381         boolean iterateThroughList = false;
382         if (iterateThroughList && logger.isDebugEnabled()) {
383             List<DimensionsCommonList.DimensionListItem> items =
384                     list.getDimensionListItem();
385             int i = 0;
386             for (DimensionsCommonList.DimensionListItem item : items) {
387                 logger.debug(testName + ": list-item[" + i + "] csid="
388                         + item.getCsid());
389                 logger.debug(testName + ": list-item[" + i + "] objectNumber="
390                         + item.getDimension());
391                 logger.debug(testName + ": list-item[" + i + "] URI="
392                         + item.getUri());
393                 i++;
394             }
395         }
396
397     }
398
399     // Failure outcomes
400     // None at present.
401     // ---------------------------------------------------------------
402     // CRUD tests : UPDATE tests
403     // ---------------------------------------------------------------
404     // Success outcomes
405     /* (non-Javadoc)
406      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
407      */
408     @Override
409     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
410     dependsOnMethods = {"read"})
411     public void update(String testName) throws Exception {
412
413         if (logger.isDebugEnabled()) {
414             logger.debug(testBanner(testName, CLASS_NAME));
415         }
416         // Perform setup.
417         setupUpdate();
418
419         // Retrieve the contents of a resource to update.
420         DimensionClient client = new DimensionClient();
421         ClientResponse<String> res =
422                 client.read(knownResourceId);
423         if (logger.isDebugEnabled()) {
424             logger.debug(testName + ": read status = " + res.getStatus());
425         }
426         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
427
428         if (logger.isDebugEnabled()) {
429             logger.debug("got object to update with ID: " + knownResourceId);
430         }
431         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
432         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
433         DimensionsCommon dimensionsCommon = null;
434         if (payloadInputPart != null) {
435                 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
436         }
437         Assert.assertNotNull(dimensionsCommon);
438
439         // Update the content of this resource.
440         dimensionsCommon.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
441         dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate());
442         if (logger.isDebugEnabled()) {
443             logger.debug("to be updated object");
444             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
445         }
446         // Submit the request to the service and store the response.
447         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
448         PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE);
449         commonPart.setLabel(client.getCommonPartName());
450
451         res = client.update(knownResourceId, output);
452         int statusCode = res.getStatus();
453         // Check the status code of the response: does it match the expected response(s)?
454         if (logger.isDebugEnabled()) {
455             logger.debug(testName + ": status = " + statusCode);
456         }
457         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
458                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
459         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
460
461         input = new PoxPayloadIn(res.getEntity());
462         DimensionsCommon updatedDimensionsCommon =
463                 (DimensionsCommon) extractPart(input,
464                 client.getCommonPartName(), DimensionsCommon.class);
465         Assert.assertNotNull(updatedDimensionsCommon);
466
467         Assert.assertEquals(updatedDimensionsCommon.getValueDate(),
468                 dimensionsCommon.getValueDate(),
469                 "Data in updated object did not match submitted data.");
470
471     }
472
473     // Failure outcomes
474     // Placeholders until the three tests below can be uncommented.
475     // See Issue CSPACE-401.
476     /* (non-Javadoc)
477      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
478      */
479     @Override
480     public void updateWithEmptyEntityBody(String testName) throws Exception {
481         //Should this really be empty?
482     }
483
484     /* (non-Javadoc)
485      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
486      */
487     @Override
488     public void updateWithMalformedXml(String testName) throws Exception {
489         //Should this really be empty?
490     }
491
492     /* (non-Javadoc)
493      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
494      */
495     @Override
496     public void updateWithWrongXmlSchema(String testName) throws Exception {
497         //Should this really be empty?
498     }
499
500     /*
501     @Override
502     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
503     dependsOnMethods = {"create", "update", "testSubmitRequest"})
504     public void updateWithEmptyEntityBody(String testName) throws Exception {
505
506         if (logger.isDebugEnabled()) {
507             logger.debug(testBanner(testName, CLASS_NAME));
508         }
509         // Perform setup.
510         setupUpdateWithEmptyEntityBody();
511
512         // Submit the request to the service and store the response.
513         String method = REQUEST_TYPE.httpMethodName();
514         String url = getResourceURL(knownResourceId);
515         String mediaType = MediaType.APPLICATION_XML;
516         final String entity = "";
517         int statusCode = submitRequest(method, url, mediaType, entity);
518
519         // Check the status code of the response: does it match
520         // the expected response(s)?
521         if(logger.isDebugEnabled()){
522         logger.debug(testName + ": url=" + url +
523         " status=" + statusCode);
524         }
525         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
526         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
527         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
528     }
529
530     @Override
531     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
532     dependsOnMethods = {"create", "update", "testSubmitRequest"})
533     public void updateWithMalformedXml(String testName) throws Exception {
534
535         if (logger.isDebugEnabled()) {
536             logger.debug(testBanner(testName, CLASS_NAME));
537         }
538         // Perform setup.
539         setupUpdateWithMalformedXml(testName, logger);
540
541         // Submit the request to the service and store the response.
542         String method = REQUEST_TYPE.httpMethodName();
543         String url = getResourceURL(knownResourceId);
544         String mediaType = MediaType.APPLICATION_XML;
545         final String entity = MALFORMED_XML_DATA;
546         int statusCode = submitRequest(method, url, mediaType, entity);
547
548         // Check the status code of the response: does it match
549         // the expected response(s)?
550         if(logger.isDebugEnabled()){
551         logger.debug(testName + ": url=" + url +
552         " status=" + statusCode);
553         }
554         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
557     }
558
559     @Override
560     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
561     dependsOnMethods = {"create", "update", "testSubmitRequest"})
562     public void updateWithWrongXmlSchema(String testName) throws Exception {
563
564         if (logger.isDebugEnabled()) {
565             logger.debug(testBanner(testName, CLASS_NAME));
566         }
567         // Perform setup.
568         setupUpdateWithWrongXmlSchema(testName, logger);
569
570         // Submit the request to the service and store the response.
571         String method = REQUEST_TYPE.httpMethodName();
572         String url = getResourceURL(knownResourceId);
573         String mediaType = MediaType.APPLICATION_XML;
574         final String entity = WRONG_XML_SCHEMA_DATA;
575         int statusCode = submitRequest(method, url, mediaType, entity);
576
577         // Check the status code of the response: does it match
578         // the expected response(s)?
579         if(logger.isDebugEnabled()){
580         logger.debug(testName + ": url=" + url +
581         " status=" + statusCode);
582         }
583         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
584         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
585         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
586     }
587      */
588
589     /* (non-Javadoc)
590      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
591      */
592     @Override
593     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
594     dependsOnMethods = {"update", "testSubmitRequest"})
595     public void updateNonExistent(String testName) throws Exception {
596
597         if (logger.isDebugEnabled()) {
598             logger.debug(testBanner(testName, CLASS_NAME));
599         }
600         // Perform setup.
601         setupUpdateNonExistent();
602
603         // Submit the request to the service and store the response.
604         // Note: The ID used in this 'create' call may be arbitrary.
605         // The only relevant ID may be the one used in update(), below.
606         DimensionClient client = new DimensionClient();
607         PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
608                 NON_EXISTENT_ID);
609         ClientResponse<String> res =
610                 client.update(NON_EXISTENT_ID, multipart);
611         int statusCode = res.getStatus();
612
613         // Check the status code of the response: does it match
614         // the expected response(s)?
615         if (logger.isDebugEnabled()) {
616             logger.debug(testName + ": status = " + statusCode);
617         }
618         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
619                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
620         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
621     }
622
623     // ---------------------------------------------------------------
624     // CRUD tests : DELETE tests
625     // ---------------------------------------------------------------
626     // Success outcomes
627     /* (non-Javadoc)
628      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
629      */
630     @Override
631     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
632     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "readWorkflow"})
633     public void delete(String testName) throws Exception {
634
635         if (logger.isDebugEnabled()) {
636             logger.debug(testBanner(testName, CLASS_NAME));
637         }
638         // Perform setup.
639         setupDelete();
640
641         // Submit the request to the service and store the response.
642         DimensionClient client = new DimensionClient();
643         ClientResponse<Response> res = client.delete(knownResourceId);
644         int statusCode = res.getStatus();
645
646         // Check the status code of the response: does it match
647         // the expected response(s)?
648         if (logger.isDebugEnabled()) {
649             logger.debug(testName + ": status = " + statusCode);
650         }
651         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
654     }
655
656     // Failure outcomes
657     /* (non-Javadoc)
658      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
659      */
660     @Override
661     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
662     dependsOnMethods = {"delete"})
663     public void deleteNonExistent(String testName) throws Exception {
664
665         if (logger.isDebugEnabled()) {
666             logger.debug(testBanner(testName, CLASS_NAME));
667         }
668         // Perform setup.
669         setupDeleteNonExistent();
670
671         // Submit the request to the service and store the response.
672         DimensionClient client = new DimensionClient();
673         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
674         int statusCode = res.getStatus();
675
676         // Check the status code of the response: does it match
677         // the expected response(s)?
678         if (logger.isDebugEnabled()) {
679             logger.debug(testName + ": status = " + statusCode);
680         }
681         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
682                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
683         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
684     }
685     
686     // ---------------------------------------------------------------
687     // Search tests
688     // ---------------------------------------------------------------
689     
690     @Override
691     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
692     public void searchWorkflowDeleted(String testName) throws Exception {
693         // Fixme: null test for now, overriding test in base class
694     }
695
696     // ---------------------------------------------------------------
697     // Utility tests : tests of code used in tests above
698     // ---------------------------------------------------------------
699     /**
700      * Tests the code for manually submitting data that is used by several
701      * of the methods above.
702      */
703     @Test(dependsOnMethods = {"create", "read"})
704     public void testSubmitRequest() {
705
706         // Expected status code: 200 OK
707         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
708
709         // Submit the request to the service and store the response.
710         String method = ServiceRequestType.READ.httpMethodName();
711         String url = getResourceURL(knownResourceId);
712         int statusCode = submitRequest(method, url);
713
714         // Check the status code of the response: does it match
715         // the expected response(s)?
716         if (logger.isDebugEnabled()) {
717             logger.debug("testSubmitRequest: url=" + url
718                     + " status=" + statusCode);
719         }
720         Assert.assertEquals(statusCode, EXPECTED_STATUS);
721
722     }
723
724     // ---------------------------------------------------------------
725     // Utility methods used by tests above
726     // ---------------------------------------------------------------
727     /* (non-Javadoc)
728      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
729      */
730     @Override
731     public String getServicePathComponent() {
732         return DimensionClient.SERVICE_PATH_COMPONENT;
733     }
734
735     @Override
736     protected PoxPayloadOut createInstance(String identifier) {
737         DimensionClient client = new DimensionClient();
738         return createDimensionInstance(client.getCommonPartName(), identifier);
739     }
740     
741     /**
742      * Creates the dimension instance.
743      *
744      * @param identifier the identifier
745      * @return the multipart output
746      */
747     private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
748         return createDimensionInstance(commonPartName, 
749                 "dimensionType-" + identifier,
750                 DIMENSION_VALUE,
751                 "entryDate-" + identifier);
752     }
753
754     /**
755      * Creates the dimension instance.
756      *
757      * @param dimensionType the dimension type
758      * @param entryNumber the entry number
759      * @param entryDate the entry date
760      * @return the multipart output
761      */
762     private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
763         DimensionsCommon dimensionsCommon = new DimensionsCommon();
764         dimensionsCommon.setDimension(dimensionType);
765         dimensionsCommon.setValue(new BigDecimal(dimensionValue));
766         dimensionsCommon.setValueDate(entryDate);
767         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
768                 commonPartName, dimensionsCommon);
769
770         if (logger.isDebugEnabled()) {
771             logger.debug("to be created, dimension common");
772             logger.debug(objectAsXmlString(dimensionsCommon,
773                     DimensionsCommon.class));
774         }
775
776         return multipart;
777     }
778         
779 //      @Override
780 //    protected String createTestObject(String testName) throws Exception {
781 //              String result = null;
782 //              
783 //        DimensionClient client = new DimensionClient();
784 //        String identifier = createIdentifier();
785 //        PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
786 //                identifier);
787 //        ClientResponse<Response> res = client.create(multipart);
788 //
789 //        int statusCode = res.getStatus();
790 //        Assert.assertEquals(statusCode, STATUS_CREATED);
791 //
792 //        result = extractId(res);
793 //        allResourceIdsCreated.add(result);
794 //
795 //        return result;
796 //      }
797         
798 //      /*
799 //       * This test assumes that no objects exist yet.
800 //       * 
801 //       * http://localhost:8180/cspace-services/intakes?wf_deleted=false
802 //       */
803 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
804 //      public void readWorkflowList(String testName) throws Exception {
805 //      //
806 //      // Create 3 new objects
807 //      //
808 //      final int OBJECTS_TOTAL = 3;
809 //      for (int i = 0; i < OBJECTS_TOTAL; i++) {
810 //              this.createWorkflowTarget(testName);
811 //      }
812 //      //
813 //      // Mark one as soft deleted
814 //      //
815 //      int currentTotal = allResourceIdsCreated.size();
816 //      String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added
817 //      this.setupUpdate();
818 //      this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED);
819 //      //
820 //      // Read the list back.  The deleted item should not be in the list
821 //      //
822 ////            int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE);
823 ////            Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results.");
824 //      }
825     
826     protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception {
827         //
828         // Read the existing object
829         //
830         DimensionClient client = new DimensionClient();
831         ClientResponse<String> res = client.getWorkflow(resourceId);
832         assertStatusCode(res, testName);
833         logger.debug("Got object to update life cycle state with ID: " + resourceId);
834         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
835         WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
836         Assert.assertNotNull(workflowCommons);
837         //
838         // Mark it for a soft delete.
839         //
840         logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
841         workflowCommons.setCurrentLifeCycleState(lifeCycleState);
842         PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
843         PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE);
844         commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME);
845         //
846         // Perform the update
847         //
848         res = client.updateWorkflow(resourceId, output);
849         assertStatusCode(res, testName);
850         input = new PoxPayloadIn(res.getEntity());
851         WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
852         Assert.assertNotNull(updatedWorkflowCommons);
853         //
854         // Read the updated object and make sure it was updated correctly.
855         //
856         res = client.getWorkflow(resourceId);
857         assertStatusCode(res, testName);
858         logger.debug("Got workflow state of updated object with ID: " + resourceId);
859         input = new PoxPayloadIn(res.getEntity());
860         updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
861         Assert.assertNotNull(workflowCommons);
862         Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);
863     }
864     
865 }