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