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