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