001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.test;
046:
047: import junit.framework.Test;
048: import org.apache.commons.logging.Log;
049: import org.apache.commons.logging.LogFactory;
050: import org.obe.client.api.repository.RepositoryException;
051: import org.obe.xpdl.model.pkg.XPDLPackage;
052: import org.obe.xpdl.model.workflow.WorkflowProcess;
053: import org.obe.xpdl.parser.XPDLParser;
054: import org.obe.xpdl.parser.XPDLParserException;
055: import org.obe.xpdl.parser.dom4j.Dom4JXPDLParser;
056: import org.wfmc.wapi.WMFilter;
057: import org.wfmc.wapi.WMProcessDefinitionState;
058:
059: import java.io.IOException;
060: import java.io.InputStream;
061: import java.util.Properties;
062:
063: /**
064: * Tests the process repository. This version uses whatever repositories
065: * are configured in the server.
066: *
067: * @author Adrian Price
068: */
069: public class ProcessRepositoryTest extends AbstractRepositoryTest {
070: private static final Log _logger = LogFactory
071: .getLog(InstanceRepositoryTest.class);
072: protected static final String[] TESTS = { "testInitialize",
073: "testCreatePackage", "testFindPackage", "testFindPackages",
074: "testUpdatePackage", "testFindWorkflowProcess",
075: "testFindWorkflowProcesses",
076: "testFindProcessDefinitionState",
077: "testUpdateProcessDefinitionState", "testDeletePackage",
078: "testPurge", "testUninitialize" };
079: private static XPDLPackage _pkg;
080: private static String _packageId1;
081: private static String _packageId2;
082: private static String _packageName1;
083: private static String _packageName2;
084: private static String _procDefId1;
085: private static String _procDefId2;
086: private static String _procDefId3;
087: private static String _procDefName1;
088:
089: public static Test suite() {
090: return cactusSuite(ProcessRepositoryTest.class, TESTS);
091: }
092:
093: public ProcessRepositoryTest(String name) {
094: super (name, null);
095: }
096:
097: protected ProcessRepositoryTest(String name, Properties svcMgrProps) {
098: super (name, svcMgrProps);
099: }
100:
101: protected Log getLogger() {
102: return _logger;
103: }
104:
105: // The sole purpose of this 'test' is to initialize the repositories for
106: // the ensuing tests.
107: public void testInitialize() throws IOException,
108: RepositoryException {
109: initializeRepositories();
110: }
111:
112: public void testCreatePackage() throws RepositoryException {
113: try {
114: XPDLParser parser = new Dom4JXPDLParser();
115: InputStream in = getClass().getResourceAsStream(
116: "/org/obe/test/WMClientTest1.xpdl");
117: if (in == null)
118: fail("Failed to load resource /org/obe/test/WMClientTest1.xpdl");
119: _pkg = parser.parse(in);
120: in.close();
121: _packageId1 = _pkg.getId();
122: _packageName1 = _pkg.getName();
123: WorkflowProcess[] processes = _pkg.getWorkflowProcess();
124: assertEquals("Package contains wrong number of workflows",
125: 2, processes.length);
126: _procDefId1 = processes[0].getId();
127: _procDefName1 = processes[0].getName();
128: _procDefId2 = processes[1].getId();
129: _processRepository.createPackage(_pkg);
130:
131: in = getClass().getResourceAsStream(
132: "/org/obe/test/WMClientTest2.xpdl");
133: if (in == null)
134: fail("Failed to load resource /org/obe/test/WMClientTest2.xpdl");
135: XPDLPackage pkg2 = parser.parse(in);
136: in.close();
137: _packageId2 = pkg2.getId();
138: _packageName2 = pkg2.getName();
139: processes = pkg2.getWorkflowProcess();
140: assertEquals("Package contains wrong number of workflows",
141: 1, processes.length);
142: _procDefId3 = processes[0].getId();
143: _processRepository.createPackage(pkg2);
144:
145: getLogger().info("testCreatePackage passed");
146: } catch (IOException e) {
147: getLogger().error("Error in testCreatePackage()", e);
148: fail("testCreatePackage failed: " + e);
149: } catch (XPDLParserException e) {
150: getLogger().error("Error in testCreatePackage()", e);
151: fail("testCreatePackage failed: " + e);
152: }
153: }
154:
155: public void testFindPackage() throws RepositoryException {
156: XPDLPackage pkg = _processRepository.findPackage(_packageId1);
157: assertEquals("Incorrect package ID", _packageId1, pkg.getId());
158: assertEquals("Incorrect package name", _packageName1, pkg
159: .getName());
160: pkg = _processRepository.findPackage(_packageId2);
161: assertEquals("Incorrect package ID", _packageId2, pkg.getId());
162: assertEquals("Incorrect package name", _packageName2, pkg
163: .getName());
164: getLogger().info("testFindPackage passed");
165: }
166:
167: public void testFindPackages() throws RepositoryException {
168: WMFilter simpleFilter = new WMFilter("packageId", WMFilter.EQ,
169: _packageId1);
170: WMFilter sqlFilter = new WMFilter("packageId = '" + _packageId2
171: + "' AND name = '" + _packageName2 + '\'');
172:
173: XPDLPackage[] pkgs = _processRepository
174: .findPackages(null, true);
175: checkCount("Unfiltered", 2, pkgs);
176:
177: pkgs = _processRepository.findPackages(simpleFilter, true);
178: checkCount("Simple filtered", 1, pkgs);
179:
180: pkgs = _processRepository.findPackages(sqlFilter, true);
181: checkCount("SQL filtered", 1, pkgs);
182:
183: pkgs = _processRepository.findPackages(null, false);
184: checkIds("Unfiltered",
185: new String[] { _packageId1, _packageId2 }, pkgs);
186:
187: pkgs = _processRepository.findPackages(simpleFilter, false);
188: checkIds("Simple filtered", new String[] { _packageId1 }, pkgs);
189:
190: pkgs = _processRepository.findPackages(sqlFilter, false);
191: checkIds("SQL filtered", new String[] { _packageId2 }, pkgs);
192:
193: getLogger().info("testFindPackages passed");
194: }
195:
196: public void testUpdatePackage() throws RepositoryException {
197: _processRepository.updatePackage(_pkg);
198: getLogger().info("testUpdatePackage passed");
199: }
200:
201: public void testFindWorkflowProcess() throws RepositoryException {
202: WorkflowProcess process = _processRepository
203: .findWorkflowProcess(_procDefId1);
204: assertEquals("Wrong process ID", _procDefId1, process.getId());
205: process = _processRepository.findWorkflowProcess(_procDefId2);
206: assertEquals("Wrong process ID", _procDefId2, process.getId());
207: process = _processRepository.findWorkflowProcess(_procDefId3);
208: assertEquals("Wrong process ID", _procDefId3, process.getId());
209: getLogger().info("testFindWorkflowProcess passed");
210: }
211:
212: public void testFindWorkflowProcesses() throws RepositoryException {
213: WMFilter simpleFilter = new WMFilter("packageId", WMFilter.EQ,
214: _packageId1);
215: WMFilter sqlFilter = new WMFilter("packageId = '" + _packageId1
216: + "' AND name = '" + _procDefName1 + '\'');
217:
218: WorkflowProcess[] processes = _processRepository
219: .findWorkflowProcesses((WMFilter) null, true);
220: checkCount("Unfiltered", 3, processes);
221:
222: processes = _processRepository.findWorkflowProcesses(
223: simpleFilter, true);
224: checkCount("Simple filtered", 2, processes);
225:
226: processes = _processRepository.findWorkflowProcesses(sqlFilter,
227: true);
228: checkCount("SQL filtered", 1, processes);
229:
230: processes = _processRepository.findWorkflowProcesses(
231: (WMFilter) null, false);
232: checkIds("Unfiltered", new String[] { _procDefId1, _procDefId2,
233: _procDefId3 }, processes);
234:
235: processes = _processRepository.findWorkflowProcesses(
236: simpleFilter, false);
237: checkIds("Simple filtered", new String[] { _procDefId1,
238: _procDefId2 }, processes);
239:
240: processes = _processRepository.findWorkflowProcesses(sqlFilter,
241: false);
242: checkIds("SQL filtered", new String[] { _procDefId1 },
243: processes);
244:
245: getLogger().info("testFindWorkflowProcesses passed");
246: }
247:
248: public void testFindProcessDefinitionState()
249: throws RepositoryException {
250: int state = _processRepository
251: .findProcessDefinitionState(_procDefId1);
252: assertEquals("Wrong process definition state",
253: WMProcessDefinitionState.ENABLED_INT, state);
254: state = _processRepository
255: .findProcessDefinitionState(_procDefId3);
256: assertEquals("Wrong process definition state",
257: WMProcessDefinitionState.ENABLED_INT, state);
258: getLogger().info("testFindProcessDefinitionState passed");
259: }
260:
261: public void testUpdateProcessDefinitionState() throws Exception {
262: int newState = WMProcessDefinitionState.DISABLED_INT;
263: _processRepository.updateProcessDefinitionState(_procDefId3,
264: newState);
265:
266: // Must commit the transaction otherwise we won't see the update.
267: if (_runTestInTransaction) {
268: commitTransaction();
269: beginTransaction();
270: }
271: int state = _processRepository
272: .findProcessDefinitionState(_procDefId3);
273: assertEquals("Wrong process definition state", newState, state);
274: getLogger().info("testUpdateProcessDefinitionState passed");
275: }
276:
277: public void testDeletePackage() throws Exception {
278: _processRepository.deletePackage(_packageId1);
279: _processRepository.deletePackage(_packageId2);
280:
281: // Must commit the transaction otherwise we won't see the delete.
282: if (_runTestInTransaction) {
283: commitTransaction();
284: beginTransaction();
285: }
286: XPDLPackage[] pkgs = _processRepository
287: .findPackages(null, true);
288: assertEquals("Failed to delete package", 0, pkgs.length);
289: WorkflowProcess[] processes = _processRepository
290: .findWorkflowProcesses((WMFilter) null, true);
291: assertEquals("Failed to delete process definitions", 0,
292: processes.length);
293: getLogger().info("testDeletePackage passed");
294: }
295:
296: public void testPurge() throws RepositoryException {
297: _processRepository.purge();
298: getLogger().info("testPurge passed");
299: }
300:
301: public void testUninitialize() throws IOException,
302: RepositoryException {
303: uninitializeRepositories();
304: }
305: }
|