]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
26ecb6bf0f8e6fa2183d9392edd24c3e4b418767
[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.PayloadInputPart;
31 import org.collectionspace.services.client.PayloadOutputPart;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.client.RelationClient;
35 import org.collectionspace.services.jaxb.AbstractCommonList;
36 import org.collectionspace.services.relation.RelationsCommon;
37 import org.collectionspace.services.relation.RelationsCommonList;
38 import org.collectionspace.services.relation.RelationshipType;
39
40 import org.jboss.resteasy.client.ClientResponse;
41
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * RelationServiceTest, carries out tests against a
50  * deployed and running Relation Service.
51  * 
52  * $LastChangedRevision$
53  * $LastChangedDate$
54  */
55 public class RelationServiceTest extends AbstractServiceTestImpl {
56
57    /** The logger. */
58     private final String CLASS_NAME = RelationServiceTest.class.getName();
59     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60
61     /** The SERVICE path component. */
62     final String SERVICE_PATH_COMPONENT = "relations";
63     
64     /** The known resource id. */
65     private String knownResourceId = null;
66     
67     /* (non-Javadoc)
68      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
69      */
70     @Override
71     protected CollectionSpaceClient getClientInstance() {
72         return new RelationClient();
73     }
74     
75     /* (non-Javadoc)
76      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
77      */
78     @Override
79         protected AbstractCommonList getAbstractCommonList(
80                         ClientResponse<AbstractCommonList> response) {
81         return response.getEntity(RelationsCommonList.class);
82     }
83  
84     // ---------------------------------------------------------------
85     // CRUD tests : CREATE tests
86     // ---------------------------------------------------------------
87     // Success outcomes
88     /* (non-Javadoc)
89      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
90      */
91     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
92     @Override
93     public void create(String testName) throws Exception {
94
95         if (logger.isDebugEnabled()) {
96             logger.debug(testBanner(testName, CLASS_NAME));
97         }
98         // Perform setup, such as initializing the type of service request
99         // (e.g. CREATE, DELETE), its valid and expected status codes, and
100         // its associated HTTP method name (e.g. POST, DELETE).
101         setupCreate();
102
103         // Submit the request to the service and store the response.
104         RelationClient client = new RelationClient();
105         String identifier = createIdentifier();
106         PoxPayloadOut multipart = createRelationInstance(identifier);
107         ClientResponse<Response> res = client.create(multipart);
108         int statusCode = res.getStatus();
109
110         // Check the status code of the response: does it match
111         // the expected response(s)?
112         //
113         // Does it fall within the set of valid status codes?
114         // Does it exactly match the expected status code?
115         if(logger.isDebugEnabled()){
116             logger.debug(testName + ": status = " + statusCode);
117         }
118         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
119                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
120         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
121
122         // Store the ID returned from the first resource created
123         // for additional tests below.
124         if (knownResourceId == null){
125             knownResourceId = extractId(res);
126             if (logger.isDebugEnabled()) {
127                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
128             }
129         }
130
131         // Store the IDs from every resource created by tests,
132         // so they can be deleted after tests have been run.
133         allResourceIdsCreated.add(extractId(res));
134     }
135
136     /* (non-Javadoc)
137      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
138      */
139     @Override
140     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
141         dependsOnMethods = {"create"})
142     public void createList(String testName) throws Exception {
143         for(int i = 0; i < 3; i++){
144             create(testName);
145         }
146     }
147     
148     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
149             dependsOnMethods = {"create"})
150     public void createWithSelfRelation(String testName) throws Exception {
151
152         if (logger.isDebugEnabled()) {
153             logger.debug(testBanner(testName, CLASS_NAME));
154         }
155
156         setupCreateWithInvalidBody();
157
158         // Submit the request to the service and store the response.
159         RelationClient client = new RelationClient();
160         String identifier = createIdentifier();
161         RelationsCommon relationsCommon = createRelationsCommon(identifier);
162         // Make the subject ID equal to the object ID
163         relationsCommon.setDocumentId1(relationsCommon.getDocumentId2());
164         PoxPayloadOut multipart = createRelationInstance(relationsCommon);
165         ClientResponse<Response> res = client.create(multipart);
166         int statusCode = res.getStatus();
167
168         // Check the status code of the response: does it match
169         // the expected response(s)?
170         //
171         // Does it fall within the set of valid status codes?
172         // Does it exactly match the expected status code?
173         if(logger.isDebugEnabled()){
174             logger.debug(testName + ": status = " + statusCode);
175         }
176         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
177                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
178         Assert.assertEquals(statusCode, STATUS_BAD_REQUEST);   //should be an error: same objectID and subjectID are not allowed by validator.
179     }
180
181     // Failure outcomes
182     // Placeholders until the three tests below can be uncommented.
183     // See Issue CSPACE-401.
184     /* (non-Javadoc)
185      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
186      */
187     @Override
188     public void createWithEmptyEntityBody(String testName) throws Exception {
189         //Should this test really be empty?
190     }
191
192     /* (non-Javadoc)
193      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
194      */
195     @Override
196     public void createWithMalformedXml(String testName) throws Exception {
197         //Should this test really be empty?
198     }
199
200     /* (non-Javadoc)
201      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
202      */
203     @Override
204     public void createWithWrongXmlSchema(String testName) throws Exception {
205         //Should this test really be empty?
206     }
207
208     /*
209     @Override
210     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
211         dependsOnMethods = {"create", "testSubmitRequest"})
212     public void createWithEmptyEntityBody(String testName) throws Exception {
213     
214             if (logger.isDebugEnabled()) {
215             logger.debug(testBanner(testName, CLASS_NAME));
216         }
217         // Perform setup.
218         setupCreateWithEmptyEntityBody();
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 = "";
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 createWithMalformedXml(String testName) throws Exception {
242     
243             if (logger.isDebugEnabled()) {
244             logger.debug(testBanner(testName, CLASS_NAME));
245         }
246         // Perform setup.
247         setupCreateWithMalformedXml();
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 = MALFORMED_XML_DATA; // Constant from base class.
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     @Override
268     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
269         dependsOnMethods = {"create", "testSubmitRequest"})
270     public void createWithWrongXmlSchema(String testName) throws Exception {
271     
272             if (logger.isDebugEnabled()) {
273             logger.debug(testBanner(testName, CLASS_NAME));
274         }
275         // Perform setup.
276         setupCreateWithWrongXmlSchema();
277
278         // Submit the request to the service and store the response.
279         String method = REQUEST_TYPE.httpMethodName();
280         String url = getServiceRootURL();
281         String mediaType = MediaType.APPLICATION_XML;
282         final String entity = WRONG_XML_SCHEMA_DATA;
283         int statusCode = submitRequest(method, url, mediaType, entity);
284
285         // Check the status code of the response: does it match
286         // the expected response(s)?
287         if(logger.isDebugEnabled()){
288           logger.debug(testName + ": url=" + url +
289               " status=" + statusCode);
290          }
291         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
292         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
293         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294     }
295      */
296
297     // ---------------------------------------------------------------
298     // CRUD tests : READ tests
299     // ---------------------------------------------------------------
300     // Success outcomes
301     /* (non-Javadoc)
302      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
303      */
304     @Override
305     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
306         dependsOnMethods = {"create"})
307     public void read(String testName) throws Exception {
308
309         if (logger.isDebugEnabled()) {
310             logger.debug(testBanner(testName, CLASS_NAME));
311         }
312         // Perform setup.
313         setupRead();
314
315         // Submit the request to the service and store the response.
316         RelationClient client = new RelationClient();
317         ClientResponse<String> res = client.read(knownResourceId);
318         int statusCode = res.getStatus();
319
320         // Check the status code of the response: does it match
321         // the expected response(s)?
322         if(logger.isDebugEnabled()){
323             logger.debug(testName + ": status = " + statusCode);
324         }
325         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328
329         // Get the common part from the response and check that it is not null.
330         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
331         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
332         RelationsCommon relationCommon = null;
333         if (payloadInputPart != null) {
334                 relationCommon = (RelationsCommon) payloadInputPart.getBody();
335         }
336         Assert.assertNotNull(relationCommon);
337
338     }
339
340     // Failure outcomes
341     /* (non-Javadoc)
342      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
343      */
344     @Override
345     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
346         dependsOnMethods = {"read"})
347     public void readNonExistent(String testName) throws Exception {
348
349         if (logger.isDebugEnabled()) {
350             logger.debug(testBanner(testName, CLASS_NAME));
351         }
352         // Perform setup.
353         setupReadNonExistent();
354
355         // Submit the request to the service and store the response.
356         RelationClient client = new RelationClient();
357         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
358         int statusCode = res.getStatus();
359
360         // Check the status code of the response: does it match
361         // the expected response(s)?
362         if(logger.isDebugEnabled()){
363             logger.debug(testName + ": status = " + statusCode);
364         }
365         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
368     }
369    
370     // ---------------------------------------------------------------
371     // CRUD tests : READ_LIST tests
372     // ---------------------------------------------------------------
373     // Success outcomes
374     /* (non-Javadoc)
375      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
376      */
377     @Override
378     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
379         dependsOnMethods = {"createList", "read"})
380     public void readList(String testName) throws Exception {
381
382         if (logger.isDebugEnabled()) {
383             logger.debug(testBanner(testName, CLASS_NAME));
384         }
385         // Perform setup.
386         setupReadList();
387
388         // Submit the request to the service and store the response.
389         RelationClient client = new RelationClient();
390         ClientResponse<RelationsCommonList> res = client.readList();
391         RelationsCommonList list = res.getEntity();
392         int statusCode = res.getStatus();
393
394         // Check the status code of the response: does it match
395         // the expected response(s)?
396         if(logger.isDebugEnabled()){
397             logger.debug(testName + ": status = " + statusCode);
398         }
399         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
400                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
401         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
402
403         // Optionally output additional data about list members for debugging.
404         boolean iterateThroughList = false;
405         if(iterateThroughList && logger.isDebugEnabled()){
406             List<RelationsCommonList.RelationListItem> items =
407                     list.getRelationListItem();
408             int i = 0;
409             for(RelationsCommonList.RelationListItem item : items){
410                 logger.debug(testName + ": list-item[" + i + "] csid=" +
411                         item.getCsid());
412                 logger.debug(testName + ": list-item[" + i + "] URI=" +
413                         item.getUri());
414                 i++;
415             }
416         }
417
418     }
419
420
421     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
422         dependsOnMethods = {"createList", "read"})
423     public void readListPaginated(String testName) throws Exception {
424
425         if (logger.isDebugEnabled()) {
426             logger.debug(testBanner(testName, CLASS_NAME));
427         }
428         // Perform setup.
429         setupReadList();
430
431         Long pageSize=1L;
432         Long pageNumber=0L;
433         RelationClient client = new RelationClient();
434         ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
435                                                                   "", //subjectType,
436                                                                   "", //predicate,
437                                                                   "", //objectCsid,
438                                                                   "", //objectType,
439                                                                   "", //sortBy,
440                                                                   pageSize,
441                                                                   pageNumber);
442         RelationsCommonList list = res.getEntity();
443         int statusCode = res.getStatus();
444
445         // Check the status code of the response: does it match
446         // the expected response(s)?
447         if(logger.isDebugEnabled()){
448             logger.debug(testName + ": status = " + statusCode);
449         }
450         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
451                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
452         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
453
454         // Optionally output additional data about list members for debugging.
455         boolean iterateThroughList = false;
456         if(iterateThroughList && logger.isDebugEnabled()){
457             List<RelationsCommonList.RelationListItem> items =
458                     list.getRelationListItem();
459             int i = 0;
460             for(RelationsCommonList.RelationListItem item : items){
461                 logger.debug(testName + ": list-item[" + i + "] csid=" +
462                         item.getCsid());
463                 logger.debug(testName + ": list-item[" + i + "] URI=" +
464                         item.getUri());
465                 i++;
466             }
467         }
468
469     }
470
471
472     // Failure outcomes
473     // None at present.
474
475     // ---------------------------------------------------------------
476     // CRUD tests : UPDATE tests
477     // ---------------------------------------------------------------
478
479     // Success outcomes
480     /* (non-Javadoc)
481      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
482      */
483     @Override
484     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
485         dependsOnMethods = {"read"})
486     public void update(String testName) throws Exception {
487
488         if (logger.isDebugEnabled()) {
489             logger.debug(testBanner(testName, CLASS_NAME));
490         }
491         // Perform setup.
492         setupUpdate();
493
494         // Retrieve an existing resource that we can update.
495         RelationClient client = new RelationClient();
496         ClientResponse<String> res = client.read(knownResourceId);
497         if(logger.isDebugEnabled()){
498             logger.debug(testName + ": read status = " + res.getStatus());
499         }
500         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
501         if(logger.isDebugEnabled()){
502             logger.debug("Got object to update with ID: " + knownResourceId);
503         }
504         
505         // Extract the common part and verify that it is not null.
506         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
507         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
508         RelationsCommon relationCommon = null;
509         if (payloadInputPart != null) {
510                 relationCommon = (RelationsCommon) payloadInputPart.getBody();
511         }
512         Assert.assertNotNull(relationCommon);
513
514         // Update the content of this resource.
515         relationCommon.setDocumentId1("updated-" + relationCommon.getDocumentId1());
516         relationCommon.setDocumentType1("updated-" + relationCommon.getDocumentType1());
517         relationCommon.setDocumentId2("updated-" + relationCommon.getDocumentId2());
518         relationCommon.setDocumentType2("updated-" + relationCommon.getDocumentType2());
519         relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
520         if(logger.isDebugEnabled()){
521             logger.debug("updated object");
522             logger.debug(objectAsXmlString(relationCommon, RelationsCommon.class));
523         }
524
525         // Submit the request containing the updated resource to the service
526         // and store the response.
527         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
528         PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
529         commonPart.setLabel(client.getCommonPartName());
530         res = client.update(knownResourceId, output);
531         int statusCode = res.getStatus();
532
533         // Check the status code of the response: does it match the expected response(s)?
534         if(logger.isDebugEnabled()){
535             logger.debug(testName + ": status = " + statusCode);
536         }
537         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
538                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
539         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
540
541         // Extract the common part of the updated resource and verify that it is not null.
542         input = new PoxPayloadIn(res.getEntity());
543         RelationsCommon updatedRelationCommon =
544                 (RelationsCommon) extractPart(input,
545                         client.getCommonPartName(), RelationsCommon.class);
546         Assert.assertNotNull(updatedRelationCommon);
547
548         final String msg =
549                 "Data in updated object did not match submitted data.";
550         Assert.assertEquals(
551                 updatedRelationCommon.getDocumentId1(), relationCommon.getDocumentId1(), msg);
552         Assert.assertEquals(
553                 updatedRelationCommon.getDocumentType1(), relationCommon.getDocumentType1(), msg);
554         Assert.assertEquals(
555                 updatedRelationCommon.getDocumentId2(), relationCommon.getDocumentId2(), msg);
556         Assert.assertEquals(
557                 updatedRelationCommon.getDocumentType2(), relationCommon.getDocumentType2(), msg);
558         Assert.assertEquals(
559                 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
560
561     }
562
563     // Failure outcomes
564     // Placeholders until the three tests below can be uncommented.
565     // See Issue CSPACE-401.
566     /* (non-Javadoc)
567      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
568      */
569     @Override
570     public void updateWithEmptyEntityBody(String testName) throws Exception {
571         //Should this test really be empty?
572     }
573
574     /* (non-Javadoc)
575      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
576      */
577     @Override
578     public void updateWithMalformedXml(String testName) throws Exception {
579         //Should this test really be empty?
580     }
581
582     /* (non-Javadoc)
583      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
584      */
585     @Override
586     public void updateWithWrongXmlSchema(String testName) throws Exception {
587         //Should this test really be empty?
588     }
589
590     /*
591     @Override
592     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
593         dependsOnMethods = {"create", "update", "testSubmitRequest"})
594     public void updateWithEmptyEntityBody(String testName) throws Exception {
595     
596         if (logger.isDebugEnabled()) {
597             logger.debug(testBanner(testName, CLASS_NAME));
598         }
599         // Perform setup.
600         setupUpdateWithEmptyEntityBody();
601
602         // Submit the request to the service and store the response.
603         String method = REQUEST_TYPE.httpMethodName();
604         String url = getResourceURL(knownResourceId);
605         String mediaType = MediaType.APPLICATION_XML;
606         final String entity = "";
607         int statusCode = submitRequest(method, url, mediaType, entity);
608
609         // Check the status code of the response: does it match
610         // the expected response(s)?
611         if(logger.isDebugEnabled()){
612            logger.debug(testName + ": url=" + url +
613                " status=" + statusCode);
614          }
615         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
618     }
619
620     @Override
621     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
622         dependsOnMethods = {"create", "update", "testSubmitRequest"})
623     public void updateWithMalformedXml(String testName) throws Exception {
624
625         if (logger.isDebugEnabled()) {
626             logger.debug(testBanner(testName, CLASS_NAME));
627         }
628         // Perform setup.
629         setupUpdateWithMalformedXml();
630
631         // Submit the request to the service and store the response.
632         String method = REQUEST_TYPE.httpMethodName();
633         String url = getResourceURL(knownResourceId);
634         String mediaType = MediaType.APPLICATION_XML;
635         final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
636         int statusCode = submitRequest(method, url, mediaType, entity);
637
638         // Check the status code of the response: does it match
639         // the expected response(s)?
640         if(logger.isDebugEnabled()){
641             logger.debug(testName + ": url=" + url +
642             " status=" + statusCode);
643          }
644         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
647     }
648
649     @Override
650     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
651         dependsOnMethods = {"create", "update", "testSubmitRequest"})
652     public void updateWithWrongXmlSchema(String testName) throws Exception {
653     
654         if (logger.isDebugEnabled()) {
655             logger.debug(testBanner(testName, CLASS_NAME));
656         }
657         // Perform setup.
658         setupUpdateWithWrongXmlSchema();
659
660         // Submit the request to the service and store the response.
661         String method = REQUEST_TYPE.httpMethodName();
662         String url = getResourceURL(knownResourceId);
663         String mediaType = MediaType.APPLICATION_XML;
664         final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
665         int statusCode = submitRequest(method, url, mediaType, entity);
666
667         // Check the status code of the response: does it match
668         // the expected response(s)?
669         if(logger.isDebugEnabled()){
670             logger.debug(testName + ": url=" + url +
671             " status=" + statusCode);
672          }
673         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
676     }
677      */
678
679     /* (non-Javadoc)
680      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
681      */
682     @Override
683     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684         dependsOnMethods = {"update", "testSubmitRequest"})
685     public void updateNonExistent(String testName) throws Exception {
686
687         if (logger.isDebugEnabled()) {
688             logger.debug(testBanner(testName, CLASS_NAME));
689         }
690         // Perform setup.
691         setupUpdateNonExistent();
692
693         // Submit the request to the service and store the response.
694         // Note: The ID used in this 'create' call may be arbitrary.
695         // The only relevant ID may be the one used in update(), below.
696         RelationClient client = new RelationClient();
697         PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
698         ClientResponse<String> res =
699                 client.update(NON_EXISTENT_ID, multipart);
700         int statusCode = res.getStatus();
701
702         // Check the status code of the response: does it match
703         // the expected response(s)?
704         if(logger.isDebugEnabled()){
705             logger.debug(testName + ": status = " + statusCode);
706         }
707         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
708                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
709         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
710     }
711
712     // ---------------------------------------------------------------
713     // CRUD tests : DELETE tests
714     // ---------------------------------------------------------------
715     // Success outcomes
716     /* (non-Javadoc)
717      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
718      */
719     @Override
720     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
721         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
722     public void delete(String testName) throws Exception {
723
724         if (logger.isDebugEnabled()) {
725             logger.debug(testBanner(testName, CLASS_NAME));
726         }
727         // Perform setup.
728         setupDelete();
729
730         // Submit the request to the service and store the response.
731         RelationClient client = new RelationClient();
732         ClientResponse<Response> res = client.delete(knownResourceId);
733         int statusCode = res.getStatus();
734
735         // Check the status code of the response: does it match
736         // the expected response(s)?
737         if(logger.isDebugEnabled()){
738             logger.debug(testName + ": status = " + statusCode);
739         }
740         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
741                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
742         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743     }
744
745     // Failure outcomes
746     /* (non-Javadoc)
747      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
748      */
749     @Override
750     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751         dependsOnMethods = {"delete"})
752     public void deleteNonExistent(String testName) throws Exception {
753
754         if (logger.isDebugEnabled()) {
755             logger.debug(testBanner(testName, CLASS_NAME));
756         }
757         // Perform setup.
758         setupDeleteNonExistent();
759
760         // Submit the request to the service and store the response.
761         RelationClient client = new RelationClient();
762         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
763         int statusCode = res.getStatus();
764
765         // Check the status code of the response: does it match
766         // the expected response(s)?
767         if(logger.isDebugEnabled()){
768             logger.debug(testName + ": status = " + statusCode);
769         }
770         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
773     }
774
775     // ---------------------------------------------------------------
776     // RELATE_OBJECT tests
777     // ---------------------------------------------------------------
778     /**
779      * Relate objects.
780      */
781     @Test(dependsOnMethods = {"create"})
782     public void relateObjects() {
783         //Should this test really be empty?
784     }
785
786     // ---------------------------------------------------------------
787     // Utility tests : tests of code used in tests above
788     // ---------------------------------------------------------------
789     /**
790      * Tests the code for manually submitting data that is used by several
791      * of the methods above.
792      */
793     @Test(dependsOnMethods = {"create", "read"})
794     public void testSubmitRequest() {
795
796         setupRead();
797
798         // Submit the request to the service and store the response.
799         String method = ServiceRequestType.READ.httpMethodName();
800         String url = getResourceURL(knownResourceId);
801         int statusCode = submitRequest(method, url);
802
803         // Check the status code of the response: does it match
804         // the expected response(s)?
805         if(logger.isDebugEnabled()){
806             logger.debug("testSubmitRequest: url=" + url +
807                 " status=" + statusCode);
808         }
809         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
810     }
811
812     // ---------------------------------------------------------------
813     // Utility methods used by tests above
814     // ---------------------------------------------------------------
815     /* (non-Javadoc)
816      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
817      */
818     @Override
819     public String getServicePathComponent() {
820         return SERVICE_PATH_COMPONENT;
821     }
822
823     private RelationsCommon createRelationsCommon(String identifier) {
824         RelationsCommon relationCommon = new RelationsCommon();
825         fillRelation(relationCommon, identifier);
826         return relationCommon;
827     }
828
829     private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
830         PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
831         PayloadOutputPart commonPart =
832                 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
833         commonPart.setLabel(new RelationClient().getCommonPartName());
834         if(logger.isDebugEnabled()){
835           logger.debug("to be created, relation common");
836           logger.debug(objectAsXmlString(relation, RelationsCommon.class));
837         }
838         return result;
839     }
840     
841     /**
842      * Creates the relation instance.
843      *
844      * @param identifier the identifier
845      * @return the multipart output
846      */
847     private PoxPayloadOut createRelationInstance(String identifier) {
848         RelationsCommon relation = createRelationsCommon(identifier);
849         PoxPayloadOut result = createRelationInstance(relation);
850         return result;
851     }
852
853     /**
854      * Fills the relation.
855      *
856      * @param relationCommon the relation
857      * @param identifier the identifier
858      */
859     private void fillRelation(RelationsCommon relationCommon, String identifier) {
860         fillRelation(relationCommon, "Subject-" + identifier,
861                 "SubjectType-" + identifier + "-type",
862                 "Object-" + identifier,
863                 "ObjectType-" + identifier + "-type",
864                 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
865                 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
866     }
867
868     /**
869      * Fills the relation.
870      *
871      * @param relationCommon the relation
872      * @param documentId1 the document id1
873      * @param documentType1 the document type1
874      * @param documentId2 the document id2
875      * @param documentType2 the document type2
876      * @param rt the rt
877      */
878     private void fillRelation(RelationsCommon relationCommon,
879             String documentId1, String documentType1,
880             String documentId2, String documentType2,
881             String rt,
882             String rtDisplayName) {
883         relationCommon.setDocumentId1(documentId1);
884         relationCommon.setDocumentType1(documentType1);
885         relationCommon.setDocumentId2(documentId2);
886         relationCommon.setDocumentType2(documentType2);
887
888         relationCommon.setRelationshipType(rt);
889         relationCommon.setPredicateDisplayName(rtDisplayName);
890     }
891
892         @Override
893         protected String getServiceName() {
894                 return RelationClient.SERVICE_NAME;
895         }
896 }