]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
44f115c505ca97be98d2fc1b7271981b6e9056fe
[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 org.collectionspace.services.client.CollectionSpaceClient;
26 import org.collectionspace.services.client.PayloadOutputPart;
27 import org.collectionspace.services.client.PoxPayloadIn;
28 import org.collectionspace.services.client.PoxPayloadOut;
29
30 import org.collectionspace.services.jaxb.AbstractCommonList;
31 import org.collectionspace.services.workflow.WorkflowCommon;
32 import org.collectionspace.services.client.DimensionClient;
33 import org.collectionspace.services.client.workflow.WorkflowClient;
34 import org.collectionspace.services.dimension.DimensionsCommon;
35
36 import org.jboss.resteasy.client.ClientResponse;
37
38 import org.testng.Assert;
39
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
45  * $LastChangedRevision:  $
46  * $LastChangedDate:  $
47  */
48 public class WorkflowServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, WorkflowCommon> {
49
50     private final String CLASS_NAME = WorkflowServiceTest.class.getName();
51     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
52     private String knownResourceId = null;
53
54     @Override
55         public String getServicePathComponent() {
56                 return WorkflowClient.SERVICE_PATH_COMPONENT;
57         }
58
59         @Override
60         protected String getServiceName() {
61                 return WorkflowClient.SERVICE_NAME;
62         }
63     
64     @Override
65     protected CollectionSpaceClient getClientInstance() {
66         return new DimensionClient();
67     }
68
69     //
70     // Test overrides
71     //
72     
73         @Override
74         public void create(String testName) throws Exception {
75                 String csid = this.createTestObject(testName);
76                 if (this.knownResourceId == null) {
77                         this.knownResourceId = csid;
78                 }
79         }
80
81     @Override
82     public void read(String testName) throws Exception {
83         setupRead();
84         DimensionClient client = new DimensionClient();
85         ClientResponse<String> res = client.getWorkflow(knownResourceId);
86         try {
87                 assertStatusCode(res, testName);
88                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
89                 WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
90                 if (logger.isDebugEnabled() == true) {
91                         logger.debug("Workflow payload is: " + input.getXmlPayload());
92                 }
93                 Assert.assertNotNull(workflowsCommon);
94         } finally {
95                 if (res != null) {
96                 res.releaseConnection();
97             }
98         }
99     }
100     
101     //
102     // FIXME: REM - This test should be a subclass of BaseServiceTest and *not* AbstractPoxServiceTestImpl
103     //
104     
105     @Override
106     public void update(String testName) throws Exception {
107         setupUpdate();
108         updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWTRANSITION_DELETE, WorkflowClient.WORKFLOWSTATE_DELETED);
109     }    
110
111     @Override
112     public void delete(String testName) throws Exception {
113         // Do nothing.  N/A
114     }
115         
116     public void searchWorkflowDeleted(String testName) throws Exception {
117         // Do nothing.  N/A
118     }    
119
120         @Override
121         public void readList(String testName) throws Exception {
122                 // Do nothing.  N/A
123         }       
124                 
125         @Override
126     public void readPaginatedList(String testName) throws Exception {
127                 // Do nothing.  N/A
128         }
129
130         @Override
131         public void CRUDTests(String testName) {
132                 // TODO Auto-generated method stub              
133         }
134
135         @Override
136         protected WorkflowCommon updateInstance(WorkflowCommon commonPartObject) {
137                 // TODO Auto-generated method stub
138                 return null;
139         }
140
141         @Override
142         protected void compareUpdatedInstances(WorkflowCommon original,
143                         WorkflowCommon updated) throws Exception {
144                 // TODO Auto-generated method stub
145                 
146         }
147     
148         /*
149          * (non-Javadoc)
150          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
151          */
152         @Override
153         public void createList(String testName) throws Exception {
154                 //empty N/A
155         }
156     
157     public void testSubmitRequest() {
158         // Do nothing.  N/A
159     }
160
161     // ---------------------------------------------------------------
162     // Utility methods used by tests above
163     // ---------------------------------------------------------------
164     
165     @Override
166     protected PoxPayloadOut createInstance(String identifier) {
167         String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
168         return createInstance(identifier, dimensionsCommonPartName);
169     }    
170     
171         @Override
172         protected PoxPayloadOut createInstance(String commonPartName,
173                         String identifier) {
174                 return createDimensionInstance(commonPartName, identifier);
175         }
176     
177         /*
178          * We're using a DimensionsCommon instance to test the workflow service.
179          */
180     private PoxPayloadOut createDimensionInstance(String dimensionValue) {
181         String commonPartName = new DimensionClient().getCommonPartName();
182         return createDimensionInstance(commonPartName, dimensionValue);
183     }
184         
185         /*
186          * We're using a DimensionsCommon instance to test the workflow service.
187          */
188     private PoxPayloadOut createDimensionInstance(String commonPartName,
189                 String dimensionValue) {
190         String measurementUnit = "measurementUnit-" + dimensionValue;
191         DimensionsCommon dimensionsCommon = new DimensionsCommon();
192         
193         dimensionsCommon.setMeasurementUnit(measurementUnit);
194         PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
195         PayloadOutputPart commonPart = multipart.addPart(commonPartName, dimensionsCommon);
196
197         if (logger.isDebugEnabled()) {
198             logger.debug("To be created, Dimensions common: " + commonPart.asXML());
199             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
200         }
201
202         return multipart;
203     }
204         
205 }