001: /*
002: * Danet GmbH
003: * Beratung und Software-Entwicklung
004: * Geschäftstelle AN
005: *
006: * $Id: Basic.java,v 1.3 2006/10/13 13:58:32 drmlipp Exp $
007: *
008: * $Log: Basic.java,v $
009: * Revision 1.3 2006/10/13 13:58:32 drmlipp
010: * Adapted to new environment.
011: *
012: * Revision 1.2 2006/10/07 20:41:34 mlipp
013: * Merged J2EE 1.4 adaptions from test branch.
014: *
015: * Revision 1.1.1.3 2004/08/18 15:18:46 drmlipp
016: * Update to 1.2
017: *
018: * Revision 1.22 2004/01/27 11:45:33 lipp
019: * Preserve newlines when reading process definitions.
020: *
021: * Revision 1.21 2003/10/21 21:00:45 lipp
022: * Moved EJBClientTest to new junit sub-package.
023: *
024: * Revision 1.20 2003/10/07 15:55:57 lipp
025: * Made tests weblogic compatible.
026: *
027: * Revision 1.19 2003/05/14 08:30:07 lipp
028: * Package import behaviour changed.
029: *
030: * Revision 1.18 2003/05/09 10:40:16 huaiyang
031: * test the reading of redefinable header in process.
032: *
033: * Revision 1.17 2003/04/26 16:46:55 lipp
034: * Made unittests and systemtests coexist in eclipse.
035: *
036: * Revision 1.16 2003/04/23 14:28:12 lipp
037: * Improved modelling of header data.
038: *
039: * Revision 1.15 2003/04/16 19:25:04 lipp
040: * Adapted to jdk 1.4
041: *
042: * Revision 1.14 2003/04/08 12:31:23 lipp
043: * Implemented version and category.
044: *
045: * Revision 1.13 2003/04/08 11:49:05 lipp
046: * ResultSignature implemented.
047: *
048: * Revision 1.12 2002/11/06 12:15:18 huaiyang
049: * Add the test of removeClosedProcess.
050: *
051: * Revision 1.11 2002/09/08 18:49:18 lipp
052: * Proper use of packageId and processId.
053: *
054: * Revision 1.10 2002/09/04 20:38:44 lipp
055: * Removed dubious use of id as process definition identifier.
056: *
057: * Revision 1.9 2002/09/02 12:26:51 huaiyang
058: * Use initialProcesses instead of testXPDL.
059: *
060: * Revision 1.8 2002/08/30 13:37:05 lipp
061: * Using Workflow engine facade now.
062: *
063: * Revision 1.7 2002/08/28 10:58:45 huaiyang
064: * Remove the test of importNewProcessDefintions temporarily.
065: *
066: * Revision 1.6 2002/08/28 09:24:12 huaiyang
067: * New method of importNewProcessDefinitions for new procDef spec.
068: *
069: * Revision 1.5 2002/08/26 20:23:14 lipp
070: * Lots of method renames.
071: *
072: * Revision 1.4 2002/08/25 18:51:01 lipp
073: * Extended test case.
074: *
075: * Revision 1.3 2002/08/22 08:47:29 lipp
076: * Some minor optimizations.
077: *
078: * Revision 1.2 2002/02/06 20:45:24 lipp
079: * Test for enabled.
080: *
081: * Revision 1.1 2002/02/03 21:41:42 lipp
082: * Cleaned up unittests.
083: *
084: */
085: package procdef;
086:
087: import java.io.BufferedReader;
088: import java.io.InputStream;
089: import java.io.InputStreamReader;
090:
091: import java.util.ArrayList;
092: import java.util.Collection;
093: import java.util.Iterator;
094:
095: import javax.naming.InitialContext;
096: import javax.security.auth.login.LoginException;
097:
098: import de.danet.an.util.EJBUtil;
099: import de.danet.an.util.junit.EJBClientTest;
100:
101: import de.danet.an.workflow.omgcore.ProcessDataInfo;
102:
103: import de.danet.an.workflow.api.ProcessDefinition;
104: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
105: import de.danet.an.workflow.api.WorkflowServiceFactory;
106:
107: import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
108:
109: import common.UTLoginContext;
110: import junit.framework.Test;
111: import junit.framework.TestCase;
112: import junit.framework.TestSuite;
113:
114: /**
115: * Zusammenstellung der Basis-Testfälle für das Prozessdefinitionsverzeichnis.
116: */
117: public class Basic extends TestCase {
118:
119: private static UTLoginContext plc = null;
120: static {
121: try {
122: plc = new UTLoginContext();
123: plc.login();
124: } catch (LoginException e) {
125: throw new IllegalStateException(e.getMessage());
126: }
127: }
128:
129: /**
130: * Konstruktor zum Erzeugen eines TestCase
131: */
132: public Basic(String name) {
133: super (name);
134: }
135:
136: /**
137: * Stellt diese TestSuite zusammen.
138: */
139: public static Test suite() {
140: TestSuite suite = new TestSuite();
141: suite.addTest(new Basic("connect"));
142: suite.addTest(new Basic("importProcessDefinitions"));
143: suite.addTest(new Basic("listProcessDefinitions"));
144: suite.addTest(new Basic("disableProcessDefinition"));
145: suite.addTest(new Basic("removeProcessDefinition"));
146: suite.addTest(new Basic("getProcessDefinition"));
147: suite.addTest(new Basic("removeClosedProcess"));
148: suite.addTest(new Basic("importProcessDefinitions"));
149: suite.addTest(new Basic("getSignatures"));
150: suite.addTest(new Basic("redefinableHeader"));
151: return new EJBClientTest(plc, suite);
152: }
153:
154: /**
155: * Simple test to check the jndi settings
156: */
157: public void connect() throws Exception {
158: InitialContext ic = new InitialContext();
159: assertTrue(ic != null);
160: }
161:
162: /**
163: * Import the process definitions from a XPDL file
164: * unsing the ProcessDefinitionDirectory bean.
165: */
166: public void importProcessDefinitions() throws Exception {
167: importProcessDefinitions("/procdef/initialProcesses.xml");
168: }
169:
170: /**
171: * Returns a list of all defined process definitions
172: * from the ProcessDefinitionDirectory bean.
173: */
174: public void listProcessDefinitions() throws Exception {
175: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
176: .newInstance().newWorkflowService()
177: .processDefinitionDirectory();
178:
179: Collection processDefinitions = pdd.processDefinitions();
180: assertTrue(processDefinitions.size() > 0);
181: Collection ids = new ArrayList();
182: Collection names = new ArrayList();
183: for (Iterator pdi = processDefinitions.iterator(); pdi
184: .hasNext();) {
185: ProcessDefinition pd = (ProcessDefinition) pdi.next();
186: ids.add(pd.processId());
187: names.add(pd.processName());
188: }
189: assertTrue(ids.contains("jut1"));
190: assertTrue(names.contains("JUnit Test Process 1"));
191: assertTrue(ids.contains("jut2"));
192: assertTrue(names.contains("JUnit Test Process 2"));
193: assertTrue(ids.contains("jut3"));
194: assertTrue(names.contains("JUnit Test Process 3"));
195: assertTrue(ids.contains("jut4"));
196: assertTrue(names.contains("JUnit Test Process 4"));
197: assertTrue(ids.contains("jut5"));
198: assertTrue(names.contains("JUnit Test Process 5"));
199: assertTrue(ids.contains("jut6"));
200: assertTrue(names.contains("JUnit Test Process 6"));
201: assertTrue(ids.contains("jut7"));
202: assertTrue(names.contains("JUnit Test Process 7"));
203: }
204:
205: /**
206: * Disable/Enable ProcessDefinitionDirectory.
207: */
208: public void disableProcessDefinition() throws Exception {
209: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
210: .newInstance().newWorkflowService()
211: .processDefinitionDirectory();
212:
213: Collection processDefinitions = pdd.processDefinitions();
214: assertTrue(processDefinitions.size() > 0);
215: ProcessDefinition pd = (ProcessDefinition) (processDefinitions
216: .iterator().next());
217: assertTrue(pdd.isEnabled(pd.packageId(), pd.processId()));
218: pdd.setEnabled(pd.packageId(), pd.processId(), false);
219: assertTrue(!pdd.isEnabled(pd.packageId(), pd.processId()));
220: pdd.setEnabled(pd.packageId(), pd.processId(), true);
221: assertTrue(pdd.isEnabled(pd.packageId(), pd.processId()));
222: }
223:
224: /**
225: * Removes a given process definition using the ProcessDirectory bean.
226: */
227: public void removeProcessDefinition() throws Exception {
228: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
229: .newInstance().newWorkflowService()
230: .processDefinitionDirectory();
231:
232: ProcessDefinition pd = pdd.lookupProcessDefinition(
233: "ut-procdef", "jut1");
234: assertTrue(pd != null);
235: pdd.removeProcessDefinition("ut-procdef", "jut1");
236: boolean gotEx = false;
237: try {
238: pd = pdd.lookupProcessDefinition("ut-procdef", "jut1");
239: } catch (Exception ex) {
240: gotEx = true;
241: }
242: assertTrue(gotEx);
243: }
244:
245: /**
246: * Returns a process definition
247: * from the ProcessDefinitionDirectory bean.
248: */
249: public ProcessDefinition getProcessDefinition() throws Exception {
250: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
251: .newInstance().newWorkflowService()
252: .processDefinitionDirectory();
253:
254: ProcessDefinition pd = pdd.lookupProcessDefinition(
255: "ut-procdef", "jut2");
256: assertTrue(pd != null);
257: boolean gotEx = false;
258: try {
259: pd = pdd.lookupProcessDefinition("ut-procdef",
260: "doesn't exist");
261: } catch (Exception ex) {
262: gotEx = true;
263: }
264: assertTrue(gotEx);
265: return pd;
266: }
267:
268: public void removeClosedProcess() throws Exception {
269: ProcessDefinition procDef = getProcessDefinition();
270: assertTrue(!procDef.removeClosedProcess());
271: }
272:
273: /**
274: * Test the signatures
275: */
276: public void getSignatures() throws Exception {
277: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
278: .newInstance().newWorkflowService()
279: .processDefinitionDirectory();
280:
281: ProcessDefinition pd = pdd.lookupProcessDefinition(
282: "ut-procdef", "called1");
283: assertTrue(pd != null);
284: assertTrue(pd.processHeader().created().equals("07.04.2003"));
285: assertTrue(pd.processHeader().description().equals("Was tun"));
286: ProcessDataInfo pdi = pd.resultSignature();
287: assertTrue(pdi.keySet().size() == 1);
288: assertTrue(pdi.containsKey("status"));
289: assertTrue(pdi.get("status") == String.class);
290: }
291:
292: /**
293: * Test if the refinableHeader in the package header and in the process
294: * header can be parsed correctly.
295: */
296: public void redefinableHeader() throws Exception {
297: importProcessDefinitions("/procdef/testRedefinableHeader.xml");
298: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
299: .newInstance().newWorkflowService()
300: .processDefinitionDirectory();
301: ProcessDefinition pd = pdd.lookupProcessDefinition(
302: "ut-procdef", "testRedefinableHeader");
303: assertTrue(pd.processHeader().author().equals("tester"));
304: // Redefinable header of version in process overrides the version
305: // defined in the package redefinable header.
306: assertTrue(pd.processHeader().version().equals("1.2"));
307: pdd.removeProcessDefinition("ut-procdef",
308: "testRedefinableHeader");
309: }
310:
311: public static void importProcessDefinitions(String filename)
312: throws Exception {
313: ProcessDefinitionDirectory pdd = WorkflowServiceFactory
314: .newInstance().newWorkflowService()
315: .processDefinitionDirectory();
316: InputStream is = Basic.class.getResourceAsStream(filename);
317: assertTrue(is != null);
318: BufferedReader br = new BufferedReader(new InputStreamReader(
319: is, "ISO-8859-1"));
320: StringBuffer sb = new StringBuffer();
321: String st;
322: while ((st = br.readLine()) != null) {
323: sb.append(st + "\n");
324: }
325: pdd.importProcessDefinitions(sb.toString());
326: Collection processDefinitions = pdd.processDefinitions();
327: assertTrue(processDefinitions.size() > 0);
328: }
329: }
|