]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
61f858207e38e1cbfa4acab124c654545b0a2a5b
[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         @Override
68         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
69         return new DimensionClient(clientPropertiesFilename);
70         }
71
72     //
73     // Test overrides
74     //
75     
76         @Override
77         public void create(String testName) throws Exception {
78                 String csid = this.createTestObject(testName);
79                 if (this.knownResourceId == null) {
80                         this.knownResourceId = csid;
81                 }
82         }
83
84     @Override
85     public void read(String testName) throws Exception {
86         setupRead();
87         DimensionClient client = new DimensionClient();
88         Response res = client.getWorkflow(knownResourceId);
89         try {
90                 assertStatusCode(res, testName);
91                 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
92                 WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
93                 if (logger.isDebugEnabled() == true) {
94                         logger.debug("Workflow payload is: " + input.getXmlPayload());
95                 }
96                 Assert.assertNotNull(workflowsCommon);
97         } finally {
98                 if (res != null) {
99                 res.close();
100             }
101         }
102     }
103     
104     //
105     // FIXME: REM - This test should be a subclass of BaseServiceTest and *not* AbstractPoxServiceTestImpl
106     //
107     
108     @Override
109     public void update(String testName) throws Exception {
110         setupUpdate();
111         updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWTRANSITION_DELETE, WorkflowClient.WORKFLOWSTATE_DELETED);
112     }    
113
114     @Override
115     public void delete(String testName) throws Exception {
116         // Do nothing.  N/A
117     }
118         
119     public void searchWorkflowDeleted(String testName) throws Exception {
120         // Do nothing.  N/A
121     }    
122
123         @Override
124         public void readList(String testName) throws Exception {
125                 // Do nothing.  N/A
126         }       
127                 
128         @Override
129     public void readPaginatedList(String testName) throws Exception {
130                 // Do nothing.  N/A
131         }
132
133         @Override
134         public void CRUDTests(String testName) {
135                 // TODO Auto-generated method stub              
136         }
137
138         @Override
139         protected WorkflowCommon updateInstance(WorkflowCommon commonPartObject) {
140                 // TODO Auto-generated method stub
141                 return null;
142         }
143
144         @Override
145         protected void compareUpdatedInstances(WorkflowCommon original,
146                         WorkflowCommon updated) throws Exception {
147                 // TODO Auto-generated method stub
148                 
149         }
150     
151         /*
152          * (non-Javadoc)
153          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
154          */
155         @Override
156         public void createList(String testName) throws Exception {
157                 //empty N/A
158         }
159     
160     public void testSubmitRequest() {
161         // Do nothing.  N/A
162     }
163
164     // ---------------------------------------------------------------
165     // Utility methods used by tests above
166     // ---------------------------------------------------------------
167     
168     @Override
169     protected PoxPayloadOut createInstance(String identifier) {
170         String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
171         return createInstance(identifier, dimensionsCommonPartName);
172     }    
173     
174         @Override
175         protected PoxPayloadOut createInstance(String commonPartName,
176                         String identifier) {
177                 return createDimensionInstance(commonPartName, identifier);
178         }
179     
180         /*
181          * We're using a DimensionsCommon instance to test the workflow service.
182          */
183     private PoxPayloadOut createDimensionInstance(String dimensionValue) {
184         String commonPartName = new DimensionClient().getCommonPartName();
185         return createDimensionInstance(commonPartName, dimensionValue);
186     }
187         
188         /*
189          * We're using a DimensionsCommon instance to test the workflow service.
190          */
191     private PoxPayloadOut createDimensionInstance(String commonPartName,
192                 String dimensionValue) {
193         String measurementUnit = "measurementUnit-" + dimensionValue;
194         DimensionsCommon dimensionsCommon = new DimensionsCommon();
195         
196         dimensionsCommon.setMeasurementUnit(measurementUnit);
197         PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
198         PayloadOutputPart commonPart = multipart.addPart(commonPartName, dimensionsCommon);
199
200         if (logger.isDebugEnabled()) {
201             logger.debug("To be created, Dimensions common: " + commonPart.asXML());
202             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
203         }
204
205         return multipart;
206     }   
207 }