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