]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
66629c3da4c8bc3817aae05e040284a9508fb733
[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         assertStatusCode(res, testName);
286
287         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
288         ContactsCommon contact = (ContactsCommon) extractPart(input,
289                 client.getCommonPartName(), ContactsCommon.class);
290         Assert.assertNotNull(contact);
291     }
292
293     // Failure outcomes
294     @Override
295     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
296     dependsOnMethods = {"read"})
297     public void readNonExistent(String testName) throws Exception {
298
299         if (logger.isDebugEnabled()) {
300             logger.debug(testBanner(testName, CLASS_NAME));
301         }
302         // Perform setup.
303         setupReadNonExistent();
304
305         // Submit the request to the service and store the response.
306         ContactClient client = new ContactClient();
307         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
308         int statusCode = res.getStatus();
309
310         // Check the status code of the response: does it match
311         // the expected response(s)?
312         if (logger.isDebugEnabled()) {
313             logger.debug(testName + ": status = " + statusCode);
314         }
315         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
316                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
317         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
318     }
319
320     // ---------------------------------------------------------------
321     // CRUD tests : READ_LIST tests
322     // ---------------------------------------------------------------
323     // Success outcomes
324     @Override
325     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
326     dependsOnMethods = {"read"})
327     public void readList(String testName) throws Exception {
328
329         if (logger.isDebugEnabled()) {
330             logger.debug(testBanner(testName, CLASS_NAME));
331         }
332         // Perform setup.
333         setupReadList();
334
335         // Submit the request to the service and store the response.
336         ContactClient client = new ContactClient();
337         ClientResponse<AbstractCommonList> res = client.readList();
338         assertStatusCode(res, testName);
339         AbstractCommonList list = res.getEntity();
340
341         // Optionally output additional data about list members for debugging.
342         boolean iterateThroughList = false;
343         if (iterateThroughList && logger.isDebugEnabled()) {
344             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
345         }
346
347     }
348
349     // Failure outcomes
350     // None at present.
351     // ---------------------------------------------------------------
352     // CRUD tests : UPDATE tests
353     // ---------------------------------------------------------------
354     // Success outcomes
355     @Override
356     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
357     dependsOnMethods = {"read"})
358     public void update(String testName) throws Exception {
359
360         if (logger.isDebugEnabled()) {
361             logger.debug(testBanner(testName, CLASS_NAME));
362         }
363         // Perform setup.
364         setupUpdate();
365
366         // Submit the request to the service and store the response.
367         ContactClient client = new ContactClient();
368         ClientResponse<String> res = client.read(knownResourceId);
369         assertStatusCode(res, testName);
370
371         if (logger.isDebugEnabled()) {
372             logger.debug("got object to update with ID: " + knownResourceId);
373         }
374         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
375         ContactsCommon contact = (ContactsCommon) extractPart(input,
376                 client.getCommonPartName(), ContactsCommon.class);
377         Assert.assertNotNull(contact);
378         
379         if(logger.isDebugEnabled()){
380             logger.debug("contact common before updating");
381             logger.debug(BaseServiceTest.objectAsXmlString(contact, ContactsCommon.class));
382         }
383
384         // Verify the contents of this resource
385         EmailGroupList emailGroupList = contact.getEmailGroupList();
386         Assert.assertNotNull(emailGroupList);
387         List<EmailGroup> emailGroups = emailGroupList.getEmailGroup();
388         Assert.assertNotNull(emailGroups);
389         Assert.assertTrue(emailGroups.size() > 0);
390         String email = emailGroups.get(0).getEmail();
391         Assert.assertNotNull(email);
392
393         AddressGroupList addressGroupList = contact.getAddressGroupList();
394         Assert.assertNotNull(addressGroupList);
395         List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
396         Assert.assertNotNull(addressGroups);
397         Assert.assertTrue(addressGroups.size() > 0);
398         String addressType = addressGroups.get(0).getAddressType();
399         String addressPlace1 = addressGroups.get(0).getAddressPlace1();
400         Assert.assertNotNull(addressType);
401         Assert.assertNotNull(addressPlace1);
402
403         // Update the contents of this resource.
404         emailGroups.get(0).setEmail("updated-" + email);
405         contact.setEmailGroupList(emailGroupList);
406
407         addressGroups.get(0).setAddressType("updated-" + addressType);
408         addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
409         contact.setAddressGroupList(addressGroupList);
410
411         if (logger.isDebugEnabled()) {
412             logger.debug("to be updated object");
413             logger.debug(BaseServiceTest.objectAsXmlString(contact, ContactsCommon.class));
414         }
415         
416         // Submit the request to the service and store the response.
417         PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
418         PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
419         commonPart.setLabel(client.getCommonPartName());
420
421         res = client.update(knownResourceId, output);
422         assertStatusCode(res, testName);
423
424         input = new PoxPayloadIn(res.getEntity());
425         ContactsCommon updatedContact =
426                 (ContactsCommon) extractPart(input,
427                 client.getCommonPartName(), ContactsCommon.class);
428         Assert.assertNotNull(updatedContact);
429         
430         if (logger.isDebugEnabled()) {
431             logger.debug("object after update");
432             logger.debug(objectAsXmlString(updatedContact, ContactsCommon.class));
433         }
434                 
435         Assert.assertNotNull(updatedContact.getEmailGroupList().getEmailGroup().get(0));
436         Assert.assertEquals(updatedContact.getEmailGroupList().getEmailGroup().get(0).getEmail(),
437                 contact.getEmailGroupList().getEmailGroup().get(0).getEmail(),
438                 "Data in updated object did not match submitted data.");
439
440     }
441
442     // Failure outcomes
443     // Placeholders until the three tests below can be uncommented.
444     // See Issue CSPACE-401.
445     @Override
446     public void updateWithEmptyEntityBody(String testName) throws Exception {
447         //Should this really be empty??
448     }
449
450     /* (non-Javadoc)
451      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
452      */
453     @Override
454     public void updateWithMalformedXml(String testName) throws Exception {
455         //Should this really be empty??
456     }
457
458     @Override
459     public void updateWithWrongXmlSchema(String testName) throws Exception {
460         //Should this really be empty??
461     }
462
463     /*
464     @Override
465     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
466     dependsOnMethods = {"create", "update", "testSubmitRequest"})
467     public void updateWithEmptyEntityBody(String testName) throws Exception {
468     
469     if (logger.isDebugEnabled()) {
470     logger.debug(testBanner(testName, CLASS_NAME));
471     }
472     // Perform setup.
473     setupUpdateWithEmptyEntityBody();
474     
475     // Submit the request to the service and store the response.
476     String method = REQUEST_TYPE.httpMethodName();
477     String url = getResourceURL(knownResourceId);
478     String mediaType = MediaType.APPLICATION_XML;
479     final String entity = "";
480     int statusCode = submitRequest(method, url, mediaType, entity);
481     
482     // Check the status code of the response: does it match
483     // the expected response(s)?
484     if(logger.isDebugEnabled()){
485     logger.debug(testName + ": url=" + url +
486     " status=" + statusCode);
487     }
488     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
489     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
490     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
491     }
492     
493     @Override
494     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
495     dependsOnMethods = {"create", "update", "testSubmitRequest"})
496     public void updateWithMalformedXml(String testName) throws Exception {
497     
498     if (logger.isDebugEnabled()) {
499     logger.debug(testBanner(testName, CLASS_NAME));
500     }
501     // Perform setup.
502     setupUpdateWithMalformedXml();
503     
504     // Submit the request to the service and store the response.
505     String method = REQUEST_TYPE.httpMethodName();
506     String url = getResourceURL(knownResourceId);
507     String mediaType = MediaType.APPLICATION_XML;
508     final String entity = MALFORMED_XML_DATA;
509     int statusCode = submitRequest(method, url, mediaType, entity);
510     
511     // Check the status code of the response: does it match
512     // the expected response(s)?
513     if(logger.isDebugEnabled()){
514     logger.debug(testName + ": url=" + url +
515     " status=" + statusCode);
516     }
517     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
518     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
519     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
520     }
521     
522     @Override
523     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
524     dependsOnMethods = {"create", "update", "testSubmitRequest"})
525     public void updateWithWrongXmlSchema(String testName) throws Exception {
526     
527     if (logger.isDebugEnabled()) {
528     logger.debug(testBanner(testName, CLASS_NAME));
529     }
530     // Perform setup.
531     setupUpdateWithWrongXmlSchema(testName, logger);
532     
533     // Submit the request to the service and store the response.
534     String method = REQUEST_TYPE.httpMethodName();
535     String url = getResourceURL(knownResourceId);
536     String mediaType = MediaType.APPLICATION_XML;
537     final String entity = WRONG_XML_SCHEMA_DATA;
538     int statusCode = submitRequest(method, url, mediaType, entity);
539     
540     // Check the status code of the response: does it match
541     // the expected response(s)?
542     if(logger.isDebugEnabled()){
543     logger.debug(testName + ": url=" + url +
544     " status=" + statusCode);
545     }
546     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549     }
550      */
551     @Override
552     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
553     dependsOnMethods = {"update", "testSubmitRequest"})
554     public void updateNonExistent(String testName) throws Exception {
555
556         if (logger.isDebugEnabled()) {
557             logger.debug(testBanner(testName, CLASS_NAME));
558         }
559         // Perform setup.
560         setupUpdateNonExistent();
561
562         // Submit the request to the service and store the response.
563         // Note: The ID used in this 'create' call may be arbitrary.
564         // The only relevant ID may be the one used in update(), below.
565         ContactClient client = new ContactClient();
566         PoxPayloadOut multipart =
567                 ContactClientUtils.createContactInstance(NON_EXISTENT_ID, client.getCommonPartName());
568         ClientResponse<String> res =
569                 client.update(NON_EXISTENT_ID, multipart);
570         int statusCode = res.getStatus();
571
572         // Check the status code of the response: does it match
573         // the expected response(s)?
574         if (logger.isDebugEnabled()) {
575             logger.debug(testName + ": status = " + statusCode);
576         }
577         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
578                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
579         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
580     }
581
582     // ---------------------------------------------------------------
583     // CRUD tests : DELETE tests
584     // ---------------------------------------------------------------
585     // Success outcomes
586     @Override
587     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
588     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
589     public void delete(String testName) throws Exception {
590
591         if (logger.isDebugEnabled()) {
592             logger.debug(testBanner(testName, CLASS_NAME));
593         }
594         // Perform setup.
595         setupDelete();
596
597         // Submit the request to the service and store the response.
598         ContactClient client = new ContactClient();
599         ClientResponse<Response> res = client.delete(knownResourceId);
600         int statusCode = res.getStatus();
601
602         // Check the status code of the response: does it match
603         // the expected response(s)?
604         if (logger.isDebugEnabled()) {
605             logger.debug(testName + ": status = " + statusCode);
606         }
607         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610     }
611
612     // Failure outcomes
613     @Override
614     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
615     dependsOnMethods = {"delete"})
616     public void deleteNonExistent(String testName) throws Exception {
617
618         if (logger.isDebugEnabled()) {
619             logger.debug(testBanner(testName, CLASS_NAME));
620         }
621         // Perform setup.
622         setupDeleteNonExistent();
623
624         // Submit the request to the service and store the response.
625         ContactClient client = new ContactClient();
626         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
627         int statusCode = res.getStatus();
628
629         // Check the status code of the response: does it match
630         // the expected response(s)?
631         if (logger.isDebugEnabled()) {
632             logger.debug(testName + ": status = " + statusCode);
633         }
634         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637     }
638
639     // ---------------------------------------------------------------
640     // Utility tests : tests of code used in tests above
641     // ---------------------------------------------------------------
642     /**
643      * Tests the code for manually submitting data that is used by several
644      * of the methods above.
645      */
646     @Test(dependsOnMethods = {"create", "read"})
647     public void testSubmitRequest() {
648
649         // Expected status code: 200 OK
650         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
651
652         // Submit the request to the service and store the response.
653         String method = ServiceRequestType.READ.httpMethodName();
654         String url = getResourceURL(knownResourceId);
655         int statusCode = submitRequest(method, url);
656
657         // Check the status code of the response: does it match
658         // the expected response(s)?
659         if (logger.isDebugEnabled()) {
660             logger.debug("testSubmitRequest: url=" + url
661                     + " status=" + statusCode);
662         }
663         Assert.assertEquals(statusCode, EXPECTED_STATUS);
664
665     }
666 }