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