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.setDocumentId1(relationsCommon.getDocumentId2());
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 int statusCode = res.getStatus();
389 // Check the status code of the response: does it match
390 // the expected response(s)?
391 if(logger.isDebugEnabled()){
392 logger.debug(testName + ": status = " + statusCode);
394 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
398 // Get the common part from the response and check that it is not null.
399 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
400 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
401 RelationsCommon relationCommon = null;
402 if (payloadInputPart != null) {
403 relationCommon = (RelationsCommon) payloadInputPart.getBody();
405 Assert.assertNotNull(relationCommon);
411 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
414 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
415 dependsOnMethods = {"read"})
416 public void readNonExistent(String testName) throws Exception {
418 if (logger.isDebugEnabled()) {
419 logger.debug(testBanner(testName, CLASS_NAME));
422 setupReadNonExistent();
424 // Submit the request to the service and store the response.
425 RelationClient client = new RelationClient();
426 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
427 int statusCode = res.getStatus();
429 // Check the status code of the response: does it match
430 // the expected response(s)?
431 if(logger.isDebugEnabled()){
432 logger.debug(testName + ": status = " + statusCode);
434 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
435 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
436 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
439 // ---------------------------------------------------------------
440 // CRUD tests : READ_LIST tests
441 // ---------------------------------------------------------------
444 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
447 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
448 dependsOnMethods = {"createList", "read"})
449 public void readList(String testName) throws Exception {
451 if (logger.isDebugEnabled()) {
452 logger.debug(testBanner(testName, CLASS_NAME));
457 // Submit the request to the service and store the response.
458 RelationClient client = new RelationClient();
459 ClientResponse<RelationsCommonList> res = client.readList();
460 RelationsCommonList list = res.getEntity();
461 int statusCode = res.getStatus();
463 // Check the status code of the response: does it match
464 // the expected response(s)?
465 if(logger.isDebugEnabled()){
466 logger.debug(testName + ": status = " + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472 // Optionally output additional data about list members for debugging.
473 boolean iterateThroughList = false;
474 if(iterateThroughList && logger.isDebugEnabled()){
475 List<RelationsCommonList.RelationListItem> items =
476 list.getRelationListItem();
478 for(RelationsCommonList.RelationListItem item : items){
479 logger.debug(testName + ": list-item[" + i + "] csid=" +
481 logger.debug(testName + ": list-item[" + i + "] URI=" +
490 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
491 dependsOnMethods = {"createList", "read"})
492 public void readListPaginated(String testName) throws Exception {
494 if (logger.isDebugEnabled()) {
495 logger.debug(testBanner(testName, CLASS_NAME));
502 RelationClient client = new RelationClient();
503 ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
511 RelationsCommonList list = res.getEntity();
512 int statusCode = res.getStatus();
514 // Check the status code of the response: does it match
515 // the expected response(s)?
516 if(logger.isDebugEnabled()){
517 logger.debug(testName + ": status = " + statusCode);
519 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
520 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
521 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
523 // Optionally output additional data about list members for debugging.
524 boolean iterateThroughList = false;
525 if(iterateThroughList && logger.isDebugEnabled()){
526 List<RelationsCommonList.RelationListItem> items =
527 list.getRelationListItem();
529 for(RelationsCommonList.RelationListItem item : items){
530 logger.debug(testName + ": list-item[" + i + "] csid=" +
532 logger.debug(testName + ": list-item[" + i + "] URI=" +
544 // ---------------------------------------------------------------
545 // CRUD tests : UPDATE tests
546 // ---------------------------------------------------------------
550 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
553 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
554 dependsOnMethods = {"read"})
555 public void update(String testName) throws Exception {
557 logger.debug(testBanner(testName, CLASS_NAME));
561 // Retrieve an existing resource that we can update.
562 RelationClient client = new RelationClient();
563 ClientResponse<String> res = client.read(knownResourceId);
564 logger.debug(testName + ": read status = " + res.getStatus());
565 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
566 logger.debug("Got object to update with ID: " + knownResourceId);
568 // Extract the common part and verify that it is not null.
569 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
570 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
571 RelationsCommon relationCommon = null;
572 if (payloadInputPart != null) {
573 relationCommon = (RelationsCommon) payloadInputPart.getBody();
575 Assert.assertNotNull(relationCommon);
576 logger.trace("object before update");
577 logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
579 String newSubjectDocType = relationCommon.getObjectDocumentType();
580 String newObjectDocType = relationCommon.getSubjectDocumentType();
581 String newSubjectId = relationCommon.getObjectCsid();
582 String newObjectId = relationCommon.getSubjectCsid();
583 // Update the content of this resource, inverting subject and object
584 relationCommon.setSubjectCsid(newSubjectId);
585 relationCommon.setSubjectDocumentType("Hooey");
586 relationCommon.setObjectCsid(newObjectId);
587 relationCommon.setObjectDocumentType("Fooey");
588 relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
589 logger.trace("updated object to send");
590 logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class));
592 // Submit the request containing the updated resource to the service
593 // and store the response.
594 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
595 PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
596 commonPart.setLabel(client.getCommonPartName());
597 res = client.update(knownResourceId, output);
598 int statusCode = res.getStatus();
600 // Check the status code of the response: does it match the expected response(s)?
601 logger.debug(testName + ": status = " + statusCode);
602 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
606 // Extract the common part of the updated resource and verify that it is not null.
607 input = new PoxPayloadIn(res.getEntity());
608 RelationsCommon updatedRelationCommon =
609 (RelationsCommon) extractPart(input,
610 client.getCommonPartName(), RelationsCommon.class);
611 Assert.assertNotNull(updatedRelationCommon);
613 logger.trace("updated object as received");
614 logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class));
617 "Data in updated object did not match submitted data.";
619 "Data in updated object was not correctly computed.";
621 updatedRelationCommon.getDocumentId1(), newSubjectId, msg);
623 updatedRelationCommon.getDocumentType1(), newSubjectDocType, msg2);
625 updatedRelationCommon.getDocumentId2(), newObjectId, msg);
627 updatedRelationCommon.getDocumentType2(), newObjectDocType, msg2);
629 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
634 // Placeholders until the three tests below can be uncommented.
635 // See Issue CSPACE-401.
637 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
640 public void updateWithEmptyEntityBody(String testName) throws Exception {
641 //Should this test really be empty?
645 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
648 public void updateWithMalformedXml(String testName) throws Exception {
649 //Should this test really be empty?
653 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
656 public void updateWithWrongXmlSchema(String testName) throws Exception {
657 //Should this test really be empty?
662 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
663 dependsOnMethods = {"create", "update", "testSubmitRequest"})
664 public void updateWithEmptyEntityBody(String testName) throws Exception {
666 if (logger.isDebugEnabled()) {
667 logger.debug(testBanner(testName, CLASS_NAME));
670 setupUpdateWithEmptyEntityBody();
672 // Submit the request to the service and store the response.
673 String method = REQUEST_TYPE.httpMethodName();
674 String url = getResourceURL(knownResourceId);
675 String mediaType = MediaType.APPLICATION_XML;
676 final String entity = "";
677 int statusCode = submitRequest(method, url, mediaType, entity);
679 // Check the status code of the response: does it match
680 // the expected response(s)?
681 if(logger.isDebugEnabled()){
682 logger.debug(testName + ": url=" + url +
683 " status=" + statusCode);
685 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
686 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
687 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
691 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
692 dependsOnMethods = {"create", "update", "testSubmitRequest"})
693 public void updateWithMalformedXml(String testName) throws Exception {
695 if (logger.isDebugEnabled()) {
696 logger.debug(testBanner(testName, CLASS_NAME));
699 setupUpdateWithMalformedXml();
701 // Submit the request to the service and store the response.
702 String method = REQUEST_TYPE.httpMethodName();
703 String url = getResourceURL(knownResourceId);
704 String mediaType = MediaType.APPLICATION_XML;
705 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
706 int statusCode = submitRequest(method, url, mediaType, entity);
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if(logger.isDebugEnabled()){
711 logger.debug(testName + ": url=" + url +
712 " status=" + statusCode);
714 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
715 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
716 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
721 dependsOnMethods = {"create", "update", "testSubmitRequest"})
722 public void updateWithWrongXmlSchema(String testName) throws Exception {
724 if (logger.isDebugEnabled()) {
725 logger.debug(testBanner(testName, CLASS_NAME));
728 setupUpdateWithWrongXmlSchema();
730 // Submit the request to the service and store the response.
731 String method = REQUEST_TYPE.httpMethodName();
732 String url = getResourceURL(knownResourceId);
733 String mediaType = MediaType.APPLICATION_XML;
734 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
735 int statusCode = submitRequest(method, url, mediaType, entity);
737 // Check the status code of the response: does it match
738 // the expected response(s)?
739 if(logger.isDebugEnabled()){
740 logger.debug(testName + ": url=" + url +
741 " status=" + statusCode);
743 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
744 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
745 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
750 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
753 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754 dependsOnMethods = {"update", "testSubmitRequest"})
755 public void updateNonExistent(String testName) throws Exception {
757 if (logger.isDebugEnabled()) {
758 logger.debug(testBanner(testName, CLASS_NAME));
761 setupUpdateNonExistent();
763 // Submit the request to the service and store the response.
764 // Note: The ID used in this 'create' call may be arbitrary.
765 // The only relevant ID may be the one used in update(), below.
766 RelationClient client = new RelationClient();
767 PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
768 ClientResponse<String> res =
769 client.update(NON_EXISTENT_ID, multipart);
770 int statusCode = res.getStatus();
772 // Check the status code of the response: does it match
773 // the expected response(s)?
774 if(logger.isDebugEnabled()){
775 logger.debug(testName + ": status = " + statusCode);
777 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
778 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
779 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
782 // ---------------------------------------------------------------
783 // CRUD tests : DELETE tests
784 // ---------------------------------------------------------------
787 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
790 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
791 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
792 public void delete(String testName) throws Exception {
794 if (logger.isDebugEnabled()) {
795 logger.debug(testBanner(testName, CLASS_NAME));
800 // Submit the request to the service and store the response.
801 RelationClient client = new RelationClient();
802 ClientResponse<Response> res = client.delete(knownResourceId);
803 int statusCode = res.getStatus();
805 // Check the status code of the response: does it match
806 // the expected response(s)?
807 if(logger.isDebugEnabled()){
808 logger.debug(testName + ": status = " + statusCode);
810 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
811 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
812 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
817 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
820 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
821 dependsOnMethods = {"delete"})
822 public void deleteNonExistent(String testName) throws Exception {
824 if (logger.isDebugEnabled()) {
825 logger.debug(testBanner(testName, CLASS_NAME));
828 setupDeleteNonExistent();
830 // Submit the request to the service and store the response.
831 RelationClient client = new RelationClient();
832 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
833 int statusCode = res.getStatus();
835 // Check the status code of the response: does it match
836 // the expected response(s)?
837 if(logger.isDebugEnabled()){
838 logger.debug(testName + ": status = " + statusCode);
840 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
841 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
842 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
845 // ---------------------------------------------------------------
846 // RELATE_OBJECT tests
847 // ---------------------------------------------------------------
851 @Test(dependsOnMethods = {"create"})
852 public void relateObjects() {
853 //Should this test really be empty?
856 // ---------------------------------------------------------------
857 // Utility tests : tests of code used in tests above
858 // ---------------------------------------------------------------
860 * Tests the code for manually submitting data that is used by several
861 * of the methods above.
863 @Test(dependsOnMethods = {"create", "read"})
864 public void testSubmitRequest() {
868 // Submit the request to the service and store the response.
869 String method = ServiceRequestType.READ.httpMethodName();
870 String url = getResourceURL(knownResourceId);
871 int statusCode = submitRequest(method, url);
873 // Check the status code of the response: does it match
874 // the expected response(s)?
875 if(logger.isDebugEnabled()){
876 logger.debug("testSubmitRequest: url=" + url +
877 " status=" + statusCode);
879 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
882 // ---------------------------------------------------------------
883 // Utility methods used by tests above
884 // ---------------------------------------------------------------
886 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
889 public String getServicePathComponent() {
890 return SERVICE_PATH_COMPONENT;
893 private RelationsCommon createRelationsCommon(String identifier) {
894 RelationsCommon relationCommon = new RelationsCommon();
895 fillRelation(relationCommon, identifier);
896 return relationCommon;
899 private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
900 PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
901 PayloadOutputPart commonPart =
902 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
903 commonPart.setLabel(new RelationClient().getCommonPartName());
904 if(logger.isDebugEnabled()){
905 logger.debug("to be created, relation common");
906 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
912 * Creates the relation instance.
914 * @param identifier the identifier
915 * @return the multipart output
917 private PoxPayloadOut createRelationInstance(String identifier) {
918 RelationsCommon relation = createRelationsCommon(identifier);
919 PoxPayloadOut result = createRelationInstance(relation);
924 * Fills the relation.
926 * @param relationCommon the relation
927 * @param identifier the identifier
929 private void fillRelation(RelationsCommon relationCommon, String identifier) {
930 fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null,
931 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
932 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
936 * Fills the relation.
938 * @param relationCommon the relation
939 * @param documentId1 the document id1
940 * @param documentType1 the document type1
941 * @param documentId2 the document id2
942 * @param documentType2 the document type2
945 private void fillRelation(RelationsCommon relationCommon,
946 String documentId1, String documentType1,
947 String documentId2, String documentType2,
949 String rtDisplayName) {
950 relationCommon.setDocumentId1(documentId1);
951 relationCommon.setDocumentType1(documentType1);
952 relationCommon.setDocumentId2(documentId2);
953 relationCommon.setDocumentType2(documentType2);
955 relationCommon.setRelationshipType(rt);
956 relationCommon.setPredicateDisplayName(rtDisplayName);
960 protected String getServiceName() {
961 return RelationClient.SERVICE_NAME;