]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7f56bdfd2c45ac877dabdc13089e34a9fee63d27
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.List;
26
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.PayloadOutputPart;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34
35 import org.collectionspace.services.jaxb.AbstractCommonList;
36 import org.collectionspace.services.workflow.WorkflowCommon;
37 import org.collectionspace.services.client.DimensionClient;
38 import org.collectionspace.services.client.workflow.WorkflowClient;
39 import org.collectionspace.services.dimension.DimensionsCommon;
40 import org.collectionspace.services.dimension.DimensionsCommonList;
41
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
46
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 /**
51  * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
52  * $LastChangedRevision:  $
53  * $LastChangedDate:  $
54  */
55 public class WorkflowServiceTest extends AbstractServiceTestImpl {
56
57     private final String CLASS_NAME = WorkflowServiceTest.class.getName();
58     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
59     private String knownResourceId = null;
60
61     @Override
62         public String getServicePathComponent() {
63                 return WorkflowClient.SERVICE_PATH_COMPONENT;
64         }
65
66         @Override
67         protected String getServiceName() {
68                 return WorkflowClient.SERVICE_NAME;
69         }
70     
71     @Override
72     protected CollectionSpaceClient getClientInstance() {
73         return new DimensionClient();
74     }
75
76     @Override
77     protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
78         return response.getEntity(AbstractCommonList.class);
79     }
80
81     @Override
82     public void createList(String testName) throws Exception {
83         //empty N/A
84     }
85
86     @Override
87     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
88     public void read(String testName) throws Exception {
89         logger.debug(testBanner(testName, CLASS_NAME));
90         setupRead();
91         DimensionClient client = new DimensionClient();
92         ClientResponse<String> res = client.getWorkflow(knownResourceId);
93         assertStatusCode(res, testName);
94         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
95         WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
96         if (logger.isDebugEnabled() == true) {
97                 logger.debug("Workflow payload is: " + input.getXmlPayload());
98         }
99         Assert.assertNotNull(workflowsCommon);
100     }
101
102 //    @Override
103 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"})
104 //    public void readList(String testName) throws Exception {
105 //        logger.debug(testBanner(testName, CLASS_NAME));
106 //        setupReadList();
107 //        WorkflowClient client = new WorkflowClient();
108 //        ClientResponse<AbstractCommonList> res = client.readList();
109 //        AbstractCommonList list = res.getEntity();
110 //        assertStatusCode(res, testName);
111 //        if (logger.isDebugEnabled()) {
112 //            List<AbstractCommonList.ListItem> items =
113 //                list.getListItem();
114 //            int i = 0;
115 //            for(AbstractCommonList.ListItem item : items){
116 //                logger.debug(testName + ": list-item[" + i + "] " +
117 //                        item.toString());
118 //                i++;
119 //            }
120 //        }
121 //    }
122     
123     @Override
124     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
125     public void update(String testName) throws Exception {
126         logger.debug(testBanner(testName, CLASS_NAME));
127         setupUpdate();
128         updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
129     }    
130
131
132     @Override
133 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"})
134     public void updateNonExistent(String testName) throws Exception {
135         logger.debug(testBanner(testName, CLASS_NAME));
136         setupUpdateNonExistent();
137         // Submit the request to the service and store the response.
138         // Note: The ID used in this 'create' call may be arbitrary.
139         // The only relevant ID may be the one used in update(), below.
140         WorkflowClient client = new WorkflowClient();
141         PoxPayloadOut multipart = createDimensionInstance(NON_EXISTENT_ID);
142         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
143         assertStatusCode(res, testName);
144     }
145
146     @Override
147 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
148     public void delete(String testName) throws Exception {
149         logger.debug(testBanner(testName, CLASS_NAME));
150         setupDelete();
151         WorkflowClient client = new WorkflowClient();
152         ClientResponse<Response> res = client.delete(knownResourceId);
153         assertStatusCode(res, testName);
154     }
155
156     // ---------------------------------------------------------------
157     // Failure outcome tests : means we expect response to fail, but test to succeed
158     // ---------------------------------------------------------------
159
160     // Failure outcome
161     @Override
162 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
163     public void readNonExistent(String testName) throws Exception {
164         logger.debug(testBanner(testName, CLASS_NAME));
165         setupReadNonExistent();
166         WorkflowClient client = new WorkflowClient();
167         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
168         assertStatusCode(res, testName);
169     }
170
171     // Failure outcome
172     @Override
173 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"})
174     public void deleteNonExistent(String testName) throws Exception {
175         logger.debug(testBanner(testName, CLASS_NAME));
176         setupDeleteNonExistent();
177         WorkflowClient client = new WorkflowClient();
178         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
179         assertStatusCode(res, testName);
180     }
181
182     // Failure outcomes
183     // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
184
185     @Override
186     public void createWithEmptyEntityBody(String testName) throws Exception {
187     }
188
189     @Override
190     public void createWithMalformedXml(String testName) throws Exception {
191     }
192
193     @Override
194     public void createWithWrongXmlSchema(String testName) throws Exception {
195     }
196
197     @Override
198     public void updateWithEmptyEntityBody(String testName) throws Exception {
199     }
200
201     @Override
202     public void updateWithMalformedXml(String testName) throws Exception {
203     }
204
205     @Override
206     public void updateWithWrongXmlSchema(String testName) throws Exception {
207     }
208     
209     // ---------------------------------------------------------------
210     // Search tests
211     // ---------------------------------------------------------------
212     
213     public void searchWorkflowDeleted(String testName) throws Exception {
214     }    
215
216     // ---------------------------------------------------------------
217     // Utility tests : tests of code used in tests above
218     // ---------------------------------------------------------------
219
220 //    @Test(dependsOnMethods = {"create", "read"})
221     public void testSubmitRequest() {
222         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK
223         String method = ServiceRequestType.READ.httpMethodName();
224         String url = getResourceURL(knownResourceId);
225         int statusCode = submitRequest(method, url);
226         logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode);
227         Assert.assertEquals(statusCode, EXPECTED_STATUS);
228     }
229
230     // ---------------------------------------------------------------
231     // Utility methods used by tests above
232     // ---------------------------------------------------------------
233     
234     @Override
235     protected PoxPayloadOut createInstance(String identifier) {
236         return createDimensionInstance(identifier);
237     }    
238     
239     private PoxPayloadOut createDimensionInstance(String dimensionValue) {
240         String value = "dimensionValue-" + dimensionValue;
241         String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
242         DimensionsCommon dimensionsCommon = new DimensionsCommon();
243         
244         dimensionsCommon.setValue(value);
245         PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
246         PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
247
248         if (logger.isDebugEnabled()) {
249             logger.debug("To be created, Dimensions common: " + commonPart.asXML());
250             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
251         }
252
253         return multipart;
254     }
255
256         @Override
257     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
258         public void create(String testName) throws Exception {
259                 String csid = this.createTestObject(testName);
260                 if (this.knownResourceId == null) {
261                         this.knownResourceId = csid;
262                 }
263         }
264
265         
266         @Override
267         public void readList(String testName) throws Exception {
268         }       
269                 
270         @Override
271     public void readPaginatedList(String testName) throws Exception {
272                 //empty N/A
273         }
274         
275 }