2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.PayloadInputPart;
31 import org.collectionspace.services.client.PayloadOutputPart;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.client.RelationClient;
35 import org.collectionspace.services.jaxb.AbstractCommonList;
36 import org.collectionspace.services.relation.RelationsCommon;
37 import org.collectionspace.services.relation.RelationsCommonList;
38 import org.collectionspace.services.relation.RelationshipType;
40 import org.jboss.resteasy.client.ClientResponse;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * RelationServiceTest, carries out tests against a
50 * deployed and running Relation Service.
52 * $LastChangedRevision$
55 public class RelationServiceTest extends AbstractServiceTestImpl {
58 private final String CLASS_NAME = RelationServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 /** The SERVICE path component. */
62 final String SERVICE_PATH_COMPONENT = "relations";
64 /** The known resource id. */
65 private String knownResourceId = null;
68 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71 protected CollectionSpaceClient getClientInstance() {
72 return new RelationClient();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getAbstractCommonList(
80 ClientResponse<AbstractCommonList> response) {
81 return response.getEntity(RelationsCommonList.class);
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
89 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
91 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
93 public void create(String testName) throws Exception {
95 if (logger.isDebugEnabled()) {
96 logger.debug(testBanner(testName, CLASS_NAME));
98 // Perform setup, such as initializing the type of service request
99 // (e.g. CREATE, DELETE), its valid and expected status codes, and
100 // its associated HTTP method name (e.g. POST, DELETE).
103 // Submit the request to the service and store the response.
104 RelationClient client = new RelationClient();
105 String identifier = createIdentifier();
106 PoxPayloadOut multipart = createRelationInstance(identifier);
107 ClientResponse<Response> res = client.create(multipart);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
113 // Does it fall within the set of valid status codes?
114 // Does it exactly match the expected status code?
115 if(logger.isDebugEnabled()){
116 logger.debug(testName + ": status = " + statusCode);
118 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
119 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
120 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
122 // Store the ID returned from the first resource created
123 // for additional tests below.
124 if (knownResourceId == null){
125 knownResourceId = extractId(res);
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": knownResourceId=" + knownResourceId);
131 // Store the IDs from every resource created by tests,
132 // so they can be deleted after tests have been run.
133 allResourceIdsCreated.add(extractId(res));
137 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
140 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
141 dependsOnMethods = {"create"})
142 public void createList(String testName) throws Exception {
143 for(int i = 0; i < 3; i++){
148 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
149 dependsOnMethods = {"create"})
150 public void createWithSelfRelation(String testName) throws Exception {
152 if (logger.isDebugEnabled()) {
153 logger.debug(testBanner(testName, CLASS_NAME));
156 setupCreateWithInvalidBody();
158 // Submit the request to the service and store the response.
159 RelationClient client = new RelationClient();
160 String identifier = createIdentifier();
161 RelationsCommon relationsCommon = createRelationsCommon(identifier);
162 // Make the subject ID equal to the object ID
163 relationsCommon.setDocumentId1(relationsCommon.getDocumentId2());
164 PoxPayloadOut multipart = createRelationInstance(relationsCommon);
165 ClientResponse<Response> res = client.create(multipart);
166 int statusCode = res.getStatus();
168 // Check the status code of the response: does it match
169 // the expected response(s)?
171 // Does it fall within the set of valid status codes?
172 // Does it exactly match the expected status code?
173 if(logger.isDebugEnabled()){
174 logger.debug(testName + ": status = " + statusCode);
176 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
177 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
178 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
182 // Placeholders until the three tests below can be uncommented.
183 // See Issue CSPACE-401.
185 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
188 public void createWithEmptyEntityBody(String testName) throws Exception {
189 //Should this test really be empty?
193 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
196 public void createWithMalformedXml(String testName) throws Exception {
197 //Should this test really be empty?
201 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
204 public void createWithWrongXmlSchema(String testName) throws Exception {
205 //Should this test really be empty?
210 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
211 dependsOnMethods = {"create", "testSubmitRequest"})
212 public void createWithEmptyEntityBody(String testName) throws Exception {
214 if (logger.isDebugEnabled()) {
215 logger.debug(testBanner(testName, CLASS_NAME));
218 setupCreateWithEmptyEntityBody();
220 // Submit the request to the service and store the response.
221 String method = REQUEST_TYPE.httpMethodName();
222 String url = getServiceRootURL();
223 String mediaType = MediaType.APPLICATION_XML;
224 final String entity = "";
225 int statusCode = submitRequest(method, url, mediaType, entity);
227 // Check the status code of the response: does it match
228 // the expected response(s)?
229 if(logger.isDebugEnabled()){
230 logger.debug(testName + ": url=" + url +
231 " status=" + statusCode);
233 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
234 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
235 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
239 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
240 dependsOnMethods = {"create", "testSubmitRequest"})
241 public void createWithMalformedXml(String testName) throws Exception {
243 if (logger.isDebugEnabled()) {
244 logger.debug(testBanner(testName, CLASS_NAME));
247 setupCreateWithMalformedXml();
249 // Submit the request to the service and store the response.
250 String method = REQUEST_TYPE.httpMethodName();
251 String url = getServiceRootURL();
252 String mediaType = MediaType.APPLICATION_XML;
253 final String entity = MALFORMED_XML_DATA; // Constant from base class.
254 int statusCode = submitRequest(method, url, mediaType, entity);
256 // Check the status code of the response: does it match
257 // the expected response(s)?
258 if(logger.isDebugEnabled()){
259 logger.debug(testName + ": url=" + url +
260 " status=" + statusCode);
262 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
263 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
264 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
268 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
269 dependsOnMethods = {"create", "testSubmitRequest"})
270 public void createWithWrongXmlSchema(String testName) throws Exception {
272 if (logger.isDebugEnabled()) {
273 logger.debug(testBanner(testName, CLASS_NAME));
276 setupCreateWithWrongXmlSchema();
278 // Submit the request to the service and store the response.
279 String method = REQUEST_TYPE.httpMethodName();
280 String url = getServiceRootURL();
281 String mediaType = MediaType.APPLICATION_XML;
282 final String entity = WRONG_XML_SCHEMA_DATA;
283 int statusCode = submitRequest(method, url, mediaType, entity);
285 // Check the status code of the response: does it match
286 // the expected response(s)?
287 if(logger.isDebugEnabled()){
288 logger.debug(testName + ": url=" + url +
289 " status=" + statusCode);
291 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
292 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
293 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
297 // ---------------------------------------------------------------
298 // CRUD tests : READ tests
299 // ---------------------------------------------------------------
302 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
305 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
306 dependsOnMethods = {"create"})
307 public void read(String testName) throws Exception {
309 if (logger.isDebugEnabled()) {
310 logger.debug(testBanner(testName, CLASS_NAME));
315 // Submit the request to the service and store the response.
316 RelationClient client = new RelationClient();
317 ClientResponse<String> res = client.read(knownResourceId);
318 int statusCode = res.getStatus();
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if(logger.isDebugEnabled()){
323 logger.debug(testName + ": status = " + statusCode);
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
329 // Get the common part from the response and check that it is not null.
330 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
331 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
332 RelationsCommon relationCommon = null;
333 if (payloadInputPart != null) {
334 relationCommon = (RelationsCommon) payloadInputPart.getBody();
336 Assert.assertNotNull(relationCommon);
342 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
345 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
346 dependsOnMethods = {"read"})
347 public void readNonExistent(String testName) throws Exception {
349 if (logger.isDebugEnabled()) {
350 logger.debug(testBanner(testName, CLASS_NAME));
353 setupReadNonExistent();
355 // Submit the request to the service and store the response.
356 RelationClient client = new RelationClient();
357 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
358 int statusCode = res.getStatus();
360 // Check the status code of the response: does it match
361 // the expected response(s)?
362 if(logger.isDebugEnabled()){
363 logger.debug(testName + ": status = " + statusCode);
365 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
370 // ---------------------------------------------------------------
371 // CRUD tests : READ_LIST tests
372 // ---------------------------------------------------------------
375 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
378 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
379 dependsOnMethods = {"createList", "read"})
380 public void readList(String testName) throws Exception {
382 if (logger.isDebugEnabled()) {
383 logger.debug(testBanner(testName, CLASS_NAME));
388 // Submit the request to the service and store the response.
389 RelationClient client = new RelationClient();
390 ClientResponse<RelationsCommonList> res = client.readList();
391 RelationsCommonList list = res.getEntity();
392 int statusCode = res.getStatus();
394 // Check the status code of the response: does it match
395 // the expected response(s)?
396 if(logger.isDebugEnabled()){
397 logger.debug(testName + ": status = " + statusCode);
399 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
400 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
401 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
403 // Optionally output additional data about list members for debugging.
404 boolean iterateThroughList = false;
405 if(iterateThroughList && logger.isDebugEnabled()){
406 List<RelationsCommonList.RelationListItem> items =
407 list.getRelationListItem();
409 for(RelationsCommonList.RelationListItem item : items){
410 logger.debug(testName + ": list-item[" + i + "] csid=" +
412 logger.debug(testName + ": list-item[" + i + "] URI=" +
421 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
422 dependsOnMethods = {"createList", "read"})
423 public void readListPaginated(String testName) throws Exception {
425 if (logger.isDebugEnabled()) {
426 logger.debug(testBanner(testName, CLASS_NAME));
433 RelationClient client = new RelationClient();
434 ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
442 RelationsCommonList list = res.getEntity();
443 int statusCode = res.getStatus();
445 // Check the status code of the response: does it match
446 // the expected response(s)?
447 if(logger.isDebugEnabled()){
448 logger.debug(testName + ": status = " + statusCode);
450 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
451 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
452 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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=" +
475 // ---------------------------------------------------------------
476 // CRUD tests : UPDATE tests
477 // ---------------------------------------------------------------
481 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
484 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
485 dependsOnMethods = {"read"})
486 public void update(String testName) throws Exception {
488 if (logger.isDebugEnabled()) {
489 logger.debug(testBanner(testName, CLASS_NAME));
494 // Retrieve an existing resource that we can update.
495 RelationClient client = new RelationClient();
496 ClientResponse<String> res = client.read(knownResourceId);
497 if(logger.isDebugEnabled()){
498 logger.debug(testName + ": read status = " + res.getStatus());
500 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
501 if(logger.isDebugEnabled()){
502 logger.debug("Got object to update with ID: " + knownResourceId);
505 // Extract the common part and verify that it is not null.
506 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
507 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
508 RelationsCommon relationCommon = null;
509 if (payloadInputPart != null) {
510 relationCommon = (RelationsCommon) payloadInputPart.getBody();
512 Assert.assertNotNull(relationCommon);
514 // Update the content of this resource.
515 relationCommon.setDocumentId1("updated-" + relationCommon.getDocumentId1());
516 relationCommon.setDocumentType1("updated-" + relationCommon.getDocumentType1());
517 relationCommon.setDocumentId2("updated-" + relationCommon.getDocumentId2());
518 relationCommon.setDocumentType2("updated-" + relationCommon.getDocumentType2());
519 relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName());
520 if(logger.isDebugEnabled()){
521 logger.debug("updated object");
522 logger.debug(objectAsXmlString(relationCommon, RelationsCommon.class));
525 // Submit the request containing the updated resource to the service
526 // and store the response.
527 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
528 PayloadOutputPart commonPart = output.addPart(relationCommon, MediaType.APPLICATION_XML_TYPE);
529 commonPart.setLabel(client.getCommonPartName());
530 res = client.update(knownResourceId, output);
531 int statusCode = res.getStatus();
533 // Check the status code of the response: does it match the expected response(s)?
534 if(logger.isDebugEnabled()){
535 logger.debug(testName + ": status = " + statusCode);
537 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
538 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
539 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
541 // Extract the common part of the updated resource and verify that it is not null.
542 input = new PoxPayloadIn(res.getEntity());
543 RelationsCommon updatedRelationCommon =
544 (RelationsCommon) extractPart(input,
545 client.getCommonPartName(), RelationsCommon.class);
546 Assert.assertNotNull(updatedRelationCommon);
549 "Data in updated object did not match submitted data.";
551 updatedRelationCommon.getDocumentId1(), relationCommon.getDocumentId1(), msg);
553 updatedRelationCommon.getDocumentType1(), relationCommon.getDocumentType1(), msg);
555 updatedRelationCommon.getDocumentId2(), relationCommon.getDocumentId2(), msg);
557 updatedRelationCommon.getDocumentType2(), relationCommon.getDocumentType2(), msg);
559 updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg);
564 // Placeholders until the three tests below can be uncommented.
565 // See Issue CSPACE-401.
567 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
570 public void updateWithEmptyEntityBody(String testName) throws Exception {
571 //Should this test really be empty?
575 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
578 public void updateWithMalformedXml(String testName) throws Exception {
579 //Should this test really be empty?
583 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
586 public void updateWithWrongXmlSchema(String testName) throws Exception {
587 //Should this test really be empty?
592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
593 dependsOnMethods = {"create", "update", "testSubmitRequest"})
594 public void updateWithEmptyEntityBody(String testName) throws Exception {
596 if (logger.isDebugEnabled()) {
597 logger.debug(testBanner(testName, CLASS_NAME));
600 setupUpdateWithEmptyEntityBody();
602 // Submit the request to the service and store the response.
603 String method = REQUEST_TYPE.httpMethodName();
604 String url = getResourceURL(knownResourceId);
605 String mediaType = MediaType.APPLICATION_XML;
606 final String entity = "";
607 int statusCode = submitRequest(method, url, mediaType, entity);
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if(logger.isDebugEnabled()){
612 logger.debug(testName + ": url=" + url +
613 " status=" + statusCode);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
621 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
622 dependsOnMethods = {"create", "update", "testSubmitRequest"})
623 public void updateWithMalformedXml(String testName) throws Exception {
625 if (logger.isDebugEnabled()) {
626 logger.debug(testBanner(testName, CLASS_NAME));
629 setupUpdateWithMalformedXml();
631 // Submit the request to the service and store the response.
632 String method = REQUEST_TYPE.httpMethodName();
633 String url = getResourceURL(knownResourceId);
634 String mediaType = MediaType.APPLICATION_XML;
635 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
636 int statusCode = submitRequest(method, url, mediaType, entity);
638 // Check the status code of the response: does it match
639 // the expected response(s)?
640 if(logger.isDebugEnabled()){
641 logger.debug(testName + ": url=" + url +
642 " status=" + statusCode);
644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
651 dependsOnMethods = {"create", "update", "testSubmitRequest"})
652 public void updateWithWrongXmlSchema(String testName) throws Exception {
654 if (logger.isDebugEnabled()) {
655 logger.debug(testBanner(testName, CLASS_NAME));
658 setupUpdateWithWrongXmlSchema();
660 // Submit the request to the service and store the response.
661 String method = REQUEST_TYPE.httpMethodName();
662 String url = getResourceURL(knownResourceId);
663 String mediaType = MediaType.APPLICATION_XML;
664 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
665 int statusCode = submitRequest(method, url, mediaType, entity);
667 // Check the status code of the response: does it match
668 // the expected response(s)?
669 if(logger.isDebugEnabled()){
670 logger.debug(testName + ": url=" + url +
671 " status=" + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
680 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
683 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684 dependsOnMethods = {"update", "testSubmitRequest"})
685 public void updateNonExistent(String testName) throws Exception {
687 if (logger.isDebugEnabled()) {
688 logger.debug(testBanner(testName, CLASS_NAME));
691 setupUpdateNonExistent();
693 // Submit the request to the service and store the response.
694 // Note: The ID used in this 'create' call may be arbitrary.
695 // The only relevant ID may be the one used in update(), below.
696 RelationClient client = new RelationClient();
697 PoxPayloadOut multipart = createRelationInstance(NON_EXISTENT_ID);
698 ClientResponse<String> res =
699 client.update(NON_EXISTENT_ID, multipart);
700 int statusCode = res.getStatus();
702 // Check the status code of the response: does it match
703 // the expected response(s)?
704 if(logger.isDebugEnabled()){
705 logger.debug(testName + ": status = " + statusCode);
707 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
708 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
709 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 // ---------------------------------------------------------------
713 // CRUD tests : DELETE tests
714 // ---------------------------------------------------------------
717 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
720 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
721 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
722 public void delete(String testName) throws Exception {
724 if (logger.isDebugEnabled()) {
725 logger.debug(testBanner(testName, CLASS_NAME));
730 // Submit the request to the service and store the response.
731 RelationClient client = new RelationClient();
732 ClientResponse<Response> res = client.delete(knownResourceId);
733 int statusCode = res.getStatus();
735 // Check the status code of the response: does it match
736 // the expected response(s)?
737 if(logger.isDebugEnabled()){
738 logger.debug(testName + ": status = " + statusCode);
740 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
741 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
742 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
747 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
750 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751 dependsOnMethods = {"delete"})
752 public void deleteNonExistent(String testName) throws Exception {
754 if (logger.isDebugEnabled()) {
755 logger.debug(testBanner(testName, CLASS_NAME));
758 setupDeleteNonExistent();
760 // Submit the request to the service and store the response.
761 RelationClient client = new RelationClient();
762 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
763 int statusCode = res.getStatus();
765 // Check the status code of the response: does it match
766 // the expected response(s)?
767 if(logger.isDebugEnabled()){
768 logger.debug(testName + ": status = " + statusCode);
770 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
775 // ---------------------------------------------------------------
776 // RELATE_OBJECT tests
777 // ---------------------------------------------------------------
781 @Test(dependsOnMethods = {"create"})
782 public void relateObjects() {
783 //Should this test really be empty?
786 // ---------------------------------------------------------------
787 // Utility tests : tests of code used in tests above
788 // ---------------------------------------------------------------
790 * Tests the code for manually submitting data that is used by several
791 * of the methods above.
793 @Test(dependsOnMethods = {"create", "read"})
794 public void testSubmitRequest() {
798 // Submit the request to the service and store the response.
799 String method = ServiceRequestType.READ.httpMethodName();
800 String url = getResourceURL(knownResourceId);
801 int statusCode = submitRequest(method, url);
803 // Check the status code of the response: does it match
804 // the expected response(s)?
805 if(logger.isDebugEnabled()){
806 logger.debug("testSubmitRequest: url=" + url +
807 " status=" + statusCode);
809 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
812 // ---------------------------------------------------------------
813 // Utility methods used by tests above
814 // ---------------------------------------------------------------
816 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
819 public String getServicePathComponent() {
820 return SERVICE_PATH_COMPONENT;
823 private RelationsCommon createRelationsCommon(String identifier) {
824 RelationsCommon relationCommon = new RelationsCommon();
825 fillRelation(relationCommon, identifier);
826 return relationCommon;
829 private PoxPayloadOut createRelationInstance(RelationsCommon relation) {
830 PoxPayloadOut result = new PoxPayloadOut(this.getServicePathComponent());
831 PayloadOutputPart commonPart =
832 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
833 commonPart.setLabel(new RelationClient().getCommonPartName());
834 if(logger.isDebugEnabled()){
835 logger.debug("to be created, relation common");
836 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
842 * Creates the relation instance.
844 * @param identifier the identifier
845 * @return the multipart output
847 private PoxPayloadOut createRelationInstance(String identifier) {
848 RelationsCommon relation = createRelationsCommon(identifier);
849 PoxPayloadOut result = createRelationInstance(relation);
854 * Fills the relation.
856 * @param relation the relation
857 * @param identifier the identifier
859 private void fillRelation(RelationsCommon relationCommon, String identifier) {
860 fillRelation(relationCommon, "Subject-" + identifier,
861 "SubjectType-" + identifier + "-type",
862 "Object-" + identifier,
863 "ObjectType-" + identifier + "-type",
864 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
865 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
869 * Fills the relation.
871 * @param relation the relation
872 * @param documentId1 the document id1
873 * @param documentType1 the document type1
874 * @param documentId2 the document id2
875 * @param documentType2 the document type2
878 private void fillRelation(RelationsCommon relationCommon,
879 String documentId1, String documentType1,
880 String documentId2, String documentType2,
882 String rtDisplayName) {
883 relationCommon.setDocumentId1(documentId1);
884 relationCommon.setDocumentType1(documentType1);
885 relationCommon.setDocumentId2(documentId2);
886 relationCommon.setDocumentType2(documentType2);
888 relationCommon.setRelationshipType(rt);
889 relationCommon.setPredicateDisplayName(rtDisplayName);
893 protected String getServiceName() {
894 return RelationClient.SERVICE_NAME;