]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
76f0254c0f9ca42a1ac55b9401923704d5e64ad0
[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         logger.debug(testBanner(testName, CLASS_NAME));
558         // Perform setup.
559         setupUpdate();
560
561         // Retrieve an existing resource that we can update.
562         RelationClient client = new RelationClient();
563         ClientResponse<String> res = client.read(knownResourceId);
564         logger.debug(testName + ": read status = " + res.getStatus());
565         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
566         logger.debug("Got object to update with ID: " + knownResourceId);
567         
568         // Extract the common part and verify that it is not null.
569         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
570         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
571         RelationsCommon relationCommon = null;
572         if (payloadInputPart != null) {
573                 relationCommon = (RelationsCommon) payloadInputPart.getBody();
574         }
575         Assert.assertNotNull(relationCommon);
576         logger.trace("object before update");
577         logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
578
579         String newSubjectDocType = relationCommon.getObjectDocumentType();
580         String newObjectDocType = relationCommon.getSubjectDocumentType();
581         String newSubjectId = relationCommon.getObjectCsid();
582         String newObjectId = relationCommon.getSubjectCsid();
583         // Update the content of this resource, inverting subject and object
584         relationCommon.setSubjectCsid(newSubjectId);
585         relationCommon.setSubjectDocumentType("Hooey");
586         relationCommon.setObjectCsid(newObjectId);
587         relationCommon.setObjectDocumentType("Fooey");
588         relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
589         logger.trace("updated object to send");
590         logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
591
592         // Submit the request containing the updated resource to the service
593         // and store the response.
594         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
595         PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
596         commonPart.setLabel(client.getCommonPartName());
597         res = client.update(knownResourceId, output);
598         int statusCode = res.getStatus();
599
600         // Check the status code of the response: does it match the expected response(s)?
601             logger.debug(testName + ": status = " + statusCode);
602         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
605
606         // Extract the common part of the updated resource and verify that it is not null.
607         input = new PoxPayloadIn(res.getEntity());
608         RelationsCommon updatedRelationCommon =
609                 (RelationsCommon) extractPart(input,
610                         client.getCommonPartName(), RelationsCommon.class);
611         Assert.assertNotNull(updatedRelationCommon);
612
613         logger.trace("updated object as received");
614         logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class));
615
616         final String msg =
617                 "Data in updated object did not match submitted data.";
618         final String msg2 =
619                 "Data in updated object was not correctly computed.";
620         Assert.assertEquals(
621                 updatedRelationCommon.getDocumentId1(), newSubjectId, msg);
622         Assert.assertEquals(
623                 updatedRelationCommon.getDocumentType1(), newSubjectDocType, msg2);
624         Assert.assertEquals(
625                 updatedRelationCommon.getDocumentId2(), newObjectId, msg);
626         Assert.assertEquals(
627                 updatedRelationCommon.getDocumentType2(), newObjectDocType, msg2);
628         Assert.assertEquals(
629                 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
630
631     }
632
633     // Failure outcomes
634     // Placeholders until the three tests below can be uncommented.
635     // See Issue CSPACE-401.
636     /* (non-Javadoc)
637      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
638      */
639     @Override
640     public void updateWithEmptyEntityBody(String testName) throws Exception {
641         //Should this test really be empty?
642     }
643
644     /* (non-Javadoc)
645      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
646      */
647     @Override
648     public void updateWithMalformedXml(String testName) throws Exception {
649         //Should this test really be empty?
650     }
651
652     /* (non-Javadoc)
653      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
654      */
655     @Override
656     public void updateWithWrongXmlSchema(String testName) throws Exception {
657         //Should this test really be empty?
658     }
659
660     /*
661     @Override
662     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
663         dependsOnMethods = {"create", "update", "testSubmitRequest"})
664     public void updateWithEmptyEntityBody(String testName) throws Exception {
665     
666         if (logger.isDebugEnabled()) {
667             logger.debug(testBanner(testName, CLASS_NAME));
668         }
669         // Perform setup.
670         setupUpdateWithEmptyEntityBody();
671
672         // Submit the request to the service and store the response.
673         String method = REQUEST_TYPE.httpMethodName();
674         String url = getResourceURL(knownResourceId);
675         String mediaType = MediaType.APPLICATION_XML;
676         final String entity = "";
677         int statusCode = submitRequest(method, url, mediaType, entity);
678
679         // Check the status code of the response: does it match
680         // the expected response(s)?
681         if(logger.isDebugEnabled()){
682            logger.debug(testName + ": url=" + url +
683                " status=" + statusCode);
684          }
685         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
686         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
687         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
688     }
689
690     @Override
691     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
692         dependsOnMethods = {"create", "update", "testSubmitRequest"})
693     public void updateWithMalformedXml(String testName) throws Exception {
694
695         if (logger.isDebugEnabled()) {
696             logger.debug(testBanner(testName, CLASS_NAME));
697         }
698         // Perform setup.
699         setupUpdateWithMalformedXml();
700
701         // Submit the request to the service and store the response.
702         String method = REQUEST_TYPE.httpMethodName();
703         String url = getResourceURL(knownResourceId);
704         String mediaType = MediaType.APPLICATION_XML;
705         final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
706         int statusCode = submitRequest(method, url, mediaType, entity);
707
708         // Check the status code of the response: does it match
709         // the expected response(s)?
710         if(logger.isDebugEnabled()){
711             logger.debug(testName + ": url=" + url +
712             " status=" + statusCode);
713          }
714         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
715         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
716         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
717     }
718
719     @Override
720     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
721         dependsOnMethods = {"create", "update", "testSubmitRequest"})
722     public void updateWithWrongXmlSchema(String testName) throws Exception {
723     
724         if (logger.isDebugEnabled()) {
725             logger.debug(testBanner(testName, CLASS_NAME));
726         }
727         // Perform setup.
728         setupUpdateWithWrongXmlSchema();
729
730         // Submit the request to the service and store the response.
731         String method = REQUEST_TYPE.httpMethodName();
732         String url = getResourceURL(knownResourceId);
733         String mediaType = MediaType.APPLICATION_XML;
734         final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
735         int statusCode = submitRequest(method, url, mediaType, entity);
736
737         // Check the status code of the response: does it match
738         // the expected response(s)?
739         if(logger.isDebugEnabled()){
740             logger.debug(testName + ": url=" + url +
741             " status=" + statusCode);
742          }
743         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
744         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
745         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
746     }
747      */
748
749     /* (non-Javadoc)
750      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
751      */
752     @Override
753     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754         dependsOnMethods = {"update", "testSubmitRequest"})
755     public void updateNonExistent(String testName) throws Exception {
756
757         if (logger.isDebugEnabled()) {
758             logger.debug(testBanner(testName, CLASS_NAME));
759         }
760         // Perform setup.
761         setupUpdateNonExistent();
762
763         // Submit the request to the service and store the response.
764         // Note: The ID used in this 'create' call may be arbitrary.
765         // The only relevant ID may be the one used in update(), below.
766         RelationClient client = new RelationClient();
767         PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
768         ClientResponse<String> res =
769                 client.update(NON_EXISTENT_ID, multipart);
770         int statusCode = res.getStatus();
771
772         // Check the status code of the response: does it match
773         // the expected response(s)?
774         if(logger.isDebugEnabled()){
775             logger.debug(testName + ": status = " + statusCode);
776         }
777         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
778                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
779         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
780     }
781
782     // ---------------------------------------------------------------
783     // CRUD tests : DELETE tests
784     // ---------------------------------------------------------------
785     // Success outcomes
786     /* (non-Javadoc)
787      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
788      */
789     @Override
790     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
791         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
792     public void delete(String testName) throws Exception {
793
794         if (logger.isDebugEnabled()) {
795             logger.debug(testBanner(testName, CLASS_NAME));
796         }
797         // Perform setup.
798         setupDelete();
799
800         // Submit the request to the service and store the response.
801         RelationClient client = new RelationClient();
802         ClientResponse<Response> res = client.delete(knownResourceId);
803         int statusCode = res.getStatus();
804
805         // Check the status code of the response: does it match
806         // the expected response(s)?
807         if(logger.isDebugEnabled()){
808             logger.debug(testName + ": status = " + statusCode);
809         }
810         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
811                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
812         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
813     }
814
815     // Failure outcomes
816     /* (non-Javadoc)
817      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
818      */
819     @Override
820     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
821         dependsOnMethods = {"delete"})
822     public void deleteNonExistent(String testName) throws Exception {
823
824         if (logger.isDebugEnabled()) {
825             logger.debug(testBanner(testName, CLASS_NAME));
826         }
827         // Perform setup.
828         setupDeleteNonExistent();
829
830         // Submit the request to the service and store the response.
831         RelationClient client = new RelationClient();
832         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
833         int statusCode = res.getStatus();
834
835         // Check the status code of the response: does it match
836         // the expected response(s)?
837         if(logger.isDebugEnabled()){
838             logger.debug(testName + ": status = " + statusCode);
839         }
840         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
841                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
842         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
843     }
844
845     // ---------------------------------------------------------------
846     // RELATE_OBJECT tests
847     // ---------------------------------------------------------------
848     /**
849      * Relate objects.
850      */
851     @Test(dependsOnMethods = {"create"})
852     public void relateObjects() {
853         //Should this test really be empty?
854     }
855
856     // ---------------------------------------------------------------
857     // Utility tests : tests of code used in tests above
858     // ---------------------------------------------------------------
859     /**
860      * Tests the code for manually submitting data that is used by several
861      * of the methods above.
862      */
863     @Test(dependsOnMethods = {"create", "read"})
864     public void testSubmitRequest() {
865
866         setupRead();
867
868         // Submit the request to the service and store the response.
869         String method = ServiceRequestType.READ.httpMethodName();
870         String url = getResourceURL(knownResourceId);
871         int statusCode = submitRequest(method, url);
872
873         // Check the status code of the response: does it match
874         // the expected response(s)?
875         if(logger.isDebugEnabled()){
876             logger.debug("testSubmitRequest: url=" + url +
877                 " status=" + statusCode);
878         }
879         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
880     }
881
882     // ---------------------------------------------------------------
883     // Utility methods used by tests above
884     // ---------------------------------------------------------------
885     /* (non-Javadoc)
886      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
887      */
888     @Override
889     public String getServicePathComponent() {
890         return SERVICE_PATH_COMPONENT;
891     }
892
893     private RelationsCommon createRelationsCommon(String identifier) {
894         RelationsCommon relationCommon = new RelationsCommon();
895         fillRelation(relationCommon, identifier);
896         return relationCommon;
897     }
898
899     private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
900         PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
901         PayloadOutputPart commonPart =
902                 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
903         commonPart.setLabel(new RelationClient().getCommonPartName());
904         if(logger.isDebugEnabled()){
905           logger.debug("to be created, relation common");
906           logger.debug(objectAsXmlString(relation, RelationsCommon.class));
907         }
908         return result;
909     }
910     
911     /**
912      * Creates the relation instance.
913      *
914      * @param identifier the identifier
915      * @return the multipart output
916      */
917     private PoxPayloadOut createRelationInstance(String identifier) {
918         RelationsCommon relation = createRelationsCommon(identifier);
919         PoxPayloadOut result = createRelationInstance(relation);
920         return result;
921     }
922
923     /**
924      * Fills the relation.
925      *
926      * @param relationCommon the relation
927      * @param identifier the identifier
928      */
929     private void fillRelation(RelationsCommon relationCommon, String identifier) {
930         fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null,
931                 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
932                 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
933     }
934
935     /**
936      * Fills the relation.
937      *
938      * @param relationCommon the relation
939      * @param documentId1 the document id1
940      * @param documentType1 the document type1
941      * @param documentId2 the document id2
942      * @param documentType2 the document type2
943      * @param rt the rt
944      */
945     private void fillRelation(RelationsCommon relationCommon,
946             String documentId1, String documentType1,
947             String documentId2, String documentType2,
948             String rt,
949             String rtDisplayName) {
950         relationCommon.setDocumentId1(documentId1);
951         relationCommon.setDocumentType1(documentType1);
952         relationCommon.setDocumentId2(documentId2);
953         relationCommon.setDocumentType2(documentType2);
954
955         relationCommon.setRelationshipType(rt);
956         relationCommon.setPredicateDisplayName(rtDisplayName);
957     }
958
959         @Override
960         protected String getServiceName() {
961                 return RelationClient.SERVICE_NAME;
962         }
963 }