001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2007 Danet GmbH (www.danet.de), BU BTS.
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: EJBInvokerTest.java,v 1.2 2007/03/22 15:49:45 schnelle Exp $
021: *
022: * $Log: EJBInvokerTest.java,v $
023: * Revision 1.2 2007/03/22 15:49:45 schnelle
024: * Component renamed.
025: *
026: * Revision 1.1 2007/03/22 13:49:51 schnelle
027: * Initial release.
028: *
029: */
030: package tools;
031:
032: import java.util.Map;
033:
034: import junit.framework.Test;
035: import junit.framework.TestSuite;
036:
037: import org.xml.sax.helpers.AttributesImpl;
038:
039: import de.danet.an.wfdemo.testejb.TestHome;
040: import de.danet.an.workflow.api.FormalParameter;
041: import de.danet.an.workflow.spis.aii.ToolAgent;
042: import de.danet.an.workflow.tools.EJBInvoker;
043: import de.danet.an.workflow.tools.test.ToolAgentTestBase;
044: import de.danet.an.workflow.util.SAXEventBufferImpl;
045:
046: /**
047: * Test class for the {@link EJBInvoker}.
048: *
049: * @author Dirk Schnelle
050: */
051: public class EJBInvokerTest extends ToolAgentTestBase {
052: /**
053: * Constructs a test case without a name.
054: */
055: public EJBInvokerTest() {
056: this (null);
057: }
058:
059: /**
060: * Constructs a test case with the specified name.
061: * @param name name of the test.
062: */
063: public EJBInvokerTest(String name) {
064: super (name);
065: }
066:
067: /**
068: * Creates this test suite.
069: * @return the test suite.
070: */
071: public static Test suite() {
072: TestSuite suite = new TestSuite();
073:
074: suite.addTest(new EJBInvokerTest("testInvokeBoolean"));
075: suite.addTest(new EJBInvokerTest("testInvokeDouble"));
076: suite.addTest(new EJBInvokerTest("testInvokeBoolean"));
077: suite.addTest(new EJBInvokerTest("testInvokeLong"));
078: suite.addTest(new EJBInvokerTest("testInvokeString"));
079: suite.addTest(new EJBInvokerTest("testInvokeXml"));
080:
081: return suite;
082: }
083:
084: /* (non-Javadoc)
085: * Comment copied from interface or super class.
086: */
087: protected void setUp() throws Exception {
088: super .setUp();
089:
090: login();
091: }
092:
093: /* (non-Javadoc)
094: * Comment copied from interface or super class.
095: */
096: protected void tearDown() throws Exception {
097: logout();
098:
099: super .tearDown();
100: }
101:
102: /* (non-Javadoc)
103: * Comment copied from interface or super class.
104: */
105: public ToolAgent createToolAgent() {
106: return new EJBInvoker();
107: }
108:
109: /**
110: * Basic method call with a string argument.
111: * @throws Exception
112: * Test failed.
113: */
114: public void testInvokeString() throws Exception {
115: FormalParameter[] fps = new FormalParameter[5];
116: fps[0] = new FormalParameter("JndiName", "0",
117: FormalParameter.Mode.IN, FP_TYPE_STRING);
118: fps[1] = new FormalParameter("HomeClass", "1",
119: FormalParameter.Mode.IN, FP_TYPE_STRING);
120: fps[2] = new FormalParameter("Method", "2",
121: FormalParameter.Mode.IN, FP_TYPE_STRING);
122: fps[3] = new FormalParameter("Name", "3",
123: FormalParameter.Mode.IN, FP_TYPE_STRING);
124: fps[4] = new FormalParameter("Result", "3",
125: FormalParameter.Mode.OUT, FP_TYPE_STRING);
126:
127: Map act = new java.util.HashMap();
128: act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
129: act.put(fps[1].id(), TestHome.class.getName());
130: act.put(fps[2].id(), "sayHello");
131: act.put(fps[3].id(), "Dirk");
132:
133: invokeTool(fps, act);
134:
135: assertEquals("Hello Dirk", getToolResult(fps[4]));
136: }
137:
138: /**
139: * Basic method call with integer arguments.
140: * @throws Exception
141: * Test failed.
142: */
143: public void testInvokeLong() throws Exception {
144: FormalParameter[] fps = new FormalParameter[6];
145: fps[0] = new FormalParameter("JndiName", "0",
146: FormalParameter.Mode.IN, FP_TYPE_STRING);
147: fps[1] = new FormalParameter("HomeClass", "1",
148: FormalParameter.Mode.IN, FP_TYPE_STRING);
149: fps[2] = new FormalParameter("Method", "2",
150: FormalParameter.Mode.IN, FP_TYPE_STRING);
151: fps[3] = new FormalParameter("Num1", "3",
152: FormalParameter.Mode.IN, FP_TYPE_INT);
153: fps[4] = new FormalParameter("Num2", "4",
154: FormalParameter.Mode.IN, FP_TYPE_INT);
155: fps[5] = new FormalParameter("Result", "5",
156: FormalParameter.Mode.OUT, FP_TYPE_INT);
157:
158: Map act = new java.util.HashMap();
159: act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
160: act.put(fps[1].id(), TestHome.class.getName());
161: act.put(fps[2].id(), "add");
162: act.put(fps[3].id(), new Long(5));
163: act.put(fps[4].id(), new Long(3));
164:
165: invokeTool(fps, act);
166:
167: assertEquals(new Long(8), getToolResult(fps[5]));
168: }
169:
170: /**
171: * Basic method call with integer arguments.
172: * @throws Exception
173: * Test failed.
174: */
175: public void testInvokeDouble() throws Exception {
176: FormalParameter[] fps = new FormalParameter[5];
177: fps[0] = new FormalParameter("JndiName", "0",
178: FormalParameter.Mode.IN, FP_TYPE_STRING);
179: fps[1] = new FormalParameter("HomeClass", "1",
180: FormalParameter.Mode.IN, FP_TYPE_STRING);
181: fps[2] = new FormalParameter("Method", "2",
182: FormalParameter.Mode.IN, FP_TYPE_STRING);
183: fps[3] = new FormalParameter("Value", "3",
184: FormalParameter.Mode.IN, FP_TYPE_FLOAT);
185: fps[4] = new FormalParameter("Result", "4",
186: FormalParameter.Mode.OUT, FP_TYPE_INT);
187:
188: Map act = new java.util.HashMap();
189: act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
190: act.put(fps[1].id(), TestHome.class.getName());
191: act.put(fps[2].id(), "sqrt");
192: act.put(fps[3].id(), new Double(43.7));
193:
194: invokeTool(fps, act);
195:
196: assertEquals(new Double(Math.sqrt(43.7)), getToolResult(fps[4]));
197: }
198:
199: /**
200: * Basic method call with integer arguments.
201: * @throws Exception
202: * Test failed.
203: */
204: public void testInvokeXml() throws Exception {
205: FormalParameter[] fps = new FormalParameter[5];
206: fps[0] = new FormalParameter("JndiName", "0",
207: FormalParameter.Mode.IN, FP_TYPE_STRING);
208: fps[1] = new FormalParameter("HomeClass", "1",
209: FormalParameter.Mode.IN, FP_TYPE_STRING);
210: fps[2] = new FormalParameter("Method", "2",
211: FormalParameter.Mode.IN, FP_TYPE_STRING);
212: fps[3] = new FormalParameter("Value", "3",
213: FormalParameter.Mode.IN, FP_TYPE_SCHEMA_SAX);
214: fps[4] = new FormalParameter("Result", "4",
215: FormalParameter.Mode.OUT, FP_TYPE_INT);
216:
217: SAXEventBufferImpl sax = new SAXEventBufferImpl();
218: sax.startDocument();
219: AttributesImpl attrs = new AttributesImpl();
220: sax.startElement("", "test", "test", attrs);
221: sax.endElement("", "test", "test");
222: sax.endDocument();
223:
224: Map act = new java.util.HashMap();
225: act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
226: act.put(fps[1].id(), TestHome.class.getName());
227: act.put(fps[2].id(), "toString");
228: act.put(fps[3].id(), sax);
229:
230: invokeTool(fps, act);
231:
232: assertEquals("<test/>", getToolResult(fps[4]));
233: }
234:
235: /**
236: * Basic method call with integer arguments.
237: * @throws Exception
238: * Test failed.
239: */
240: public void testInvokeBoolean() throws Exception {
241: FormalParameter[] fps = new FormalParameter[5];
242: fps[0] = new FormalParameter("JndiName", "0",
243: FormalParameter.Mode.IN, FP_TYPE_STRING);
244: fps[1] = new FormalParameter("HomeClass", "1",
245: FormalParameter.Mode.IN, FP_TYPE_STRING);
246: fps[2] = new FormalParameter("Method", "2",
247: FormalParameter.Mode.IN, FP_TYPE_STRING);
248: fps[3] = new FormalParameter("Value", "3",
249: FormalParameter.Mode.IN, FP_TYPE_BOOL);
250: fps[4] = new FormalParameter("Result", "4",
251: FormalParameter.Mode.OUT, FP_TYPE_STRING);
252:
253: Map act = new java.util.HashMap();
254: act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
255: act.put(fps[1].id(), TestHome.class.getName());
256: act.put(fps[2].id(), "toString");
257: act.put(fps[3].id(), Boolean.TRUE);
258:
259: invokeTool(fps, act);
260:
261: assertEquals(Boolean.TRUE.toString(), getToolResult(fps[4]));
262: }
263: }
|