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