]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
c9ac4b32ca6a391797088090b379ef60d0b00552
[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     // Failure outcomes
148     // Placeholders until the three tests below can be uncommented.
149     // See Issue CSPACE-401.
150     /* (non-Javadoc)
151      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
152      */
153     @Override
154     public void createWithEmptyEntityBody(String testName) throws Exception {
155         //Should this test really be empty?
156     }
157
158     /* (non-Javadoc)
159      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
160      */
161     @Override
162     public void createWithMalformedXml(String testName) throws Exception {
163         //Should this test really be empty?
164     }
165
166     /* (non-Javadoc)
167      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
168      */
169     @Override
170     public void createWithWrongXmlSchema(String testName) throws Exception {
171         //Should this test really be empty?
172     }
173
174     /*
175     @Override
176     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
177         dependsOnMethods = {"create", "testSubmitRequest"})
178     public void createWithEmptyEntityBody(String testName) throws Exception {
179     
180             if (logger.isDebugEnabled()) {
181             logger.debug(testBanner(testName, CLASS_NAME));
182         }
183         // Perform setup.
184         setupCreateWithEmptyEntityBody();
185
186         // Submit the request to the service and store the response.
187         String method = REQUEST_TYPE.httpMethodName();
188         String url = getServiceRootURL();
189         String mediaType = MediaType.APPLICATION_XML;
190         final String entity = "";
191         int statusCode = submitRequest(method, url, mediaType, entity);
192
193         // Check the status code of the response: does it match
194         // the expected response(s)?
195         if(logger.isDebugEnabled()){
196             logger.debug(testName + ": url=" + url +
197                 " status=" + statusCode);
198          }
199         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
200         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
201         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
202     }
203
204     @Override
205     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
206         dependsOnMethods = {"create", "testSubmitRequest"})
207     public void createWithMalformedXml(String testName) throws Exception {
208     
209             if (logger.isDebugEnabled()) {
210             logger.debug(testBanner(testName, CLASS_NAME));
211         }
212         // Perform setup.
213         setupCreateWithMalformedXml();
214
215         // Submit the request to the service and store the response.
216         String method = REQUEST_TYPE.httpMethodName();
217         String url = getServiceRootURL();
218         String mediaType = MediaType.APPLICATION_XML;
219         final String entity = MALFORMED_XML_DATA; // Constant from base class.
220         int statusCode = submitRequest(method, url, mediaType, entity);
221
222         // Check the status code of the response: does it match
223         // the expected response(s)?
224         if(logger.isDebugEnabled()){
225             logger.debug(testName + ": url=" + url +
226                 " status=" + statusCode);
227          }
228         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
229         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
230         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
231     }
232
233     @Override
234     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
235         dependsOnMethods = {"create", "testSubmitRequest"})
236     public void createWithWrongXmlSchema(String testName) throws Exception {
237     
238             if (logger.isDebugEnabled()) {
239             logger.debug(testBanner(testName, CLASS_NAME));
240         }
241         // Perform setup.
242         setupCreateWithWrongXmlSchema();
243
244         // Submit the request to the service and store the response.
245         String method = REQUEST_TYPE.httpMethodName();
246         String url = getServiceRootURL();
247         String mediaType = MediaType.APPLICATION_XML;
248         final String entity = WRONG_XML_SCHEMA_DATA;
249         int statusCode = submitRequest(method, url, mediaType, entity);
250
251         // Check the status code of the response: does it match
252         // the expected response(s)?
253         if(logger.isDebugEnabled()){
254           logger.debug(testName + ": url=" + url +
255               " status=" + statusCode);
256          }
257         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
258         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
259         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
260     }
261      */
262
263     // ---------------------------------------------------------------
264     // CRUD tests : READ tests
265     // ---------------------------------------------------------------
266     // Success outcomes
267     /* (non-Javadoc)
268      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
269      */
270     @Override
271     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
272         dependsOnMethods = {"create"})
273     public void read(String testName) throws Exception {
274
275         if (logger.isDebugEnabled()) {
276             logger.debug(testBanner(testName, CLASS_NAME));
277         }
278         // Perform setup.
279         setupRead();
280
281         // Submit the request to the service and store the response.
282         RelationClient client = new RelationClient();
283         ClientResponse<MultipartInput> res = client.read(knownResourceId);
284         int statusCode = res.getStatus();
285
286         // Check the status code of the response: does it match
287         // the expected response(s)?
288         if(logger.isDebugEnabled()){
289             logger.debug(testName + ": status = " + statusCode);
290         }
291         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
292                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
293         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294
295         // Verify that the resource identifier ...
296         MultipartInput input = (MultipartInput) res.getEntity();
297         RelationsCommon relation = (RelationsCommon) extractPart(input,
298                 client.getCommonPartName(), RelationsCommon.class);
299         Assert.assertNotNull(relation);
300
301     }
302
303     // Failure outcomes
304     /* (non-Javadoc)
305      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
306      */
307     @Override
308     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
309         dependsOnMethods = {"read"})
310     public void readNonExistent(String testName) throws Exception {
311
312         if (logger.isDebugEnabled()) {
313             logger.debug(testBanner(testName, CLASS_NAME));
314         }
315         // Perform setup.
316         setupReadNonExistent();
317
318         // Submit the request to the service and store the response.
319         RelationClient client = new RelationClient();
320         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
321         int statusCode = res.getStatus();
322
323         // Check the status code of the response: does it match
324         // the expected response(s)?
325         if(logger.isDebugEnabled()){
326             logger.debug(testName + ": status = " + statusCode);
327         }
328         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
329                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
330         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
331     }
332    
333     // ---------------------------------------------------------------
334     // CRUD tests : READ_LIST tests
335     // ---------------------------------------------------------------
336     // Success outcomes
337     /* (non-Javadoc)
338      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
339      */
340     @Override
341     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
342         dependsOnMethods = {"createList", "read"})
343     public void readList(String testName) throws Exception {
344
345         if (logger.isDebugEnabled()) {
346             logger.debug(testBanner(testName, CLASS_NAME));
347         }
348         // Perform setup.
349         setupReadList();
350
351         // Submit the request to the service and store the response.
352         RelationClient client = new RelationClient();
353         ClientResponse<RelationsCommonList> res = client.readList();
354         RelationsCommonList list = res.getEntity();
355         int statusCode = res.getStatus();
356
357         // Check the status code of the response: does it match
358         // the expected response(s)?
359         if(logger.isDebugEnabled()){
360             logger.debug(testName + ": status = " + statusCode);
361         }
362         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
365
366         // Optionally output additional data about list members for debugging.
367         boolean iterateThroughList = false;
368         if(iterateThroughList && logger.isDebugEnabled()){
369             List<RelationsCommonList.RelationListItem> items =
370                     list.getRelationListItem();
371             int i = 0;
372             for(RelationsCommonList.RelationListItem item : items){
373                 logger.debug(testName + ": list-item[" + i + "] csid=" +
374                         item.getCsid());
375                 logger.debug(testName + ": list-item[" + i + "] URI=" +
376                         item.getUri());
377                 i++;
378             }
379         }
380
381     }
382
383
384     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
385         dependsOnMethods = {"createList", "read"})
386     public void readListPaginated(String testName) throws Exception {
387
388         if (logger.isDebugEnabled()) {
389             logger.debug(testBanner(testName, CLASS_NAME));
390         }
391         // Perform setup.
392         setupReadList();
393
394         Long pageSize=1L;
395         Long pageNumber=0L;
396         RelationClient client = new RelationClient();
397         ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
398                                                                   "", //subjectType,
399                                                                   "", //predicate,
400                                                                   "", //objectCsid,
401                                                                   "", //objectType,
402                                                                   "", //sortBy,
403                                                                   pageSize,
404                                                                   pageNumber);
405         RelationsCommonList list = res.getEntity();
406         int statusCode = res.getStatus();
407
408         // Check the status code of the response: does it match
409         // the expected response(s)?
410         if(logger.isDebugEnabled()){
411             logger.debug(testName + ": status = " + statusCode);
412         }
413         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
414                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
415         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416
417         // Optionally output additional data about list members for debugging.
418         boolean iterateThroughList = false;
419         if(iterateThroughList && logger.isDebugEnabled()){
420             List<RelationsCommonList.RelationListItem> items =
421                     list.getRelationListItem();
422             int i = 0;
423             for(RelationsCommonList.RelationListItem item : items){
424                 logger.debug(testName + ": list-item[" + i + "] csid=" +
425                         item.getCsid());
426                 logger.debug(testName + ": list-item[" + i + "] URI=" +
427                         item.getUri());
428                 i++;
429             }
430         }
431
432     }
433
434
435     // Failure outcomes
436     // None at present.
437
438     // ---------------------------------------------------------------
439     // CRUD tests : UPDATE tests
440     // ---------------------------------------------------------------
441
442     // Success outcomes
443     /* (non-Javadoc)
444      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
445      */
446     @Override
447     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
448         dependsOnMethods = {"read"})
449     public void update(String testName) throws Exception {
450
451         if (logger.isDebugEnabled()) {
452             logger.debug(testBanner(testName, CLASS_NAME));
453         }
454         // Perform setup.
455         setupUpdate();
456
457         // Retrieve an existing resource that we can update.
458         RelationClient client = new RelationClient();
459         ClientResponse<MultipartInput> res =
460                 client.read(knownResourceId);
461         if(logger.isDebugEnabled()){
462             logger.debug(testName + ": read status = " + res.getStatus());
463         }
464         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
465         if(logger.isDebugEnabled()){
466             logger.debug("Got object to update with ID: " + knownResourceId);
467         }
468         MultipartInput input = (MultipartInput) res.getEntity();
469         RelationsCommon relation = (RelationsCommon) extractPart(input,
470                 client.getCommonPartName(), RelationsCommon.class);
471         Assert.assertNotNull(relation);
472
473         // Update the content of this resource.
474         relation.setDocumentId1("updated-" + relation.getDocumentId1());
475         relation.setDocumentType1("updated-" + relation.getDocumentType1());
476         relation.setDocumentId2("updated-" + relation.getDocumentId2());
477         relation.setDocumentType2("updated-" + relation.getDocumentType2());
478         relation.setPredicateDisplayName("updated-" + relation.getPredicateDisplayName());
479         if(logger.isDebugEnabled()){
480             logger.debug("updated object");
481             logger.debug(objectAsXmlString(relation, RelationsCommon.class));
482         }
483
484         // Submit the request to the service and store the response.
485         MultipartOutput output = new MultipartOutput();
486         OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
487         commonPart.getHeaders().add("label", client.getCommonPartName());
488         res = client.update(knownResourceId, output);
489         int statusCode = res.getStatus();
490
491         // Check the status code of the response: does it match the expected response(s)?
492         if(logger.isDebugEnabled()){
493             logger.debug(testName + ": status = " + statusCode);
494         }
495         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
496                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
497         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
498
499         input = (MultipartInput) res.getEntity();
500         RelationsCommon updatedObject = (RelationsCommon) extractPart(
501                 input, client.getCommonPartName(),
502                 RelationsCommon.class);
503         Assert.assertNotNull(updatedObject);
504
505         final String msg =
506                 "Data in updated object did not match submitted data.";
507         Assert.assertEquals(
508                 updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
509         Assert.assertEquals(
510                 updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
511         Assert.assertEquals(
512                 updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
513         Assert.assertEquals(
514                 updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
515         Assert.assertEquals(
516                 updatedObject.getPredicateDisplayName(), relation.getPredicateDisplayName(), msg);
517
518     }
519
520     // Failure outcomes
521     // Placeholders until the three tests below can be uncommented.
522     // See Issue CSPACE-401.
523     /* (non-Javadoc)
524      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
525      */
526     @Override
527     public void updateWithEmptyEntityBody(String testName) throws Exception {
528         //Should this test really be empty?
529     }
530
531     /* (non-Javadoc)
532      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
533      */
534     @Override
535     public void updateWithMalformedXml(String testName) throws Exception {
536         //Should this test really be empty?
537     }
538
539     /* (non-Javadoc)
540      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
541      */
542     @Override
543     public void updateWithWrongXmlSchema(String testName) throws Exception {
544         //Should this test really be empty?
545     }
546
547     /*
548     @Override
549     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
550         dependsOnMethods = {"create", "update", "testSubmitRequest"})
551     public void updateWithEmptyEntityBody(String testName) throws Exception {
552     
553         if (logger.isDebugEnabled()) {
554             logger.debug(testBanner(testName, CLASS_NAME));
555         }
556         // Perform setup.
557         setupUpdateWithEmptyEntityBody();
558
559         // Submit the request to the service and store the response.
560         String method = REQUEST_TYPE.httpMethodName();
561         String url = getResourceURL(knownResourceId);
562         String mediaType = MediaType.APPLICATION_XML;
563         final String entity = "";
564         int statusCode = submitRequest(method, url, mediaType, entity);
565
566         // Check the status code of the response: does it match
567         // the expected response(s)?
568         if(logger.isDebugEnabled()){
569            logger.debug(testName + ": url=" + url +
570                " status=" + statusCode);
571          }
572         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
573         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
574         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
575     }
576
577     @Override
578     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
579         dependsOnMethods = {"create", "update", "testSubmitRequest"})
580     public void updateWithMalformedXml(String testName) throws Exception {
581
582         if (logger.isDebugEnabled()) {
583             logger.debug(testBanner(testName, CLASS_NAME));
584         }
585         // Perform setup.
586         setupUpdateWithMalformedXml();
587
588         // Submit the request to the service and store the response.
589         String method = REQUEST_TYPE.httpMethodName();
590         String url = getResourceURL(knownResourceId);
591         String mediaType = MediaType.APPLICATION_XML;
592         final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
593         int statusCode = submitRequest(method, url, mediaType, entity);
594
595         // Check the status code of the response: does it match
596         // the expected response(s)?
597         if(logger.isDebugEnabled()){
598             logger.debug(testName + ": url=" + url +
599             " status=" + statusCode);
600          }
601         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
602         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
603         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
604     }
605
606     @Override
607     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
608         dependsOnMethods = {"create", "update", "testSubmitRequest"})
609     public void updateWithWrongXmlSchema(String testName) throws Exception {
610     
611         if (logger.isDebugEnabled()) {
612             logger.debug(testBanner(testName, CLASS_NAME));
613         }
614         // Perform setup.
615         setupUpdateWithWrongXmlSchema();
616
617         // Submit the request to the service and store the response.
618         String method = REQUEST_TYPE.httpMethodName();
619         String url = getResourceURL(knownResourceId);
620         String mediaType = MediaType.APPLICATION_XML;
621         final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
622         int statusCode = submitRequest(method, url, mediaType, entity);
623
624         // Check the status code of the response: does it match
625         // the expected response(s)?
626         if(logger.isDebugEnabled()){
627             logger.debug(testName + ": url=" + url +
628             " status=" + statusCode);
629          }
630         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
631         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
632         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
633     }
634      */
635
636     /* (non-Javadoc)
637      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
638      */
639     @Override
640     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
641         dependsOnMethods = {"update", "testSubmitRequest"})
642     public void updateNonExistent(String testName) throws Exception {
643
644         if (logger.isDebugEnabled()) {
645             logger.debug(testBanner(testName, CLASS_NAME));
646         }
647         // Perform setup.
648         setupUpdateNonExistent();
649
650         // Submit the request to the service and store the response.
651         // Note: The ID used in this 'create' call may be arbitrary.
652         // The only relevant ID may be the one used in update(), below.
653         RelationClient client = new RelationClient();
654         MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
655         ClientResponse<MultipartInput> res =
656                 client.update(NON_EXISTENT_ID, multipart);
657         int statusCode = res.getStatus();
658
659         // Check the status code of the response: does it match
660         // the expected response(s)?
661         if(logger.isDebugEnabled()){
662             logger.debug(testName + ": status = " + statusCode);
663         }
664         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667     }
668
669     // ---------------------------------------------------------------
670     // CRUD tests : DELETE tests
671     // ---------------------------------------------------------------
672     // Success outcomes
673     /* (non-Javadoc)
674      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
675      */
676     @Override
677     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
678         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
679     public void delete(String testName) throws Exception {
680
681         if (logger.isDebugEnabled()) {
682             logger.debug(testBanner(testName, CLASS_NAME));
683         }
684         // Perform setup.
685         setupDelete();
686
687         // Submit the request to the service and store the response.
688         RelationClient client = new RelationClient();
689         ClientResponse<Response> res = client.delete(knownResourceId);
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     // Failure outcomes
703     /* (non-Javadoc)
704      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
705      */
706     @Override
707     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
708         dependsOnMethods = {"delete"})
709     public void deleteNonExistent(String testName) throws Exception {
710
711         if (logger.isDebugEnabled()) {
712             logger.debug(testBanner(testName, CLASS_NAME));
713         }
714         // Perform setup.
715         setupDeleteNonExistent();
716
717         // Submit the request to the service and store the response.
718         RelationClient client = new RelationClient();
719         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
720         int statusCode = res.getStatus();
721
722         // Check the status code of the response: does it match
723         // the expected response(s)?
724         if(logger.isDebugEnabled()){
725             logger.debug(testName + ": status = " + statusCode);
726         }
727         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
728                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
729         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
730     }
731
732     // ---------------------------------------------------------------
733     // RELATE_OBJECT tests
734     // ---------------------------------------------------------------
735     /**
736      * Relate objects.
737      */
738     @Test(dependsOnMethods = {"create"})
739     public void relateObjects() {
740         //Should this test really be empty?
741     }
742
743     // ---------------------------------------------------------------
744     // Utility tests : tests of code used in tests above
745     // ---------------------------------------------------------------
746     /**
747      * Tests the code for manually submitting data that is used by several
748      * of the methods above.
749      */
750     @Test(dependsOnMethods = {"create", "read"})
751     public void testSubmitRequest() {
752
753         setupRead();
754
755         // Submit the request to the service and store the response.
756         String method = ServiceRequestType.READ.httpMethodName();
757         String url = getResourceURL(knownResourceId);
758         int statusCode = submitRequest(method, url);
759
760         // Check the status code of the response: does it match
761         // the expected response(s)?
762         if(logger.isDebugEnabled()){
763             logger.debug("testSubmitRequest: url=" + url +
764                 " status=" + statusCode);
765         }
766         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
767     }
768
769     // ---------------------------------------------------------------
770     // Utility methods used by tests above
771     // ---------------------------------------------------------------
772     /* (non-Javadoc)
773      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
774      */
775     @Override
776     public String getServicePathComponent() {
777         return SERVICE_PATH_COMPONENT;
778     }
779
780     /**
781      * Creates the relation instance.
782      *
783      * @param identifier the identifier
784      * @return the multipart output
785      */
786     private MultipartOutput createRelationInstance(String identifier) {
787         RelationsCommon relation = new RelationsCommon();
788         fillRelation(relation, identifier);
789
790         MultipartOutput multipart = new MultipartOutput();
791         OutputPart commonPart =
792                 multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
793         commonPart.getHeaders().add("label", new RelationClient().getCommonPartName());
794         if(logger.isDebugEnabled()){
795           logger.debug("to be created, relation common");
796           logger.debug(objectAsXmlString(relation, RelationsCommon.class));
797         }
798         return multipart;
799     }
800
801     /**
802      * Fills the relation.
803      *
804      * @param relation the relation
805      * @param identifier the identifier
806      */
807     private void fillRelation(RelationsCommon relation, String identifier) {
808         fillRelation(relation, "Subject-" + identifier,
809                 "SubjectType-" + identifier + "-type",
810                 "Object-" + identifier,
811                 "ObjectType-" + identifier + "-type",
812                 RelationshipType.COLLECTIONOBJECT_INTAKE,
813                 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
814     }
815
816     /**
817      * Fills the relation.
818      *
819      * @param relation the relation
820      * @param documentId1 the document id1
821      * @param documentType1 the document type1
822      * @param documentId2 the document id2
823      * @param documentType2 the document type2
824      * @param rt the rt
825      */
826     private void fillRelation(RelationsCommon relation,
827             String documentId1, String documentType1,
828             String documentId2, String documentType2,
829             RelationshipType rt,
830             String rtDisplayName) {
831         relation.setDocumentId1(documentId1);
832         relation.setDocumentType1(documentType1);
833         relation.setDocumentId2(documentId2);
834         relation.setDocumentType2(documentType2);
835
836         relation.setRelationshipType(rt);
837         relation.setPredicateDisplayName(rtDisplayName);
838     }
839 }