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 org.collectionspace.services.client.AbstractCommonListUtils;
26 import org.collectionspace.services.client.CollectionSpaceClient;
27 import org.collectionspace.services.client.PayloadInputPart;
28 import org.collectionspace.services.client.ServiceGroupClient;
29 import org.collectionspace.services.client.ServiceGroupProxy;
30 import org.collectionspace.services.client.PoxPayloadIn;
31 import org.collectionspace.services.client.PoxPayloadOut;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.servicegroup.ServicegroupsCommon;
35 import javax.ws.rs.core.Response;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * ServiceGroupServiceTest, carries out tests against a deployed and running ServiceGroup Service. <p/>
43 * $LastChangedRevision: $
46 public class ServiceGroupServiceTest extends BaseServiceTest<AbstractCommonList> {
48 private final String CLASS_NAME = ServiceGroupServiceTest.class.getName();
49 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
50 final String SERVICE_PATH_COMPONENT = "servicegroups";
51 private String readGroupName = "procedure";
54 public String getServicePathComponent() {
55 return ServiceGroupClient.SERVICE_PATH_COMPONENT;
59 protected String getServiceName() {
60 return ServiceGroupClient.SERVICE_NAME;
64 protected CollectionSpaceClient<AbstractCommonList, PoxPayloadOut, String, ServiceGroupProxy> getClientInstance() {
65 return new ServiceGroupClient();
69 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
70 return new ServiceGroupClient(clientPropertiesFilename);
74 protected AbstractCommonList getCommonList(Response response) {
75 return response.readEntity(AbstractCommonList.class);
78 public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client,
79 Response res) throws Exception {
81 ServicegroupsCommon result = null;
82 PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());
83 if (payloadInputPart != null) {
84 result = (ServicegroupsCommon) payloadInputPart.getBody();
86 Assert.assertNotNull(result,
87 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
92 protected PayloadInputPart extractPart(Response res, String partLabel)
94 if (getLogger().isDebugEnabled()) {
95 getLogger().debug("Reading part " + partLabel + " ...");
97 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
98 PayloadInputPart payloadInputPart = input.getPart(partLabel);
99 Assert.assertNotNull(payloadInputPart,
100 "Part " + partLabel + " was unexpectedly null.");
101 return payloadInputPart;
105 @Test(dataProvider = "testName", dependsOnMethods = {"readList"})
106 public void read(String testName) throws Exception {
110 // Submit the request to the service and store the response.
111 CollectionSpaceClient client = this.getClientInstance();
112 Response res = client.read(readGroupName);
113 int statusCode = res.getStatus();
115 // Check the status code of the response: does it match
116 // the expected response(s)?
117 if (logger.isDebugEnabled()) {
118 logger.debug(testName + ": status = " + statusCode);
120 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
121 invalidStatusCodeMessage(testRequestType, statusCode));
122 Assert.assertEquals(statusCode, testExpectedStatusCode);
124 ServicegroupsCommon output = extractCommonPartValue(client, res);
125 Assert.assertNotNull(output);
128 // Now compare with the expected field values
130 Assert.assertEquals(output.getName(), readGroupName,
131 "Display name in updated object did not match submitted data.");
135 @Test(dataProvider = "testName")
136 public void readList(String testName) throws Exception {
140 // Submit the request to the service and store the response.
141 CollectionSpaceClient client = this.getClientInstance();
142 Response res = client.readList();
143 AbstractCommonList list = res.readEntity(getCommonListType());
146 statusCode = res.getStatus();
152 // Check the status code of the response: does it match
153 // the expected response(s)?
154 if (logger.isDebugEnabled()) {
155 logger.debug(testName + ": status = " + statusCode);
157 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
158 invalidStatusCodeMessage(testRequestType, statusCode));
159 Assert.assertEquals(statusCode, testExpectedStatusCode);
161 // Optionally output additional data about list members for debugging.
162 boolean iterateThroughList = true;
163 if (iterateThroughList && logger.isTraceEnabled()) {
164 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName);