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.List;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.AbstractCommonListUtils;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.PayloadOutputPart;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.client.ReportClient;
35 import org.collectionspace.services.common.invocable.InvocationContext;
36 import org.collectionspace.services.report.ReportsCommon;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.jboss.resteasy.client.ClientResponse;
40 import org.testng.Assert;
41 //import org.testng.annotations.AfterClass;
42 import org.testng.annotations.Test;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * FIXME: http://issues.collectionspace.org/browse/CSPACE-1685
49 * ReportServiceTest, carries out tests against a
50 * deployed and running Report Service.
52 * $LastChangedRevision: 2261 $
53 * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $
55 public class ReportServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, ReportsCommon> {
58 private final String CLASS_NAME = ReportServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60 final String SERVICE_NAME = "reports";
61 final String SERVICE_PATH_COMPONENT = "reports";
62 // Instance variables specific to this test.
63 private String testDocType = "Acquisition";
65 @Test(dataProvider = "testName", dependsOnMethods = {"create"})
66 public void publishReportInstance(String testName) throws Exception {
70 // Submit the request to the service and store the response.
71 ReportClient client = (ReportClient)this.getClientInstance();
73 createReportInstance()
76 // Hard coded for now, but need to create this test in the Integration test area where
77 // we'll create an Acquisition instance for this test
79 InvocationContext invocationContext = new InvocationContext();
80 invocationContext.setDocType("Acquisition");
81 invocationContext.setMode("single");
82 invocationContext.setSingleCSID("34abdc63-944c-421d-a585");
84 String reportCsid = "8680d49c-99b8-4788-aa45";
85 ClientResponse<Response> res = client.publishReport(reportCsid, invocationContext);
86 int statusCode = res.getStatus();
88 // Check the status code of the response: does it match
89 // the expected response(s)?
90 if (logger.isDebugEnabled()) {
91 logger.debug(testName + ": status = " + statusCode);
93 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
94 invalidStatusCodeMessage(testRequestType, statusCode));
95 Assert.assertEquals(statusCode, testExpectedStatusCode);
97 String articleCsid = extractId(res);
98 Assert.assertNotNull(articleCsid);
102 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
105 protected CollectionSpaceClient getClientInstance() {
106 return new ReportClient();
109 @Test(dataProvider = "testName",
110 dependsOnMethods = {"CRUDTests"})
111 public void readListFiltered(String testName) throws Exception {
115 // Submit the request to the service and store the response.
116 ReportClient client = new ReportClient();
117 ClientResponse<AbstractCommonList> res = client.readListFiltered(testDocType, "single");
118 AbstractCommonList list = null;
120 assertStatusCode(res, testName);
121 list = res.getEntity();
124 res.releaseConnection();
127 List<AbstractCommonList.ListItem> items = list.getListItem();
128 // We must find the basic one we created
129 boolean fFoundBaseItem = false;
130 for (AbstractCommonList.ListItem item : items) {
131 String itemCsid = AbstractCommonListUtils.ListItemGetCSID(item);
132 if (knownResourceId.equalsIgnoreCase(itemCsid)) {
133 fFoundBaseItem = true;
137 if(!fFoundBaseItem) {
138 Assert.fail("readListFiltered failed to return base item");
141 // Now filter for something else, and ensure it is NOT returned
142 res = client.readListFiltered("Intake", "single");
144 assertStatusCode(res, testName);
145 list = res.getEntity();
148 res.releaseConnection();
152 items = list.getListItem();
153 // We must NOT find the basic one we created
154 for (AbstractCommonList.ListItem item : items) {
155 Assert.assertNotSame(AbstractCommonListUtils.ListItemGetCSID(item), knownResourceId,
156 "readListFiltered(\"Intake\", \"single\") incorrectly returned base item");
159 // Now filter for something else, and ensure it is NOT returned
160 res = client.readListFiltered(testDocType, "group");
162 assertStatusCode(res, testName);
163 list = res.getEntity();
166 res.releaseConnection();
170 items = list.getListItem();
171 // We must NOT find the basic one we created
172 for (AbstractCommonList.ListItem item : items) {
173 Assert.assertNotSame(AbstractCommonListUtils.ListItemGetCSID(item), knownResourceId,
174 "readListFiltered(\""+testDocType+"\", \"group\") incorrectly returned base item");
179 * This method overrides the delete method in the base class which is marked with the TestNG @Test annotation.
180 * Since we don't want the actually delete test to happen until later in the dependency test chain, we're make this
181 * an empty method. Later in the test suite, the method localDelete() will get called and it will call super.delete()
184 public void delete(String testName) throws Exception {
186 // Do nothing for now. The test localDelete() will get called later in the dependency chain.
191 * This test will delete the known resource after the test readListFiltered() is run
193 @Test(dataProvider = "testName",
194 dependsOnMethods = {"readListFiltered"})
195 public void localDelete(String testName) throws Exception {
196 super.delete(testName);
199 // ---------------------------------------------------------------
200 // Utility methods used by tests above
201 // ---------------------------------------------------------------
203 protected String getServiceName() {
208 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
211 public String getServicePathComponent() {
212 return SERVICE_PATH_COMPONENT;
216 * Creates the report instance.
218 * @param identifier the identifier
219 * @return the multipart output
221 private PoxPayloadOut createReportInstance(String identifier) {
222 List<String> docTypes = new ArrayList<String>();
223 docTypes.add(testDocType);
224 return createReportInstance(
225 "Acquisition Summary " + identifier,
226 docTypes, true, false, false, true,
232 * Creates the report instance.
234 * @param name the report name
235 * @param filename the relative path to the report
236 * @param outputMIME the MIME type we will return for this report
237 * @return the multipart output
239 private PoxPayloadOut createReportInstance(String name,
240 List<String> forDocTypeList,
241 boolean supportsSingle, boolean supportsList,
242 boolean supportsGroup, boolean supportsNoContext,
245 ReportsCommon reportCommon = new ReportsCommon();
246 reportCommon.setName(name);
247 ReportsCommon.ForDocTypes forDocTypes = new ReportsCommon.ForDocTypes();
248 List<String> docTypeList = forDocTypes.getForDocType();
249 docTypeList.addAll(forDocTypeList);
250 reportCommon.setForDocTypes(forDocTypes);
251 reportCommon.setSupportsSingleDoc(supportsSingle);
252 reportCommon.setSupportsDocList(supportsList);
253 reportCommon.setSupportsGroup(supportsGroup);
254 reportCommon.setSupportsNoContext(supportsNoContext);
255 reportCommon.setFilename(filename);
256 reportCommon.setOutputMIME(outputMIME);
257 reportCommon.setNotes(getUTF8DataFragment()); // For UTF-8 tests
259 PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
260 PayloadOutputPart commonPart =
261 multipart.addPart(new ReportClient().getCommonPartName(), reportCommon);
263 if (logger.isDebugEnabled()) {
264 logger.debug("to be created, report common");
265 logger.debug(objectAsXmlString(reportCommon, ReportsCommon.class));
266 logger.debug(multipart.toXML());
273 protected PoxPayloadOut createInstance(String commonPartName,
275 PoxPayloadOut result = createReportInstance(identifier);
280 protected ReportsCommon updateInstance(ReportsCommon reportsCommon) {
281 ReportsCommon result = new ReportsCommon();
283 result.setSupportsSingleDoc(true);
284 result.setName("updated-" + reportsCommon.getName());
285 result.setOutputMIME("updated-" + reportsCommon.getOutputMIME());
286 result.setNotes("updated-" + reportsCommon.getNotes());
292 protected void compareUpdatedInstances(ReportsCommon original,
293 ReportsCommon updated) throws Exception {
294 // Check selected fields in the updated common part.
295 Assert.assertEquals(updated.getName(),
297 "Name in updated object did not match submitted data.");
299 // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters.
300 if (logger.isDebugEnabled()) {
301 logger.debug("UTF-8 data sent=" + original.getNotes() + "\n"
302 + "UTF-8 data received=" + updated.getNotes());
304 Assert.assertTrue(updated.getNotes().contains(getUTF8DataFragment()),
305 "UTF-8 data retrieved '" + updated.getNotes()
306 + "' does not contain expected data '" + getUTF8DataFragment());
307 Assert.assertEquals(updated.getNotes(),
309 "Notes in updated object did not match submitted data.");
312 protected void compareReadInstances(ReportsCommon original, ReportsCommon fromRead) throws Exception {
313 Assert.assertEquals(fromRead.getNotes(), getUTF8DataFragment(),
314 "UTF-8 data retrieved '" + fromRead.getNotes()
315 + "' does not match expected data '" + getUTF8DataFragment());
319 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
320 * refer to this method in their @Test annotation declarations.
323 @Test(dataProvider = "testName",
325 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
326 public void CRUDTests(String testName) {
327 // TODO Auto-generated method stub