]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
75e8a5fe10686f0326519a1f6bde1b882663e567
[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         assertStatusCode(res, testName);
298         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
299         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
300         DimensionsCommon dimensionsCommon = null;
301         if (payloadInputPart != null) {
302                 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
303         }
304         Assert.assertNotNull(dimensionsCommon);
305     }
306
307     // Failure outcomes
308     /* (non-Javadoc)
309      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
310      */
311     @Override
312     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
313     dependsOnMethods = {"read"})
314     public void readNonExistent(String testName) throws Exception {
315
316         if (logger.isDebugEnabled()) {
317             logger.debug(testBanner(testName, CLASS_NAME));
318         }
319         // Perform setup.
320         setupReadNonExistent();
321
322         // Submit the request to the service and store the response.
323         DimensionClient client = new DimensionClient();
324         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
325         int statusCode = res.getStatus();
326
327         // Check the status code of the response: does it match
328         // the expected response(s)?
329         if (logger.isDebugEnabled()) {
330             logger.debug(testName + ": status = " + statusCode);
331         }
332         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
333                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
334         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
335     }
336
337     // ---------------------------------------------------------------
338     // CRUD tests : READ_LIST tests
339     // ---------------------------------------------------------------
340     // Success outcomes
341     /* (non-Javadoc)
342      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
343      */
344     @Override
345     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
346     dependsOnMethods = {"read"})
347     public void readList(String testName) throws Exception {
348
349         if (logger.isDebugEnabled()) {
350             logger.debug(testBanner(testName, CLASS_NAME));
351         }
352         // Perform setup.
353         setupReadList();
354
355         // Submit the request to the service and store the response.
356         DimensionClient client = new DimensionClient();
357         ClientResponse<DimensionsCommonList> res = client.readList();
358         assertStatusCode(res, testName);
359         DimensionsCommonList list = res.getEntity();
360
361         // Optionally output additional data about list members for debugging.
362         boolean iterateThroughList = false;
363         if (iterateThroughList && logger.isDebugEnabled()) {
364             List<DimensionsCommonList.DimensionListItem> items =
365                     list.getDimensionListItem();
366             int i = 0;
367             for (DimensionsCommonList.DimensionListItem item : items) {
368                 logger.debug(testName + ": list-item[" + i + "] csid="
369                         + item.getCsid());
370                 logger.debug(testName + ": list-item[" + i + "] objectNumber="
371                         + item.getDimension());
372                 logger.debug(testName + ": list-item[" + i + "] URI="
373                         + item.getUri());
374                 i++;
375             }
376         }
377
378     }
379
380     // Failure outcomes
381     // None at present.
382     // ---------------------------------------------------------------
383     // CRUD tests : UPDATE tests
384     // ---------------------------------------------------------------
385     // Success outcomes
386     /* (non-Javadoc)
387      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
388      */
389     @Override
390     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
391     dependsOnMethods = {"read"})
392     public void update(String testName) throws Exception {
393
394         if (logger.isDebugEnabled()) {
395             logger.debug(testBanner(testName, CLASS_NAME));
396         }
397         // Perform setup.
398         setupUpdate();
399
400         // Retrieve the contents of a resource to update.
401         DimensionClient client = new DimensionClient();
402         ClientResponse<String> res =
403                 client.read(knownResourceId);
404         assertStatusCode(res, testName);
405         if (logger.isDebugEnabled()) {
406             logger.debug("got object to update with ID: " + knownResourceId);
407         }
408         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
409         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
410         DimensionsCommon dimensionsCommon = null;
411         if (payloadInputPart != null) {
412                 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
413         }
414         Assert.assertNotNull(dimensionsCommon);
415
416         // Update the content of this resource.
417         dimensionsCommon.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
418         dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate());
419         if (logger.isDebugEnabled()) {
420             logger.debug("to be updated object");
421             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
422         }
423         // Submit the request to the service and store the response.
424         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
425         PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE);
426         commonPart.setLabel(client.getCommonPartName());
427
428         res = client.update(knownResourceId, output);
429         int statusCode = res.getStatus();
430         assertStatusCode(res, testName);
431         input = new PoxPayloadIn(res.getEntity());
432         DimensionsCommon updatedDimensionsCommon =
433                 (DimensionsCommon) extractPart(input,
434                 client.getCommonPartName(), DimensionsCommon.class);
435         Assert.assertNotNull(updatedDimensionsCommon);
436
437         Assert.assertEquals(updatedDimensionsCommon.getValueDate(),
438                 dimensionsCommon.getValueDate(),
439                 "Data in updated object did not match submitted data.");
440
441     }
442
443     // Failure outcomes
444     // Placeholders until the three tests below can be uncommented.
445     // See Issue CSPACE-401.
446     /* (non-Javadoc)
447      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
448      */
449     @Override
450     public void updateWithEmptyEntityBody(String testName) throws Exception {
451         //Should this really be empty?
452     }
453
454     /* (non-Javadoc)
455      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
456      */
457     @Override
458     public void updateWithMalformedXml(String testName) throws Exception {
459         //Should this really be empty?
460     }
461
462     /* (non-Javadoc)
463      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
464      */
465     @Override
466     public void updateWithWrongXmlSchema(String testName) throws Exception {
467         //Should this really be empty?
468     }
469
470     /*
471     @Override
472     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
473     dependsOnMethods = {"create", "update", "testSubmitRequest"})
474     public void updateWithEmptyEntityBody(String testName) throws Exception {
475
476         if (logger.isDebugEnabled()) {
477             logger.debug(testBanner(testName, CLASS_NAME));
478         }
479         // Perform setup.
480         setupUpdateWithEmptyEntityBody();
481
482         // Submit the request to the service and store the response.
483         String method = REQUEST_TYPE.httpMethodName();
484         String url = getResourceURL(knownResourceId);
485         String mediaType = MediaType.APPLICATION_XML;
486         final String entity = "";
487         int statusCode = submitRequest(method, url, mediaType, entity);
488
489         // Check the status code of the response: does it match
490         // the expected response(s)?
491         if(logger.isDebugEnabled()){
492         logger.debug(testName + ": url=" + url +
493         " status=" + statusCode);
494         }
495         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
496         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
497         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
498     }
499
500     @Override
501     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
502     dependsOnMethods = {"create", "update", "testSubmitRequest"})
503     public void updateWithMalformedXml(String testName) throws Exception {
504
505         if (logger.isDebugEnabled()) {
506             logger.debug(testBanner(testName, CLASS_NAME));
507         }
508         // Perform setup.
509         setupUpdateWithMalformedXml(testName, logger);
510
511         // Submit the request to the service and store the response.
512         String method = REQUEST_TYPE.httpMethodName();
513         String url = getResourceURL(knownResourceId);
514         String mediaType = MediaType.APPLICATION_XML;
515         final String entity = MALFORMED_XML_DATA;
516         int statusCode = submitRequest(method, url, mediaType, entity);
517
518         // Check the status code of the response: does it match
519         // the expected response(s)?
520         if(logger.isDebugEnabled()){
521         logger.debug(testName + ": url=" + url +
522         " status=" + statusCode);
523         }
524         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
527     }
528
529     @Override
530     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
531     dependsOnMethods = {"create", "update", "testSubmitRequest"})
532     public void updateWithWrongXmlSchema(String testName) throws Exception {
533
534         if (logger.isDebugEnabled()) {
535             logger.debug(testBanner(testName, CLASS_NAME));
536         }
537         // Perform setup.
538         setupUpdateWithWrongXmlSchema(testName, logger);
539
540         // Submit the request to the service and store the response.
541         String method = REQUEST_TYPE.httpMethodName();
542         String url = getResourceURL(knownResourceId);
543         String mediaType = MediaType.APPLICATION_XML;
544         final String entity = WRONG_XML_SCHEMA_DATA;
545         int statusCode = submitRequest(method, url, mediaType, entity);
546
547         // Check the status code of the response: does it match
548         // the expected response(s)?
549         if(logger.isDebugEnabled()){
550         logger.debug(testName + ": url=" + url +
551         " status=" + statusCode);
552         }
553         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556     }
557      */
558
559     /* (non-Javadoc)
560      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
561      */
562     @Override
563     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
564     dependsOnMethods = {"update", "testSubmitRequest"})
565     public void updateNonExistent(String testName) throws Exception {
566
567         if (logger.isDebugEnabled()) {
568             logger.debug(testBanner(testName, CLASS_NAME));
569         }
570         // Perform setup.
571         setupUpdateNonExistent();
572
573         // Submit the request to the service and store the response.
574         // Note: The ID used in this 'create' call may be arbitrary.
575         // The only relevant ID may be the one used in update(), below.
576         DimensionClient client = new DimensionClient();
577         PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
578                 NON_EXISTENT_ID);
579         ClientResponse<String> res =
580                 client.update(NON_EXISTENT_ID, multipart);
581         int statusCode = res.getStatus();
582
583         // Check the status code of the response: does it match
584         // the expected response(s)?
585         if (logger.isDebugEnabled()) {
586             logger.debug(testName + ": status = " + statusCode);
587         }
588         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
589                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
590         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591     }
592
593     // ---------------------------------------------------------------
594     // CRUD tests : DELETE tests
595     // ---------------------------------------------------------------
596     // Success outcomes
597     /* (non-Javadoc)
598      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
599      */
600     @Override
601     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
602     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "readWorkflow"})
603     public void delete(String testName) throws Exception {
604
605         if (logger.isDebugEnabled()) {
606             logger.debug(testBanner(testName, CLASS_NAME));
607         }
608         // Perform setup.
609         setupDelete();
610
611         // Submit the request to the service and store the response.
612         DimensionClient client = new DimensionClient();
613         ClientResponse<Response> res = client.delete(knownResourceId);
614         int statusCode = res.getStatus();
615
616         // Check the status code of the response: does it match
617         // the expected response(s)?
618         if (logger.isDebugEnabled()) {
619             logger.debug(testName + ": status = " + statusCode);
620         }
621         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624     }
625
626     // Failure outcomes
627     /* (non-Javadoc)
628      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
629      */
630     @Override
631     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
632     dependsOnMethods = {"delete"})
633     public void deleteNonExistent(String testName) throws Exception {
634
635         if (logger.isDebugEnabled()) {
636             logger.debug(testBanner(testName, CLASS_NAME));
637         }
638         // Perform setup.
639         setupDeleteNonExistent();
640
641         // Submit the request to the service and store the response.
642         DimensionClient client = new DimensionClient();
643         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
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     // ---------------------------------------------------------------
657     // Search tests
658     // ---------------------------------------------------------------
659     
660     @Override
661     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
662     public void searchWorkflowDeleted(String testName) throws Exception {
663         // Fixme: null test for now, overriding test in base class
664     }
665
666     // ---------------------------------------------------------------
667     // Utility tests : tests of code used in tests above
668     // ---------------------------------------------------------------
669     /**
670      * Tests the code for manually submitting data that is used by several
671      * of the methods above.
672      */
673     @Test(dependsOnMethods = {"create", "read"})
674     public void testSubmitRequest() {
675
676         // Expected status code: 200 OK
677         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
678
679         // Submit the request to the service and store the response.
680         String method = ServiceRequestType.READ.httpMethodName();
681         String url = getResourceURL(knownResourceId);
682         int statusCode = submitRequest(method, url);
683
684         // Check the status code of the response: does it match
685         // the expected response(s)?
686         if (logger.isDebugEnabled()) {
687             logger.debug("testSubmitRequest: url=" + url
688                     + " status=" + statusCode);
689         }
690         Assert.assertEquals(statusCode, EXPECTED_STATUS);
691
692     }
693
694     // ---------------------------------------------------------------
695     // Utility methods used by tests above
696     // ---------------------------------------------------------------
697     /* (non-Javadoc)
698      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
699      */
700     @Override
701     public String getServicePathComponent() {
702         return DimensionClient.SERVICE_PATH_COMPONENT;
703     }
704
705     @Override
706     protected PoxPayloadOut createInstance(String identifier) {
707         DimensionClient client = new DimensionClient();
708         return createDimensionInstance(client.getCommonPartName(), identifier);
709     }
710     
711     /**
712      * Creates the dimension instance.
713      *
714      * @param identifier the identifier
715      * @return the multipart output
716      */
717     private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
718         return createDimensionInstance(commonPartName, 
719                 "dimensionType-" + identifier,
720                 DIMENSION_VALUE,
721                 "entryDate-" + identifier);
722     }
723
724     /**
725      * Creates the dimension instance.
726      *
727      * @param dimensionType the dimension type
728      * @param entryNumber the entry number
729      * @param entryDate the entry date
730      * @return the multipart output
731      */
732     private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
733         DimensionsCommon dimensionsCommon = new DimensionsCommon();
734         dimensionsCommon.setDimension(dimensionType);
735         dimensionsCommon.setValue(new BigDecimal(dimensionValue));
736         dimensionsCommon.setValueDate(entryDate);
737         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
738                 commonPartName, dimensionsCommon);
739
740         if (logger.isDebugEnabled()) {
741             logger.debug("to be created, dimension common");
742             logger.debug(objectAsXmlString(dimensionsCommon,
743                     DimensionsCommon.class));
744         }
745
746         return multipart;
747     }
748         
749 //      @Override
750 //    protected String createTestObject(String testName) throws Exception {
751 //              String result = null;
752 //              
753 //        DimensionClient client = new DimensionClient();
754 //        String identifier = createIdentifier();
755 //        PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
756 //                identifier);
757 //        ClientResponse<Response> res = client.create(multipart);
758 //
759 //        int statusCode = res.getStatus();
760 //        Assert.assertEquals(statusCode, STATUS_CREATED);
761 //
762 //        result = extractId(res);
763 //        allResourceIdsCreated.add(result);
764 //
765 //        return result;
766 //      }
767         
768 //      /*
769 //       * This test assumes that no objects exist yet.
770 //       * 
771 //       * http://localhost:8180/cspace-services/intakes?wf_deleted=false
772 //       */
773 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
774 //      public void readWorkflowList(String testName) throws Exception {
775 //      //
776 //      // Create 3 new objects
777 //      //
778 //      final int OBJECTS_TOTAL = 3;
779 //      for (int i = 0; i < OBJECTS_TOTAL; i++) {
780 //              this.createWorkflowTarget(testName);
781 //      }
782 //      //
783 //      // Mark one as soft deleted
784 //      //
785 //      int currentTotal = allResourceIdsCreated.size();
786 //      String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added
787 //      this.setupUpdate();
788 //      this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED);
789 //      //
790 //      // Read the list back.  The deleted item should not be in the list
791 //      //
792 ////            int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE);
793 ////            Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results.");
794 //      }
795     
796     protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception {
797         //
798         // Read the existing object
799         //
800         DimensionClient client = new DimensionClient();
801         ClientResponse<String> res = client.getWorkflow(resourceId);
802         assertStatusCode(res, testName);
803         logger.debug("Got object to update life cycle state with ID: " + resourceId);
804         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
805         WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
806         Assert.assertNotNull(workflowCommons);
807         //
808         // Mark it for a soft delete.
809         //
810         logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
811         workflowCommons.setCurrentLifeCycleState(lifeCycleState);
812         PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
813         PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE);
814         commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME);
815         //
816         // Perform the update
817         //
818         res = client.updateWorkflow(resourceId, output);
819         assertStatusCode(res, testName);
820         input = new PoxPayloadIn(res.getEntity());
821         WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
822         Assert.assertNotNull(updatedWorkflowCommons);
823         //
824         // Read the updated object and make sure it was updated correctly.
825         //
826         res = client.getWorkflow(resourceId);
827         assertStatusCode(res, testName);
828         logger.debug("Got workflow state of updated object with ID: " + resourceId);
829         input = new PoxPayloadIn(res.getEntity());
830         updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
831         Assert.assertNotNull(workflowCommons);
832         Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);
833     }
834     
835 }