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 javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
28 import org.collectionspace.services.client.AbstractCommonListUtils;
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.PayloadInputPart;
31 import org.collectionspace.services.client.ServiceGroupClient;
32 import org.collectionspace.services.client.ServiceGroupProxy;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.collectionspace.services.servicegroup.ServicegroupsCommon;
39 import org.jboss.resteasy.client.ClientResponse;
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * ServiceGroupServiceTest, carries out tests against a deployed and running ServiceGroup Service. <p/>
49 * $LastChangedRevision: $
52 public class ServiceGroupServiceTest extends BaseServiceTest<AbstractCommonList> {
54 private final String CLASS_NAME = ServiceGroupServiceTest.class.getName();
55 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
56 final String SERVICE_PATH_COMPONENT = "servicegroups";
57 private String readGroupName = "procedure";
60 public String getServicePathComponent() {
61 return ServiceGroupClient.SERVICE_PATH_COMPONENT;
65 protected String getServiceName() {
66 return ServiceGroupClient.SERVICE_NAME;
70 protected CollectionSpaceClient<AbstractCommonList, PoxPayloadOut, String, ServiceGroupProxy> getClientInstance() {
71 return new ServiceGroupClient();
75 protected AbstractCommonList getCommonList(Response response) {
76 return response.readEntity(AbstractCommonList.class);
79 public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client,
80 Response res) throws Exception {
82 ServicegroupsCommon result = null;
83 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
84 if (payloadInputPart != null) {
85 result = (ServicegroupsCommon) payloadInputPart.getBody();
87 Assert.assertNotNull(result,
88 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
93 protected PayloadInputPart extractPart(Response res, String partLabel)
95 if (getLogger().isDebugEnabled()) {
96 getLogger().debug("Reading part " + partLabel + " ...");
98 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
99 PayloadInputPart payloadInputPart = input.getPart(partLabel);
100 Assert.assertNotNull(payloadInputPart,
101 "Part " + partLabel + " was unexpectedly null.");
102 return payloadInputPart;
106 @Test(dataProvider = "testName", dependsOnMethods = {"readList"})
107 public void read(String testName) throws Exception {
111 // Submit the request to the service and store the response.
112 CollectionSpaceClient client = this.getClientInstance();
113 Response res = client.read(readGroupName);
114 int statusCode = res.getStatus();
116 // Check the status code of the response: does it match
117 // the expected response(s)?
118 if (logger.isDebugEnabled()) {
119 logger.debug(testName + ": status = " + statusCode);
121 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
122 invalidStatusCodeMessage(testRequestType, statusCode));
123 Assert.assertEquals(statusCode, testExpectedStatusCode);
125 ServicegroupsCommon output = extractCommonPartValue(client, res);
126 Assert.assertNotNull(output);
129 // Now compare with the expected field values
131 Assert.assertEquals(output.getName(), readGroupName,
132 "Display name in updated object did not match submitted data.");
136 @Test(dataProvider = "testName")
137 public void readList(String testName) throws Exception {
141 // Submit the request to the service and store the response.
142 CollectionSpaceClient client = this.getClientInstance();
143 Response res = client.readList();
144 AbstractCommonList list = res.readEntity(getCommonListType());
147 statusCode = res.getStatus();
153 // Check the status code of the response: does it match
154 // the expected response(s)?
155 if (logger.isDebugEnabled()) {
156 logger.debug(testName + ": status = " + statusCode);
158 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
159 invalidStatusCodeMessage(testRequestType, statusCode));
160 Assert.assertEquals(statusCode, testExpectedStatusCode);
162 // Optionally output additional data about list members for debugging.
163 boolean iterateThroughList = true;
164 if (iterateThroughList && logger.isTraceEnabled()) {
165 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);