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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
25 import java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
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;
36 import org.jboss.resteasy.client.ClientResponse;
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;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * RelationServiceTest, carries out tests against a
49 * deployed and running Relation Service.
51 * $LastChangedRevision$
54 public class RelationServiceTest extends AbstractServiceTestImpl {
57 private final String CLASS_NAME = RelationServiceTest.class.getName();
58 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60 /** The SERVICE path component. */
61 final String SERVICE_PATH_COMPONENT = "relations";
63 /** The known resource id. */
64 private String knownResourceId = null;
67 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
70 protected CollectionSpaceClient getClientInstance() {
71 return new RelationClient();
75 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
78 protected AbstractCommonList getAbstractCommonList(
79 ClientResponse<AbstractCommonList> response) {
80 return response.getEntity(RelationsCommonList.class);
83 // ---------------------------------------------------------------
84 // CRUD tests : CREATE tests
85 // ---------------------------------------------------------------
88 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
90 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
92 public void create(String testName) throws Exception {
94 if (logger.isDebugEnabled()) {
95 logger.debug(testBanner(testName, CLASS_NAME));
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).
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();
109 // Check the status code of the response: does it match
110 // the expected response(s)?
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);
117 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
118 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
119 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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));
136 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
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++){
148 // Placeholders until the three tests below can be uncommented.
149 // See Issue CSPACE-401.
151 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
154 public void createWithEmptyEntityBody(String testName) throws Exception {
155 //Should this test really be empty?
159 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
162 public void createWithMalformedXml(String testName) throws Exception {
163 //Should this test really be empty?
167 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
170 public void createWithWrongXmlSchema(String testName) throws Exception {
171 //Should this test really be empty?
176 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
177 dependsOnMethods = {"create", "testSubmitRequest"})
178 public void createWithEmptyEntityBody(String testName) throws Exception {
180 if (logger.isDebugEnabled()) {
181 logger.debug(testBanner(testName, CLASS_NAME));
184 setupCreateWithEmptyEntityBody();
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);
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);
199 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
200 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
201 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
205 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
206 dependsOnMethods = {"create", "testSubmitRequest"})
207 public void createWithMalformedXml(String testName) throws Exception {
209 if (logger.isDebugEnabled()) {
210 logger.debug(testBanner(testName, CLASS_NAME));
213 setupCreateWithMalformedXml();
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);
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);
228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
234 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
235 dependsOnMethods = {"create", "testSubmitRequest"})
236 public void createWithWrongXmlSchema(String testName) throws Exception {
238 if (logger.isDebugEnabled()) {
239 logger.debug(testBanner(testName, CLASS_NAME));
242 setupCreateWithWrongXmlSchema();
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);
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);
257 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
258 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
259 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
263 // ---------------------------------------------------------------
264 // CRUD tests : READ tests
265 // ---------------------------------------------------------------
268 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
271 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
272 dependsOnMethods = {"create"})
273 public void read(String testName) throws Exception {
275 if (logger.isDebugEnabled()) {
276 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
291 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
292 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
293 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
305 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
308 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
309 dependsOnMethods = {"read"})
310 public void readNonExistent(String testName) throws Exception {
312 if (logger.isDebugEnabled()) {
313 logger.debug(testBanner(testName, CLASS_NAME));
316 setupReadNonExistent();
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();
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);
328 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
329 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
330 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
333 // ---------------------------------------------------------------
334 // CRUD tests : READ_LIST tests
335 // ---------------------------------------------------------------
338 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
341 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
342 dependsOnMethods = {"createList", "read"})
343 public void readList(String testName) throws Exception {
345 if (logger.isDebugEnabled()) {
346 logger.debug(testBanner(testName, CLASS_NAME));
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();
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);
362 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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();
372 for(RelationsCommonList.RelationListItem item : items){
373 logger.debug(testName + ": list-item[" + i + "] csid=" +
375 logger.debug(testName + ": list-item[" + i + "] URI=" +
386 // ---------------------------------------------------------------
387 // CRUD tests : UPDATE tests
388 // ---------------------------------------------------------------
392 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
395 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
396 dependsOnMethods = {"read"})
397 public void update(String testName) throws Exception {
399 if (logger.isDebugEnabled()) {
400 logger.debug(testBanner(testName, CLASS_NAME));
405 // Retrieve an existing resource that we can update.
406 RelationClient client = new RelationClient();
407 ClientResponse<MultipartInput> res =
408 client.read(knownResourceId);
409 if(logger.isDebugEnabled()){
410 logger.debug(testName + ": read status = " + res.getStatus());
412 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
413 if(logger.isDebugEnabled()){
414 logger.debug("Got object to update with ID: " + knownResourceId);
416 MultipartInput input = (MultipartInput) res.getEntity();
417 RelationsCommon relation = (RelationsCommon) extractPart(input,
418 client.getCommonPartName(), RelationsCommon.class);
419 Assert.assertNotNull(relation);
421 // Update the content of this resource.
422 relation.setDocumentId1("updated-" + relation.getDocumentId1());
423 relation.setDocumentType1("updated-" + relation.getDocumentType1());
424 relation.setDocumentId2("updated-" + relation.getDocumentId2());
425 relation.setDocumentType2("updated-" + relation.getDocumentType2());
426 relation.setPredicateDisplayName("updated-" + relation.getPredicateDisplayName());
427 if(logger.isDebugEnabled()){
428 logger.debug("updated object");
429 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
432 // Submit the request to the service and store the response.
433 MultipartOutput output = new MultipartOutput();
434 OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
435 commonPart.getHeaders().add("label", client.getCommonPartName());
436 res = client.update(knownResourceId, output);
437 int statusCode = res.getStatus();
439 // Check the status code of the response: does it match the expected response(s)?
440 if(logger.isDebugEnabled()){
441 logger.debug(testName + ": status = " + statusCode);
443 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
444 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
445 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447 input = (MultipartInput) res.getEntity();
448 RelationsCommon updatedObject = (RelationsCommon) extractPart(
449 input, client.getCommonPartName(),
450 RelationsCommon.class);
451 Assert.assertNotNull(updatedObject);
454 "Data in updated object did not match submitted data.";
456 updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
458 updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
460 updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
462 updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
464 updatedObject.getPredicateDisplayName(), relation.getPredicateDisplayName(), msg);
469 // Placeholders until the three tests below can be uncommented.
470 // See Issue CSPACE-401.
472 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
475 public void updateWithEmptyEntityBody(String testName) throws Exception {
476 //Should this test really be empty?
480 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
483 public void updateWithMalformedXml(String testName) throws Exception {
484 //Should this test really be empty?
488 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
491 public void updateWithWrongXmlSchema(String testName) throws Exception {
492 //Should this test really be empty?
497 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
498 dependsOnMethods = {"create", "update", "testSubmitRequest"})
499 public void updateWithEmptyEntityBody(String testName) throws Exception {
501 if (logger.isDebugEnabled()) {
502 logger.debug(testBanner(testName, CLASS_NAME));
505 setupUpdateWithEmptyEntityBody();
507 // Submit the request to the service and store the response.
508 String method = REQUEST_TYPE.httpMethodName();
509 String url = getResourceURL(knownResourceId);
510 String mediaType = MediaType.APPLICATION_XML;
511 final String entity = "";
512 int statusCode = submitRequest(method, url, mediaType, entity);
514 // Check the status code of the response: does it match
515 // the expected response(s)?
516 if(logger.isDebugEnabled()){
517 logger.debug(testName + ": url=" + url +
518 " status=" + statusCode);
520 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
521 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
522 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
526 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
527 dependsOnMethods = {"create", "update", "testSubmitRequest"})
528 public void updateWithMalformedXml(String testName) throws Exception {
530 if (logger.isDebugEnabled()) {
531 logger.debug(testBanner(testName, CLASS_NAME));
534 setupUpdateWithMalformedXml();
536 // Submit the request to the service and store the response.
537 String method = REQUEST_TYPE.httpMethodName();
538 String url = getResourceURL(knownResourceId);
539 String mediaType = MediaType.APPLICATION_XML;
540 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
541 int statusCode = submitRequest(method, url, mediaType, entity);
543 // Check the status code of the response: does it match
544 // the expected response(s)?
545 if(logger.isDebugEnabled()){
546 logger.debug(testName + ": url=" + url +
547 " status=" + statusCode);
549 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
550 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
551 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
555 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
556 dependsOnMethods = {"create", "update", "testSubmitRequest"})
557 public void updateWithWrongXmlSchema(String testName) throws Exception {
559 if (logger.isDebugEnabled()) {
560 logger.debug(testBanner(testName, CLASS_NAME));
563 setupUpdateWithWrongXmlSchema();
565 // Submit the request to the service and store the response.
566 String method = REQUEST_TYPE.httpMethodName();
567 String url = getResourceURL(knownResourceId);
568 String mediaType = MediaType.APPLICATION_XML;
569 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
570 int statusCode = submitRequest(method, url, mediaType, entity);
572 // Check the status code of the response: does it match
573 // the expected response(s)?
574 if(logger.isDebugEnabled()){
575 logger.debug(testName + ": url=" + url +
576 " status=" + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
585 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
588 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
589 dependsOnMethods = {"update", "testSubmitRequest"})
590 public void updateNonExistent(String testName) throws Exception {
592 if (logger.isDebugEnabled()) {
593 logger.debug(testBanner(testName, CLASS_NAME));
596 setupUpdateNonExistent();
598 // Submit the request to the service and store the response.
599 // Note: The ID used in this 'create' call may be arbitrary.
600 // The only relevant ID may be the one used in update(), below.
601 RelationClient client = new RelationClient();
602 MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
603 ClientResponse<MultipartInput> res =
604 client.update(NON_EXISTENT_ID, multipart);
605 int statusCode = res.getStatus();
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 if(logger.isDebugEnabled()){
610 logger.debug(testName + ": status = " + statusCode);
612 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
613 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
614 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617 // ---------------------------------------------------------------
618 // CRUD tests : DELETE tests
619 // ---------------------------------------------------------------
622 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
625 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
626 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
627 public void delete(String testName) throws Exception {
629 if (logger.isDebugEnabled()) {
630 logger.debug(testBanner(testName, CLASS_NAME));
635 // Submit the request to the service and store the response.
636 RelationClient client = new RelationClient();
637 ClientResponse<Response> res = client.delete(knownResourceId);
638 int statusCode = res.getStatus();
640 // Check the status code of the response: does it match
641 // the expected response(s)?
642 if(logger.isDebugEnabled()){
643 logger.debug(testName + ": status = " + statusCode);
645 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
655 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
656 dependsOnMethods = {"delete"})
657 public void deleteNonExistent(String testName) throws Exception {
659 if (logger.isDebugEnabled()) {
660 logger.debug(testBanner(testName, CLASS_NAME));
663 setupDeleteNonExistent();
665 // Submit the request to the service and store the response.
666 RelationClient client = new RelationClient();
667 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
668 int statusCode = res.getStatus();
670 // Check the status code of the response: does it match
671 // the expected response(s)?
672 if(logger.isDebugEnabled()){
673 logger.debug(testName + ": status = " + statusCode);
675 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
676 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
677 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
680 // ---------------------------------------------------------------
681 // RELATE_OBJECT tests
682 // ---------------------------------------------------------------
686 @Test(dependsOnMethods = {"create"})
687 public void relateObjects() {
688 //Should this test really be empty?
691 // ---------------------------------------------------------------
692 // Utility tests : tests of code used in tests above
693 // ---------------------------------------------------------------
695 * Tests the code for manually submitting data that is used by several
696 * of the methods above.
698 @Test(dependsOnMethods = {"create", "read"})
699 public void testSubmitRequest() {
703 // Submit the request to the service and store the response.
704 String method = ServiceRequestType.READ.httpMethodName();
705 String url = getResourceURL(knownResourceId);
706 int statusCode = submitRequest(method, url);
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if(logger.isDebugEnabled()){
711 logger.debug("testSubmitRequest: url=" + url +
712 " status=" + statusCode);
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
717 // ---------------------------------------------------------------
718 // Utility methods used by tests above
719 // ---------------------------------------------------------------
721 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
724 public String getServicePathComponent() {
725 return SERVICE_PATH_COMPONENT;
729 * Creates the relation instance.
731 * @param identifier the identifier
732 * @return the multipart output
734 private MultipartOutput createRelationInstance(String identifier) {
735 RelationsCommon relation = new RelationsCommon();
736 fillRelation(relation, identifier);
738 MultipartOutput multipart = new MultipartOutput();
739 OutputPart commonPart =
740 multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
741 commonPart.getHeaders().add("label", new RelationClient().getCommonPartName());
742 if(logger.isDebugEnabled()){
743 logger.debug("to be created, relation common");
744 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
750 * Fills the relation.
752 * @param relation the relation
753 * @param identifier the identifier
755 private void fillRelation(RelationsCommon relation, String identifier) {
756 fillRelation(relation, "Subject-" + identifier,
757 "SubjectType-" + identifier + "-type",
758 "Object-" + identifier,
759 "ObjectType-" + identifier + "-type",
760 RelationshipType.COLLECTIONOBJECT_INTAKE,
761 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
765 * Fills the relation.
767 * @param relation the relation
768 * @param documentId1 the document id1
769 * @param documentType1 the document type1
770 * @param documentId2 the document id2
771 * @param documentType2 the document type2
774 private void fillRelation(RelationsCommon relation,
775 String documentId1, String documentType1,
776 String documentId2, String documentType2,
778 String rtDisplayName) {
779 relation.setDocumentId1(documentId1);
780 relation.setDocumentType1(documentType1);
781 relation.setDocumentId2(documentId2);
782 relation.setDocumentType2(documentType2);
784 relation.setRelationshipType(rt);
785 relation.setPredicateDisplayName(rtDisplayName);