001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: WSIF.java,v 1.2 2006/09/29 12:32:08 drmlipp Exp $
021: *
022: * $Log: WSIF.java,v $
023: * Revision 1.2 2006/09/29 12:32:08 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.2 2003/12/19 13:01:45 drmlipp
027: * Updated to 1.1rc1
028: *
029: * Revision 1.8 2003/10/21 21:00:45 lipp
030: * Moved EJBClientTest to new junit sub-package.
031: *
032: * Revision 1.7 2003/10/08 12:39:40 huaiyang
033: * make test weblogic compatible.
034: *
035: * Revision 1.6 2003/06/27 09:44:03 lipp
036: * Fixed copyright/license information.
037: *
038: * Revision 1.5 2003/06/02 14:19:05 huaiyang
039: * change the check.
040: *
041: * Revision 1.4 2003/05/28 15:17:21 huaiyang
042: * integrate the testWSIF- and testWSIFBasic.xml
043: *
044: * Revision 1.3 2003/05/28 13:59:39 huaiyang
045: * new test of googleSearch.
046: *
047: * Revision 1.2 2003/04/16 19:58:49 lipp
048: * Adapted to jdk 1.4
049: *
050: * Revision 1.1 2003/03/26 11:14:34 huaiyang
051: * initial.
052: *
053: *
054: */
055: package tools;
056:
057: import java.util.Iterator;
058: import java.util.Map;
059:
060: import junit.framework.Test;
061: import junit.framework.TestSuite;
062: import process.WfMOpenTestCase;
063: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
064: import de.danet.an.workflow.api.ProcessMgr;
065: import de.danet.an.workflow.omgcore.WfProcess;
066: import de.danet.an.util.junit.EJBClientTest;
067:
068: /**
069: * Test the tool of WSIFDynamicInvocationTool.
070: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
071: * @version 1.0
072: */
073: public class WSIF extends WfMOpenTestCase {
074: private ProcessDefinitionDirectory pdd = null;
075:
076: /**
077: * Constructor of this TestCase
078: * @param name a <code>String</code> value
079: */
080: public WSIF(String name) {
081: super (name);
082: }
083:
084: /**
085: * Construct this test suite.
086: * @return a <code>Test</code> value
087: */
088: public static Test suite() {
089: TestSuite suite = new TestSuite();
090: suite.addTest(new WSIF("importProcessDefinitions"));
091: // suite.addTest(new WSIF("checkWSIFToolInvocation"));
092: // suite.addTest(new WSIF("googleSearch"));
093: suite.addTest(new WSIF("removeProcessDefinition"));
094: return new EJBClientTest(plc, suite);
095: }
096:
097: /**
098: * Initialisation.
099: * The <code>setUp</code> method defines the way a state change is
100: * realized. Override this method to change this way.
101: * @exception Exception if an error occurs
102: */
103: protected void setUp() throws Exception {
104: super .setUp();
105: xpdlFile = "/tools/testWSIF.xml";
106: System.out.println("xpdlFile = " + xpdlFile);
107: pdd = workflowService().processDefinitionDirectory();
108: }
109:
110: /**
111: * Test a simple process definition with a simple soap tool invocation.
112: * @exception Exception if an error occurs
113: */
114: public void checkWSIFToolInvocation() throws Exception {
115: // create the process
116: ProcessDefinitionDirectory pdd = workflowService()
117: .processDefinitionDirectory();
118: // dynamic invoke WSIF with WSDL definition as DOM tree.
119: ProcessMgr pmgr = pdd.processMgr("st-testWSIF", "testWSIF1");
120: WfProcess process = pmgr.createProcess(defaultRequester());
121: process.start();
122: checkResult(process);
123: // dynamic invoke WSIF with WSDL definition retrieved from URL.
124: ProcessMgr pmgr2 = pdd.processMgr("st-testWSIF", "testWSIF2");
125: WfProcess process2 = pmgr2.createProcess(defaultRequester());
126: process2.start();
127: checkResult(process2);
128: }
129:
130: /**
131: * Test a soap tool invocation which returns a complex data type of JDOM
132: * element.
133: * @exception Exception if an error occurs
134: */
135: public void googleSearch() throws Exception {
136: ProcessMgr pmgr3 = pdd.processMgr("st-testWSIF", "testWSIF3");
137: WfProcess process3 = pmgr3.createProcess(defaultRequester());
138: process3.start();
139: Thread.sleep(30000);
140: Map map = (Map) process3.result();
141: for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
142: String name = (String) it2.next();
143: System.out.println("name = " + name);
144: if (name.equals("searchresult")) {
145: String returnResult = (String) map.get(name);
146: System.out.println("return = " + returnResult);
147: }
148: }
149: }
150:
151: private void checkResult(WfProcess process) throws Exception {
152: // wait so that invocation of the WSIF tool for the first activity
153: // is completed. Wait time is needed for wsdl fetch and wsif dynamic
154: // calling.
155: Thread.sleep(10000);
156: Map map = (Map) process.result();
157: for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
158: String name = (String) it2.next();
159: if (name.equals("Result")) {
160: float stockquote = Float.parseFloat((String) map
161: .get(name));
162: System.out.println("stockquote of " + name + " = "
163: + stockquote);
164: assertTrue(stockquote != 0);
165: }
166: }
167: }
168:
169: /**
170: * Test a simple process definition with a simple soap tool invocation.
171: * @exception Exception if an error occurs
172: */
173: public void removeProcessDefinition() throws Exception {
174: removeProcessDefinition("st-testWSIF", "testWSIF1");
175: removeProcessDefinition("st-testWSIF", "testWSIF2");
176: removeProcessDefinition("st-testWSIF", "testWSIF3");
177: }
178: }
|