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