]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6c9b3b2db069c728e3584222a1a3a4b43580f6bd
[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.setSubjectCsid(relationsCommon.getObjectCsid());
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         assertStatusCode(res, testName);
388
389         // Get the common part from the response and check that it is not null.
390         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
391         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
392         RelationsCommon relationCommon = null;
393         if (payloadInputPart != null) {
394                 relationCommon = (RelationsCommon) payloadInputPart.getBody();
395         }
396         Assert.assertNotNull(relationCommon);
397
398     }
399
400     // Failure outcomes
401     /* (non-Javadoc)
402      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
403      */
404     @Override
405     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
406         dependsOnMethods = {"read"})
407     public void readNonExistent(String testName) throws Exception {
408
409         if (logger.isDebugEnabled()) {
410             logger.debug(testBanner(testName, CLASS_NAME));
411         }
412         // Perform setup.
413         setupReadNonExistent();
414
415         // Submit the request to the service and store the response.
416         RelationClient client = new RelationClient();
417         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
418         int statusCode = res.getStatus();
419
420         // Check the status code of the response: does it match
421         // the expected response(s)?
422         if(logger.isDebugEnabled()){
423             logger.debug(testName + ": status = " + statusCode);
424         }
425         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
426                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
427         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
428     }
429    
430     // ---------------------------------------------------------------
431     // CRUD tests : READ_LIST tests
432     // ---------------------------------------------------------------
433     // Success outcomes
434     /* (non-Javadoc)
435      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
436      */
437     @Override
438     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
439         dependsOnMethods = {"createList", "read"})
440     public void readList(String testName) throws Exception {
441
442         if (logger.isDebugEnabled()) {
443             logger.debug(testBanner(testName, CLASS_NAME));
444         }
445         // Perform setup.
446         setupReadList();
447
448         // Submit the request to the service and store the response.
449         RelationClient client = new RelationClient();
450         ClientResponse<RelationsCommonList> res = client.readList();
451         assertStatusCode(res, testName);
452         RelationsCommonList list = res.getEntity();
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     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
473         dependsOnMethods = {"createList", "read"})
474     public void readListPaginated(String testName) throws Exception {
475
476         if (logger.isDebugEnabled()) {
477             logger.debug(testBanner(testName, CLASS_NAME));
478         }
479         // Perform setup.
480         setupReadList();
481
482         Long pageSize=1L;
483         Long pageNumber=0L;
484         RelationClient client = new RelationClient();
485         ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
486                                                                   "", //subjectType,
487                                                                   "", //predicate,
488                                                                   "", //objectCsid,
489                                                                   "", //objectType,
490                                                                   "", //sortBy,
491                                                                   pageSize,
492                                                                   pageNumber);
493         RelationsCommonList list = res.getEntity();
494         assertStatusCode(res, testName);
495
496         // Optionally output additional data about list members for debugging.
497         boolean iterateThroughList = false;
498         if(iterateThroughList && logger.isDebugEnabled()){
499             List<RelationsCommonList.RelationListItem> items =
500                     list.getRelationListItem();
501             int i = 0;
502             for(RelationsCommonList.RelationListItem item : items){
503                 logger.debug(testName + ": list-item[" + i + "] csid=" +
504                         item.getCsid());
505                 logger.debug(testName + ": list-item[" + i + "] URI=" +
506                         item.getUri());
507                 i++;
508             }
509         }
510
511     }
512
513
514     // Failure outcomes
515     // None at present.
516
517     // ---------------------------------------------------------------
518     // CRUD tests : UPDATE tests
519     // ---------------------------------------------------------------
520
521     // Success outcomes
522     /* (non-Javadoc)
523      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
524      */
525     @Override
526     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
527         dependsOnMethods = {"read"})
528     public void update(String testName) throws Exception {
529
530         logger.debug(testBanner(testName, CLASS_NAME));
531         // Perform setup.
532         setupUpdate();
533
534         // Retrieve an existing resource that we can update.
535         RelationClient client = new RelationClient();
536         ClientResponse<String> res = client.read(knownResourceId);
537         assertStatusCode(res, testName);
538         logger.debug("Got object to update with ID: " + knownResourceId);
539         
540         // Extract the common part and verify that it is not null.
541         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
542         PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
543         RelationsCommon relationCommon = null;
544         if (payloadInputPart != null) {
545                 relationCommon = (RelationsCommon) payloadInputPart.getBody();
546         }
547         Assert.assertNotNull(relationCommon);
548         logger.trace("object before update");
549         logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
550
551         String newSubjectDocType = relationCommon.getObjectDocumentType();
552         String newObjectDocType = relationCommon.getSubjectDocumentType();
553         String newSubjectId = relationCommon.getObjectCsid();
554         String newObjectId = relationCommon.getSubjectCsid();
555         // Update the content of this resource, inverting subject and object
556         relationCommon.setSubjectCsid(newSubjectId);
557         relationCommon.setSubjectDocumentType("Hooey");
558         relationCommon.setObjectCsid(newObjectId);
559         relationCommon.setObjectDocumentType("Fooey");
560         relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
561         logger.trace("updated object to send");
562         logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
563
564         // Submit the request containing the updated resource to the service
565         // and store the response.
566         PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
567         PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
568         commonPart.setLabel(client.getCommonPartName());
569         res = client.update(knownResourceId, output);
570         assertStatusCode(res, testName);
571
572         // Extract the common part of the updated resource and verify that it is not null.
573         input = new PoxPayloadIn(res.getEntity());
574         RelationsCommon updatedRelationCommon =
575                 (RelationsCommon) extractPart(input,
576                         client.getCommonPartName(), RelationsCommon.class);
577         Assert.assertNotNull(updatedRelationCommon);
578
579         logger.trace("updated object as received");
580         logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class));
581
582         final String msg =
583                 "Data in updated object did not match submitted data.";
584         final String msg2 =
585                 "Data in updated object was not correctly computed.";
586         Assert.assertEquals(
587                 updatedRelationCommon.getSubjectCsid(), newSubjectId, msg);
588         Assert.assertEquals(
589                 updatedRelationCommon.getSubjectDocumentType(), newSubjectDocType, msg2);
590         Assert.assertEquals(
591                 updatedRelationCommon.getObjectCsid(), newObjectId, msg);
592         Assert.assertEquals(
593                 updatedRelationCommon.getObjectDocumentType(), newObjectDocType, msg2);
594         Assert.assertEquals(
595                 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
596
597     }
598
599     // Failure outcomes
600     // Placeholders until the three tests below can be uncommented.
601     // See Issue CSPACE-401.
602     /* (non-Javadoc)
603      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
604      */
605     @Override
606     public void updateWithEmptyEntityBody(String testName) throws Exception {
607         //Should this test really be empty?
608     }
609
610     /* (non-Javadoc)
611      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
612      */
613     @Override
614     public void updateWithMalformedXml(String testName) throws Exception {
615         //Should this test really be empty?
616     }
617
618     /* (non-Javadoc)
619      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
620      */
621     @Override
622     public void updateWithWrongXmlSchema(String testName) throws Exception {
623         //Should this test really be empty?
624     }
625
626     /*
627     @Override
628     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
629         dependsOnMethods = {"create", "update", "testSubmitRequest"})
630     public void updateWithEmptyEntityBody(String testName) throws Exception {
631     
632         if (logger.isDebugEnabled()) {
633             logger.debug(testBanner(testName, CLASS_NAME));
634         }
635         // Perform setup.
636         setupUpdateWithEmptyEntityBody();
637
638         // Submit the request to the service and store the response.
639         String method = REQUEST_TYPE.httpMethodName();
640         String url = getResourceURL(knownResourceId);
641         String mediaType = MediaType.APPLICATION_XML;
642         final String entity = "";
643         int statusCode = submitRequest(method, url, mediaType, entity);
644
645         // Check the status code of the response: does it match
646         // the expected response(s)?
647         if(logger.isDebugEnabled()){
648            logger.debug(testName + ": url=" + url +
649                " status=" + statusCode);
650          }
651         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
654     }
655
656     @Override
657     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
658         dependsOnMethods = {"create", "update", "testSubmitRequest"})
659     public void updateWithMalformedXml(String testName) throws Exception {
660
661         if (logger.isDebugEnabled()) {
662             logger.debug(testBanner(testName, CLASS_NAME));
663         }
664         // Perform setup.
665         setupUpdateWithMalformedXml();
666
667         // Submit the request to the service and store the response.
668         String method = REQUEST_TYPE.httpMethodName();
669         String url = getResourceURL(knownResourceId);
670         String mediaType = MediaType.APPLICATION_XML;
671         final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
672         int statusCode = submitRequest(method, url, mediaType, entity);
673
674         // Check the status code of the response: does it match
675         // the expected response(s)?
676         if(logger.isDebugEnabled()){
677             logger.debug(testName + ": url=" + url +
678             " status=" + statusCode);
679          }
680         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
683     }
684
685     @Override
686     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
687         dependsOnMethods = {"create", "update", "testSubmitRequest"})
688     public void updateWithWrongXmlSchema(String testName) throws Exception {
689     
690         if (logger.isDebugEnabled()) {
691             logger.debug(testBanner(testName, CLASS_NAME));
692         }
693         // Perform setup.
694         setupUpdateWithWrongXmlSchema();
695
696         // Submit the request to the service and store the response.
697         String method = REQUEST_TYPE.httpMethodName();
698         String url = getResourceURL(knownResourceId);
699         String mediaType = MediaType.APPLICATION_XML;
700         final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
701         int statusCode = submitRequest(method, url, mediaType, entity);
702
703         // Check the status code of the response: does it match
704         // the expected response(s)?
705         if(logger.isDebugEnabled()){
706             logger.debug(testName + ": url=" + url +
707             " status=" + statusCode);
708          }
709         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
710         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
711         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712     }
713      */
714
715     /* (non-Javadoc)
716      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
717      */
718     @Override
719     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
720         dependsOnMethods = {"update", "testSubmitRequest"})
721     public void updateNonExistent(String testName) throws Exception {
722
723         if (logger.isDebugEnabled()) {
724             logger.debug(testBanner(testName, CLASS_NAME));
725         }
726         // Perform setup.
727         setupUpdateNonExistent();
728
729         // Submit the request to the service and store the response.
730         // Note: The ID used in this 'create' call may be arbitrary.
731         // The only relevant ID may be the one used in update(), below.
732         RelationClient client = new RelationClient();
733         PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
734         ClientResponse<String> res =
735                 client.update(NON_EXISTENT_ID, multipart);
736         int statusCode = res.getStatus();
737
738         // Check the status code of the response: does it match
739         // the expected response(s)?
740         if(logger.isDebugEnabled()){
741             logger.debug(testName + ": 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     // CRUD tests : DELETE tests
750     // ---------------------------------------------------------------
751     // Success outcomes
752     /* (non-Javadoc)
753      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
754      */
755     @Override
756     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
757         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
758     public void delete(String testName) throws Exception {
759
760         if (logger.isDebugEnabled()) {
761             logger.debug(testBanner(testName, CLASS_NAME));
762         }
763         // Perform setup.
764         setupDelete();
765
766         // Submit the request to the service and store the response.
767         RelationClient client = new RelationClient();
768         ClientResponse<Response> res = client.delete(knownResourceId);
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     // Failure outcomes
782     /* (non-Javadoc)
783      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
784      */
785     @Override
786     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
787         dependsOnMethods = {"delete"})
788     public void deleteNonExistent(String testName) throws Exception {
789
790         if (logger.isDebugEnabled()) {
791             logger.debug(testBanner(testName, CLASS_NAME));
792         }
793         // Perform setup.
794         setupDeleteNonExistent();
795
796         // Submit the request to the service and store the response.
797         RelationClient client = new RelationClient();
798         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
799         int statusCode = res.getStatus();
800
801         // Check the status code of the response: does it match
802         // the expected response(s)?
803         if(logger.isDebugEnabled()){
804             logger.debug(testName + ": status = " + statusCode);
805         }
806         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
807                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
808         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
809     }
810
811     // ---------------------------------------------------------------
812     // RELATE_OBJECT tests
813     // ---------------------------------------------------------------
814     /**
815      * Relate objects.
816      */
817     @Test(dependsOnMethods = {"create"})
818     public void relateObjects() {
819         //Should this test really be empty?
820     }
821
822     // ---------------------------------------------------------------
823     // Utility tests : tests of code used in tests above
824     // ---------------------------------------------------------------
825     /**
826      * Tests the code for manually submitting data that is used by several
827      * of the methods above.
828      */
829     @Test(dependsOnMethods = {"create", "read"})
830     public void testSubmitRequest() {
831
832         setupRead();
833
834         // Submit the request to the service and store the response.
835         String method = ServiceRequestType.READ.httpMethodName();
836         String url = getResourceURL(knownResourceId);
837         int statusCode = submitRequest(method, url);
838
839         // Check the status code of the response: does it match
840         // the expected response(s)?
841         if(logger.isDebugEnabled()){
842             logger.debug("testSubmitRequest: url=" + url +
843                 " status=" + statusCode);
844         }
845         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
846     }
847
848     // ---------------------------------------------------------------
849     // Utility methods used by tests above
850     // ---------------------------------------------------------------
851     /* (non-Javadoc)
852      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
853      */
854     @Override
855     public String getServicePathComponent() {
856         return SERVICE_PATH_COMPONENT;
857     }
858
859     private RelationsCommon createRelationsCommon(String identifier) {
860         RelationsCommon relationCommon = new RelationsCommon();
861         fillRelation(relationCommon, identifier);
862         return relationCommon;
863     }
864
865     private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
866         PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
867         PayloadOutputPart commonPart =
868                 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
869         commonPart.setLabel(new RelationClient().getCommonPartName());
870         if(logger.isDebugEnabled()){
871           logger.debug("to be created, relation common");
872           logger.debug(objectAsXmlString(relation, RelationsCommon.class));
873         }
874         return result;
875     }
876     
877     /**
878      * Creates the relation instance.
879      *
880      * @param identifier the identifier
881      * @return the multipart output
882      */
883     private PoxPayloadOut createRelationInstance(String identifier) {
884         RelationsCommon relation = createRelationsCommon(identifier);
885         PoxPayloadOut result = createRelationInstance(relation);
886         return result;
887     }
888
889     /**
890      * Fills the relation.
891      *
892      * @param relationCommon the relation
893      * @param identifier the identifier
894      */
895     private void fillRelation(RelationsCommon relationCommon, String identifier) {
896         fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null,
897                 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
898                 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
899     }
900
901     /**
902      * Fills the relation.
903      *
904      * @param relationCommon the relation
905      * @param subjectCsid the subject document id
906      * @param subjectDocumentType the subject document type
907      * @param objectCsid the object document id
908      * @param objectDocumentType the object document type
909      * @param rt the rt
910      */
911     private void fillRelation(RelationsCommon relationCommon,
912             String subjectCsid, String subjectDocumentType,
913             String objectCsid, String objectDocumentType,
914             String rt,
915             String rtDisplayName) {
916         relationCommon.setSubjectCsid(subjectCsid);
917         relationCommon.setSubjectDocumentType(subjectDocumentType);
918         relationCommon.setObjectCsid(objectCsid);
919         relationCommon.setObjectDocumentType(objectDocumentType);
920
921         relationCommon.setRelationshipType(rt);
922         relationCommon.setPredicateDisplayName(rtDisplayName);
923     }
924
925         @Override
926         protected String getServiceName() {
927                 return RelationClient.SERVICE_NAME;
928         }
929 }