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.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
33 import org.collectionspace.services.PersonJAXBSchema;
34 import org.collectionspace.services.client.CollectionSpaceClient;
35 import org.collectionspace.services.client.PayloadInputPart;
36 import org.collectionspace.services.client.PayloadOutputPart;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.client.PoxPayloadIn;
40 import org.collectionspace.services.client.PoxPayloadOut;
41 import org.collectionspace.services.client.RelationClient;
42 import org.collectionspace.services.jaxb.AbstractCommonList;
43 import org.collectionspace.services.relation.RelationsCommon;
44 import org.collectionspace.services.relation.RelationsCommonList;
45 import org.collectionspace.services.relation.RelationshipType;
47 import org.jboss.resteasy.client.ClientResponse;
49 import org.testng.Assert;
50 import org.testng.annotations.Test;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
56 * RelationServiceTest, carries out tests against a
57 * deployed and running Relation Service.
59 * $LastChangedRevision$
62 public class RelationServiceTest extends AbstractServiceTestImpl {
65 private final String CLASS_NAME = RelationServiceTest.class.getName();
66 private final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
67 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
68 private List<String> personIdsCreated = new ArrayList<String>();
69 private String samSubjectPersonCSID = null;
70 private String oliveObjectPersonCSID = null;
71 private String samSubjectRefName = null;
72 private String oliveObjectRefName = null;
73 private String personAuthCSID = null;
74 private String personShortId = PERSON_AUTHORITY_NAME;
77 /** The SERVICE path component. */
78 final String SERVICE_PATH_COMPONENT = "relations";
80 /** The known resource id. */
81 private String knownResourceId = null;
84 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
87 protected CollectionSpaceClient getClientInstance() {
88 return new RelationClient();
92 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
95 protected AbstractCommonList getAbstractCommonList(
96 ClientResponse<AbstractCommonList> response) {
97 return response.getEntity(RelationsCommonList.class);
100 // ---------------------------------------------------------------
101 // CRUD tests : CREATE tests
102 // ---------------------------------------------------------------
105 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
107 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
109 public void create(String testName) throws Exception {
111 if (logger.isDebugEnabled()) {
112 logger.debug(testBanner(testName, CLASS_NAME));
114 // Perform setup, such as initializing the type of service request
115 // (e.g. CREATE, DELETE), its valid and expected status codes, and
116 // its associated HTTP method name (e.g. POST, DELETE).
120 // Submit the request to the service and store the response.
121 RelationClient client = new RelationClient();
122 String identifier = createIdentifier();
123 PoxPayloadOut multipart = createRelationInstance(identifier);
124 ClientResponse<Response> res = client.create(multipart);
125 int statusCode = res.getStatus();
127 // Check the status code of the response: does it match
128 // the expected response(s)?
130 // Does it fall within the set of valid status codes?
131 // Does it exactly match the expected status code?
132 if(logger.isDebugEnabled()){
133 logger.debug(testName + ": status = " + statusCode);
135 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
136 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
137 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
139 // Store the ID returned from the first resource created
140 // for additional tests below.
141 if (knownResourceId == null){
142 knownResourceId = extractId(res);
143 if (logger.isDebugEnabled()) {
144 logger.debug(testName + ": knownResourceId=" + knownResourceId);
148 // Store the IDs from every resource created by tests,
149 // so they can be deleted after tests have been run.
150 allResourceIdsCreated.add(extractId(res));
154 * Creates the person refs.
156 protected void createPersonRefs() {
157 PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
158 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
159 PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
160 ClientResponse<Response> res = personAuthClient.create(multipart);
161 int statusCode = res.getStatus();
163 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
164 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
165 Assert.assertEquals(statusCode, STATUS_CREATED);
166 personAuthCSID = extractId(res);
168 String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
170 String csid = createPerson("Sam", "Subject", "samSubject", authRefName);
171 Assert.assertNotNull(csid);
172 samSubjectPersonCSID = csid;
173 samSubjectRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
174 Assert.assertNotNull(samSubjectRefName);
175 personIdsCreated.add(csid);
177 csid = createPerson("Olive", "Object", "oliveObject", authRefName);
178 Assert.assertNotNull(csid);
179 oliveObjectRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
180 oliveObjectPersonCSID = csid;
181 Assert.assertNotNull(oliveObjectRefName);
182 personIdsCreated.add(csid);
185 protected String createPerson(String firstName, String surName, String shortId, String authRefName) {
186 PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
187 Map<String, String> personInfo = new HashMap<String, String>();
188 personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
189 personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
190 personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
191 PoxPayloadOut multipart =
192 PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
193 authRefName, personInfo, personAuthClient.getItemCommonPartName());
194 ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
195 int statusCode = res.getStatus();
197 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
198 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
199 Assert.assertEquals(statusCode, STATUS_CREATED);
200 return extractId(res);
206 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
210 dependsOnMethods = {"create"})
211 public void createList(String testName) throws Exception {
212 for(int i = 0; i < 3; i++){
217 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
218 dependsOnMethods = {"create"})
219 public void createWithSelfRelation(String testName) throws Exception {
221 if (logger.isDebugEnabled()) {
222 logger.debug(testBanner(testName, CLASS_NAME));
225 setupCreateWithInvalidBody();
227 // Submit the request to the service and store the response.
228 RelationClient client = new RelationClient();
229 String identifier = createIdentifier();
230 RelationsCommon relationsCommon = createRelationsCommon(identifier);
231 // Make the subject ID equal to the object ID
232 relationsCommon.setSubjectCsid(relationsCommon.getObjectCsid());
233 PoxPayloadOut multipart = createRelationInstance(relationsCommon);
234 ClientResponse<Response> res = client.create(multipart);
235 int statusCode = res.getStatus();
237 // Check the status code of the response: does it match
238 // the expected response(s)?
240 // Does it fall within the set of valid status codes?
241 // Does it exactly match the expected status code?
242 if(logger.isDebugEnabled()){
243 logger.debug(testName + ": status = " + statusCode);
245 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
246 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
247 Assert.assertEquals(statusCode, STATUS_BAD_REQUEST); //should be an error: same objectID and subjectID are not allowed by validator.
251 // Placeholders until the three tests below can be uncommented.
252 // See Issue CSPACE-401.
254 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
257 public void createWithEmptyEntityBody(String testName) throws Exception {
258 //Should this test really be empty?
262 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
265 public void createWithMalformedXml(String testName) throws Exception {
266 //Should this test really be empty?
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
273 public void createWithWrongXmlSchema(String testName) throws Exception {
274 //Should this test really be empty?
279 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
280 dependsOnMethods = {"create", "testSubmitRequest"})
281 public void createWithEmptyEntityBody(String testName) throws Exception {
283 if (logger.isDebugEnabled()) {
284 logger.debug(testBanner(testName, CLASS_NAME));
287 setupCreateWithEmptyEntityBody();
289 // Submit the request to the service and store the response.
290 String method = REQUEST_TYPE.httpMethodName();
291 String url = getServiceRootURL();
292 String mediaType = MediaType.APPLICATION_XML;
293 final String entity = "";
294 int statusCode = submitRequest(method, url, mediaType, entity);
296 // Check the status code of the response: does it match
297 // the expected response(s)?
298 if(logger.isDebugEnabled()){
299 logger.debug(testName + ": url=" + url +
300 " status=" + statusCode);
302 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
303 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
304 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
308 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
309 dependsOnMethods = {"create", "testSubmitRequest"})
310 public void createWithMalformedXml(String testName) throws Exception {
312 if (logger.isDebugEnabled()) {
313 logger.debug(testBanner(testName, CLASS_NAME));
316 setupCreateWithMalformedXml();
318 // Submit the request to the service and store the response.
319 String method = REQUEST_TYPE.httpMethodName();
320 String url = getServiceRootURL();
321 String mediaType = MediaType.APPLICATION_XML;
322 final String entity = MALFORMED_XML_DATA; // Constant from base class.
323 int statusCode = submitRequest(method, url, mediaType, entity);
325 // Check the status code of the response: does it match
326 // the expected response(s)?
327 if(logger.isDebugEnabled()){
328 logger.debug(testName + ": url=" + url +
329 " status=" + statusCode);
331 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
332 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
333 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
337 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
338 dependsOnMethods = {"create", "testSubmitRequest"})
339 public void createWithWrongXmlSchema(String testName) throws Exception {
341 if (logger.isDebugEnabled()) {
342 logger.debug(testBanner(testName, CLASS_NAME));
345 setupCreateWithWrongXmlSchema();
347 // Submit the request to the service and store the response.
348 String method = REQUEST_TYPE.httpMethodName();
349 String url = getServiceRootURL();
350 String mediaType = MediaType.APPLICATION_XML;
351 final String entity = WRONG_XML_SCHEMA_DATA;
352 int statusCode = submitRequest(method, url, mediaType, entity);
354 // Check the status code of the response: does it match
355 // the expected response(s)?
356 if(logger.isDebugEnabled()){
357 logger.debug(testName + ": url=" + url +
358 " status=" + statusCode);
360 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
361 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
362 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
366 // ---------------------------------------------------------------
367 // CRUD tests : READ tests
368 // ---------------------------------------------------------------
371 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
374 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
375 dependsOnMethods = {"create"})
376 public void read(String testName) throws Exception {
378 if (logger.isDebugEnabled()) {
379 logger.debug(testBanner(testName, CLASS_NAME));
384 // Submit the request to the service and store the response.
385 RelationClient client = new RelationClient();
386 ClientResponse<String> res = client.read(knownResourceId);
387 assertStatusCode(res, testName);
389 // Get the common part from the response and check that it is not null.
390 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
391 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
392 RelationsCommon relationCommon = null;
393 if (payloadInputPart != null) {
394 relationCommon = (RelationsCommon) payloadInputPart.getBody();
396 Assert.assertNotNull(relationCommon);
402 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
405 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
406 dependsOnMethods = {"read"})
407 public void readNonExistent(String testName) throws Exception {
409 if (logger.isDebugEnabled()) {
410 logger.debug(testBanner(testName, CLASS_NAME));
413 setupReadNonExistent();
415 // Submit the request to the service and store the response.
416 RelationClient client = new RelationClient();
417 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
418 int statusCode = res.getStatus();
420 // Check the status code of the response: does it match
421 // the expected response(s)?
422 if(logger.isDebugEnabled()){
423 logger.debug(testName + ": status = " + statusCode);
425 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
426 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
427 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
430 // ---------------------------------------------------------------
431 // CRUD tests : READ_LIST tests
432 // ---------------------------------------------------------------
435 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
438 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
439 dependsOnMethods = {"createList", "read"})
440 public void readList(String testName) throws Exception {
442 if (logger.isDebugEnabled()) {
443 logger.debug(testBanner(testName, CLASS_NAME));
448 // Submit the request to the service and store the response.
449 RelationClient client = new RelationClient();
450 ClientResponse<RelationsCommonList> res = client.readList();
451 assertStatusCode(res, testName);
452 RelationsCommonList list = res.getEntity();
454 // Optionally output additional data about list members for debugging.
455 boolean iterateThroughList = false;
456 if(iterateThroughList && logger.isDebugEnabled()){
457 List<RelationsCommonList.RelationListItem> items =
458 list.getRelationListItem();
460 for(RelationsCommonList.RelationListItem item : items){
461 logger.debug(testName + ": list-item[" + i + "] csid=" +
463 logger.debug(testName + ": list-item[" + i + "] URI=" +
472 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
473 dependsOnMethods = {"createList", "read"})
474 public void readListPaginated(String testName) throws Exception {
476 if (logger.isDebugEnabled()) {
477 logger.debug(testBanner(testName, CLASS_NAME));
484 RelationClient client = new RelationClient();
485 ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
493 RelationsCommonList list = res.getEntity();
494 assertStatusCode(res, testName);
496 // Optionally output additional data about list members for debugging.
497 boolean iterateThroughList = false;
498 if(iterateThroughList && logger.isDebugEnabled()){
499 List<RelationsCommonList.RelationListItem> items =
500 list.getRelationListItem();
502 for(RelationsCommonList.RelationListItem item : items){
503 logger.debug(testName + ": list-item[" + i + "] csid=" +
505 logger.debug(testName + ": list-item[" + i + "] URI=" +
517 // ---------------------------------------------------------------
518 // CRUD tests : UPDATE tests
519 // ---------------------------------------------------------------
523 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
526 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
527 dependsOnMethods = {"read"})
528 public void update(String testName) throws Exception {
530 logger.debug(testBanner(testName, CLASS_NAME));
534 // Retrieve an existing resource that we can update.
535 RelationClient client = new RelationClient();
536 ClientResponse<String> res = client.read(knownResourceId);
537 assertStatusCode(res, testName);
538 logger.debug("Got object to update with ID: " + knownResourceId);
540 // Extract the common part and verify that it is not null.
541 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
542 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
543 RelationsCommon relationCommon = null;
544 if (payloadInputPart != null) {
545 relationCommon = (RelationsCommon) payloadInputPart.getBody();
547 Assert.assertNotNull(relationCommon);
548 logger.trace("object before update");
549 logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
551 String newSubjectDocType = relationCommon.getObjectDocumentType();
552 String newObjectDocType = relationCommon.getSubjectDocumentType();
553 String newSubjectId = relationCommon.getObjectCsid();
554 String newObjectId = relationCommon.getSubjectCsid();
555 // Update the content of this resource, inverting subject and object
556 relationCommon.setSubjectCsid(newSubjectId);
557 relationCommon.setSubjectDocumentType("Hooey");
558 relationCommon.setObjectCsid(newObjectId);
559 relationCommon.setObjectDocumentType("Fooey");
560 relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
561 logger.trace("updated object to send");
562 logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
564 // Submit the request containing the updated resource to the service
565 // and store the response.
566 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
567 PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
568 commonPart.setLabel(client.getCommonPartName());
569 res = client.update(knownResourceId, output);
570 assertStatusCode(res, testName);
572 // Extract the common part of the updated resource and verify that it is not null.
573 input = new PoxPayloadIn(res.getEntity());
574 RelationsCommon updatedRelationCommon =
575 (RelationsCommon) extractPart(input,
576 client.getCommonPartName(), RelationsCommon.class);
577 Assert.assertNotNull(updatedRelationCommon);
579 logger.trace("updated object as received");
580 logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class));
583 "Data in updated object did not match submitted data.";
585 "Data in updated object was not correctly computed.";
587 updatedRelationCommon.getSubjectCsid(), newSubjectId, msg);
589 updatedRelationCommon.getSubjectDocumentType(), newSubjectDocType, msg2);
591 updatedRelationCommon.getObjectCsid(), newObjectId, msg);
593 updatedRelationCommon.getObjectDocumentType(), newObjectDocType, msg2);
595 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
600 // Placeholders until the three tests below can be uncommented.
601 // See Issue CSPACE-401.
603 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
606 public void updateWithEmptyEntityBody(String testName) throws Exception {
607 //Should this test really be empty?
611 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
614 public void updateWithMalformedXml(String testName) throws Exception {
615 //Should this test really be empty?
619 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
622 public void updateWithWrongXmlSchema(String testName) throws Exception {
623 //Should this test really be empty?
628 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
629 dependsOnMethods = {"create", "update", "testSubmitRequest"})
630 public void updateWithEmptyEntityBody(String testName) throws Exception {
632 if (logger.isDebugEnabled()) {
633 logger.debug(testBanner(testName, CLASS_NAME));
636 setupUpdateWithEmptyEntityBody();
638 // Submit the request to the service and store the response.
639 String method = REQUEST_TYPE.httpMethodName();
640 String url = getResourceURL(knownResourceId);
641 String mediaType = MediaType.APPLICATION_XML;
642 final String entity = "";
643 int statusCode = submitRequest(method, url, mediaType, entity);
645 // Check the status code of the response: does it match
646 // the expected response(s)?
647 if(logger.isDebugEnabled()){
648 logger.debug(testName + ": url=" + url +
649 " status=" + statusCode);
651 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
657 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
658 dependsOnMethods = {"create", "update", "testSubmitRequest"})
659 public void updateWithMalformedXml(String testName) throws Exception {
661 if (logger.isDebugEnabled()) {
662 logger.debug(testBanner(testName, CLASS_NAME));
665 setupUpdateWithMalformedXml();
667 // Submit the request to the service and store the response.
668 String method = REQUEST_TYPE.httpMethodName();
669 String url = getResourceURL(knownResourceId);
670 String mediaType = MediaType.APPLICATION_XML;
671 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
672 int statusCode = submitRequest(method, url, mediaType, entity);
674 // Check the status code of the response: does it match
675 // the expected response(s)?
676 if(logger.isDebugEnabled()){
677 logger.debug(testName + ": url=" + url +
678 " status=" + statusCode);
680 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
686 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
687 dependsOnMethods = {"create", "update", "testSubmitRequest"})
688 public void updateWithWrongXmlSchema(String testName) throws Exception {
690 if (logger.isDebugEnabled()) {
691 logger.debug(testBanner(testName, CLASS_NAME));
694 setupUpdateWithWrongXmlSchema();
696 // Submit the request to the service and store the response.
697 String method = REQUEST_TYPE.httpMethodName();
698 String url = getResourceURL(knownResourceId);
699 String mediaType = MediaType.APPLICATION_XML;
700 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
701 int statusCode = submitRequest(method, url, mediaType, entity);
703 // Check the status code of the response: does it match
704 // the expected response(s)?
705 if(logger.isDebugEnabled()){
706 logger.debug(testName + ": url=" + url +
707 " status=" + statusCode);
709 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
710 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
711 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
716 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
719 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
720 dependsOnMethods = {"update", "testSubmitRequest"})
721 public void updateNonExistent(String testName) throws Exception {
723 if (logger.isDebugEnabled()) {
724 logger.debug(testBanner(testName, CLASS_NAME));
727 setupUpdateNonExistent();
729 // Submit the request to the service and store the response.
730 // Note: The ID used in this 'create' call may be arbitrary.
731 // The only relevant ID may be the one used in update(), below.
732 RelationClient client = new RelationClient();
733 PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
734 ClientResponse<String> res =
735 client.update(NON_EXISTENT_ID, multipart);
736 int statusCode = res.getStatus();
738 // Check the status code of the response: does it match
739 // the expected response(s)?
740 if(logger.isDebugEnabled()){
741 logger.debug(testName + ": status = " + statusCode);
743 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
744 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
745 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
748 // ---------------------------------------------------------------
749 // CRUD tests : DELETE tests
750 // ---------------------------------------------------------------
753 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
756 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
757 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
758 public void delete(String testName) throws Exception {
760 if (logger.isDebugEnabled()) {
761 logger.debug(testBanner(testName, CLASS_NAME));
766 // Submit the request to the service and store the response.
767 RelationClient client = new RelationClient();
768 ClientResponse<Response> res = client.delete(knownResourceId);
769 int statusCode = res.getStatus();
771 // Check the status code of the response: does it match
772 // the expected response(s)?
773 if(logger.isDebugEnabled()){
774 logger.debug(testName + ": status = " + statusCode);
776 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
777 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
778 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
783 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
786 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
787 dependsOnMethods = {"delete"})
788 public void deleteNonExistent(String testName) throws Exception {
790 if (logger.isDebugEnabled()) {
791 logger.debug(testBanner(testName, CLASS_NAME));
794 setupDeleteNonExistent();
796 // Submit the request to the service and store the response.
797 RelationClient client = new RelationClient();
798 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
799 int statusCode = res.getStatus();
801 // Check the status code of the response: does it match
802 // the expected response(s)?
803 if(logger.isDebugEnabled()){
804 logger.debug(testName + ": status = " + statusCode);
806 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
807 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
808 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
811 // ---------------------------------------------------------------
812 // RELATE_OBJECT tests
813 // ---------------------------------------------------------------
817 @Test(dependsOnMethods = {"create"})
818 public void relateObjects() {
819 //Should this test really be empty?
822 // ---------------------------------------------------------------
823 // Utility tests : tests of code used in tests above
824 // ---------------------------------------------------------------
826 * Tests the code for manually submitting data that is used by several
827 * of the methods above.
829 @Test(dependsOnMethods = {"create", "read"})
830 public void testSubmitRequest() {
834 // Submit the request to the service and store the response.
835 String method = ServiceRequestType.READ.httpMethodName();
836 String url = getResourceURL(knownResourceId);
837 int statusCode = submitRequest(method, url);
839 // Check the status code of the response: does it match
840 // the expected response(s)?
841 if(logger.isDebugEnabled()){
842 logger.debug("testSubmitRequest: url=" + url +
843 " status=" + statusCode);
845 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
848 // ---------------------------------------------------------------
849 // Utility methods used by tests above
850 // ---------------------------------------------------------------
852 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
855 public String getServicePathComponent() {
856 return SERVICE_PATH_COMPONENT;
859 private RelationsCommon createRelationsCommon(String identifier) {
860 RelationsCommon relationCommon = new RelationsCommon();
861 fillRelation(relationCommon, identifier);
862 return relationCommon;
865 private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
866 PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
867 PayloadOutputPart commonPart =
868 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
869 commonPart.setLabel(new RelationClient().getCommonPartName());
870 if(logger.isDebugEnabled()){
871 logger.debug("to be created, relation common");
872 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
878 * Creates the relation instance.
880 * @param identifier the identifier
881 * @return the multipart output
883 private PoxPayloadOut createRelationInstance(String identifier) {
884 RelationsCommon relation = createRelationsCommon(identifier);
885 PoxPayloadOut result = createRelationInstance(relation);
890 * Fills the relation.
892 * @param relationCommon the relation
893 * @param identifier the identifier
895 private void fillRelation(RelationsCommon relationCommon, String identifier) {
896 fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null,
897 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
898 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
902 * Fills the relation.
904 * @param relationCommon the relation
905 * @param subjectCsid the subject document id
906 * @param subjectDocumentType the subject document type
907 * @param objectCsid the object document id
908 * @param objectDocumentType the object document type
911 private void fillRelation(RelationsCommon relationCommon,
912 String subjectCsid, String subjectDocumentType,
913 String objectCsid, String objectDocumentType,
915 String rtDisplayName) {
916 relationCommon.setSubjectCsid(subjectCsid);
917 relationCommon.setSubjectDocumentType(subjectDocumentType);
918 relationCommon.setObjectCsid(objectCsid);
919 relationCommon.setObjectDocumentType(objectDocumentType);
921 relationCommon.setRelationshipType(rt);
922 relationCommon.setPredicateDisplayName(rtDisplayName);
926 protected String getServiceName() {
927 return RelationClient.SERVICE_NAME;