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