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 if (logger.isDebugEnabled()) {
558 logger.debug(testBanner(testName, CLASS_NAME));
563 // Retrieve an existing resource that we can update.
564 RelationClient client = new RelationClient();
565 ClientResponse<String> res = client.read(knownResourceId);
566 if(logger.isDebugEnabled()){
567 logger.debug(testName + ": read status = " + res.getStatus());
569 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
570 if(logger.isDebugEnabled()){
571 logger.debug("Got object to update with ID: " + knownResourceId);
574 // Extract the common part and verify that it is not null.
575 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
576 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
577 RelationsCommon relationCommon = null;
578 if (payloadInputPart != null) {
579 relationCommon = (RelationsCommon) payloadInputPart.getBody();
581 Assert.assertNotNull(relationCommon);
583 // Update the content of this resource.
584 relationCommon.setDocumentId1("updated-" + relationCommon.getDocumentId1());
585 relationCommon.setDocumentType1("updated-" + relationCommon.getDocumentType1());
586 relationCommon.setDocumentId2("updated-" + relationCommon.getDocumentId2());
587 relationCommon.setDocumentType2("updated-" + relationCommon.getDocumentType2());
588 relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
589 if(logger.isDebugEnabled()){
590 logger.debug("updated object");
591 logger.debug(objectAsXmlString(relationCommon, RelationsCommon.class));
594 // Submit the request containing the updated resource to the service
595 // and store the response.
596 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
597 PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
598 commonPart.setLabel(client.getCommonPartName());
599 res = client.update(knownResourceId, output);
600 int statusCode = res.getStatus();
602 // Check the status code of the response: does it match the expected response(s)?
603 if(logger.isDebugEnabled()){
604 logger.debug(testName + ": status = " + statusCode);
606 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
607 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
608 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 // Extract the common part of the updated resource and verify that it is not null.
611 input = new PoxPayloadIn(res.getEntity());
612 RelationsCommon updatedRelationCommon =
613 (RelationsCommon) extractPart(input,
614 client.getCommonPartName(), RelationsCommon.class);
615 Assert.assertNotNull(updatedRelationCommon);
618 "Data in updated object did not match submitted data.";
620 updatedRelationCommon.getDocumentId1(), relationCommon.getDocumentId1(), msg);
622 updatedRelationCommon.getDocumentType1(), relationCommon.getDocumentType1(), msg);
624 updatedRelationCommon.getDocumentId2(), relationCommon.getDocumentId2(), msg);
626 updatedRelationCommon.getDocumentType2(), relationCommon.getDocumentType2(), msg);
628 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
633 // Placeholders until the three tests below can be uncommented.
634 // See Issue CSPACE-401.
636 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
639 public void updateWithEmptyEntityBody(String testName) throws Exception {
640 //Should this test really be empty?
644 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
647 public void updateWithMalformedXml(String testName) throws Exception {
648 //Should this test really be empty?
652 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
655 public void updateWithWrongXmlSchema(String testName) throws Exception {
656 //Should this test really be empty?
661 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
662 dependsOnMethods = {"create", "update", "testSubmitRequest"})
663 public void updateWithEmptyEntityBody(String testName) throws Exception {
665 if (logger.isDebugEnabled()) {
666 logger.debug(testBanner(testName, CLASS_NAME));
669 setupUpdateWithEmptyEntityBody();
671 // Submit the request to the service and store the response.
672 String method = REQUEST_TYPE.httpMethodName();
673 String url = getResourceURL(knownResourceId);
674 String mediaType = MediaType.APPLICATION_XML;
675 final String entity = "";
676 int statusCode = submitRequest(method, url, mediaType, entity);
678 // Check the status code of the response: does it match
679 // the expected response(s)?
680 if(logger.isDebugEnabled()){
681 logger.debug(testName + ": url=" + url +
682 " status=" + statusCode);
684 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
685 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
686 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
690 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
691 dependsOnMethods = {"create", "update", "testSubmitRequest"})
692 public void updateWithMalformedXml(String testName) throws Exception {
694 if (logger.isDebugEnabled()) {
695 logger.debug(testBanner(testName, CLASS_NAME));
698 setupUpdateWithMalformedXml();
700 // Submit the request to the service and store the response.
701 String method = REQUEST_TYPE.httpMethodName();
702 String url = getResourceURL(knownResourceId);
703 String mediaType = MediaType.APPLICATION_XML;
704 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
705 int statusCode = submitRequest(method, url, mediaType, entity);
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if(logger.isDebugEnabled()){
710 logger.debug(testName + ": url=" + url +
711 " status=" + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
719 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
720 dependsOnMethods = {"create", "update", "testSubmitRequest"})
721 public void updateWithWrongXmlSchema(String testName) throws Exception {
723 if (logger.isDebugEnabled()) {
724 logger.debug(testBanner(testName, CLASS_NAME));
727 setupUpdateWithWrongXmlSchema();
729 // Submit the request to the service and store the response.
730 String method = REQUEST_TYPE.httpMethodName();
731 String url = getResourceURL(knownResourceId);
732 String mediaType = MediaType.APPLICATION_XML;
733 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
734 int statusCode = submitRequest(method, url, mediaType, entity);
736 // Check the status code of the response: does it match
737 // the expected response(s)?
738 if(logger.isDebugEnabled()){
739 logger.debug(testName + ": url=" + url +
740 " status=" + statusCode);
742 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
743 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
744 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
749 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
752 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
753 dependsOnMethods = {"update", "testSubmitRequest"})
754 public void updateNonExistent(String testName) throws Exception {
756 if (logger.isDebugEnabled()) {
757 logger.debug(testBanner(testName, CLASS_NAME));
760 setupUpdateNonExistent();
762 // Submit the request to the service and store the response.
763 // Note: The ID used in this 'create' call may be arbitrary.
764 // The only relevant ID may be the one used in update(), below.
765 RelationClient client = new RelationClient();
766 PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
767 ClientResponse<String> res =
768 client.update(NON_EXISTENT_ID, multipart);
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);
781 // ---------------------------------------------------------------
782 // CRUD tests : DELETE tests
783 // ---------------------------------------------------------------
786 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
789 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
790 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
791 public void delete(String testName) throws Exception {
793 if (logger.isDebugEnabled()) {
794 logger.debug(testBanner(testName, CLASS_NAME));
799 // Submit the request to the service and store the response.
800 RelationClient client = new RelationClient();
801 ClientResponse<Response> res = client.delete(knownResourceId);
802 int statusCode = res.getStatus();
804 // Check the status code of the response: does it match
805 // the expected response(s)?
806 if(logger.isDebugEnabled()){
807 logger.debug(testName + ": status = " + statusCode);
809 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
810 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
811 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
816 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
819 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
820 dependsOnMethods = {"delete"})
821 public void deleteNonExistent(String testName) throws Exception {
823 if (logger.isDebugEnabled()) {
824 logger.debug(testBanner(testName, CLASS_NAME));
827 setupDeleteNonExistent();
829 // Submit the request to the service and store the response.
830 RelationClient client = new RelationClient();
831 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
832 int statusCode = res.getStatus();
834 // Check the status code of the response: does it match
835 // the expected response(s)?
836 if(logger.isDebugEnabled()){
837 logger.debug(testName + ": status = " + statusCode);
839 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
840 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
841 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
844 // ---------------------------------------------------------------
845 // RELATE_OBJECT tests
846 // ---------------------------------------------------------------
850 @Test(dependsOnMethods = {"create"})
851 public void relateObjects() {
852 //Should this test really be empty?
855 // ---------------------------------------------------------------
856 // Utility tests : tests of code used in tests above
857 // ---------------------------------------------------------------
859 * Tests the code for manually submitting data that is used by several
860 * of the methods above.
862 @Test(dependsOnMethods = {"create", "read"})
863 public void testSubmitRequest() {
867 // Submit the request to the service and store the response.
868 String method = ServiceRequestType.READ.httpMethodName();
869 String url = getResourceURL(knownResourceId);
870 int statusCode = submitRequest(method, url);
872 // Check the status code of the response: does it match
873 // the expected response(s)?
874 if(logger.isDebugEnabled()){
875 logger.debug("testSubmitRequest: url=" + url +
876 " status=" + statusCode);
878 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
881 // ---------------------------------------------------------------
882 // Utility methods used by tests above
883 // ---------------------------------------------------------------
885 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
888 public String getServicePathComponent() {
889 return SERVICE_PATH_COMPONENT;
892 private RelationsCommon createRelationsCommon(String identifier) {
893 RelationsCommon relationCommon = new RelationsCommon();
894 fillRelation(relationCommon, identifier);
895 return relationCommon;
898 private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
899 PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
900 PayloadOutputPart commonPart =
901 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
902 commonPart.setLabel(new RelationClient().getCommonPartName());
903 if(logger.isDebugEnabled()){
904 logger.debug("to be created, relation common");
905 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
911 * Creates the relation instance.
913 * @param identifier the identifier
914 * @return the multipart output
916 private PoxPayloadOut createRelationInstance(String identifier) {
917 RelationsCommon relation = createRelationsCommon(identifier);
918 PoxPayloadOut result = createRelationInstance(relation);
923 * Fills the relation.
925 * @param relationCommon the relation
926 * @param identifier the identifier
928 private void fillRelation(RelationsCommon relationCommon, String identifier) {
929 fillRelation(relationCommon, samSubjectPersonCSID, null, oliveObjectPersonCSID, null,
930 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
931 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
935 * Fills the relation.
937 * @param relationCommon the relation
938 * @param documentId1 the document id1
939 * @param documentType1 the document type1
940 * @param documentId2 the document id2
941 * @param documentType2 the document type2
944 private void fillRelation(RelationsCommon relationCommon,
945 String documentId1, String documentType1,
946 String documentId2, String documentType2,
948 String rtDisplayName) {
949 relationCommon.setDocumentId1(documentId1);
950 relationCommon.setDocumentType1(documentType1);
951 relationCommon.setDocumentId2(documentId2);
952 relationCommon.setDocumentType2(documentType2);
954 relationCommon.setRelationshipType(rt);
955 relationCommon.setPredicateDisplayName(rtDisplayName);
959 protected String getServiceName() {
960 return RelationClient.SERVICE_NAME;