/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2007 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: EJBInvokerTest.java 2321 2007-03-22 15:49:45Z schnelle $
*
* $Log$
* Revision 1.1 2007/03/22 13:49:51 schnelle
* Initial release.
*
*/
package tools;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.xml.sax.helpers.AttributesImpl;
import de.danet.an.wfdemo.testejb.TestHome;
import de.danet.an.workflow.api.FormalParameter;
import de.danet.an.workflow.spis.aii.ToolAgent;
import de.danet.an.workflow.tools.EJBInvoker;
import de.danet.an.workflow.tools.test.ToolAgentTestBase;
import de.danet.an.workflow.util.SAXEventBufferImpl;
/**
* Test class for the {@link EJBInvoker}.
*
* @author Dirk Schnelle
*/
public class EJBInvokerTest extends ToolAgentTestBase {
/**
* Constructs a test case without a name.
*/
public EJBInvokerTest() {
this(null);
}
/**
* Constructs a test case with the specified name.
* @param name name of the test.
*/
public EJBInvokerTest(String name) {
super(name);
}
/**
* Creates this test suite.
* @return the test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new EJBInvokerTest("testInvokeBoolean"));
suite.addTest(new EJBInvokerTest("testInvokeDouble"));
suite.addTest(new EJBInvokerTest("testInvokeBoolean"));
suite.addTest(new EJBInvokerTest("testInvokeLong"));
suite.addTest(new EJBInvokerTest("testInvokeString"));
suite.addTest(new EJBInvokerTest("testInvokeXml"));
return suite;
}
/* (non-Javadoc)
* Comment copied from interface or super class.
*/
protected void setUp() throws Exception {
super.setUp();
login();
}
/* (non-Javadoc)
* Comment copied from interface or super class.
*/
protected void tearDown() throws Exception {
logout();
super.tearDown();
}
/* (non-Javadoc)
* Comment copied from interface or super class.
*/
public ToolAgent createToolAgent() {
return new EJBInvoker();
}
/**
* Basic method call with a string argument.
* @throws Exception
* Test failed.
*/
public void testInvokeString() throws Exception {
FormalParameter[] fps = new FormalParameter[5];
fps[0] = new FormalParameter("JndiName", "0", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[1] = new FormalParameter("HomeClass", "1", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[2] = new FormalParameter("Method", "2", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[3] = new FormalParameter("Name", "3", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[4] = new FormalParameter("Result", "3", FormalParameter.Mode.OUT,
FP_TYPE_STRING);
Map act = new java.util.HashMap();
act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
act.put(fps[1].id(), TestHome.class.getName());
act.put(fps[2].id(), "sayHello");
act.put(fps[3].id(), "Dirk");
invokeTool(fps, act);
assertEquals("Hello Dirk", getToolResult(fps[4]));
}
/**
* Basic method call with integer arguments.
* @throws Exception
* Test failed.
*/
public void testInvokeLong() throws Exception {
FormalParameter[] fps = new FormalParameter[6];
fps[0] = new FormalParameter("JndiName", "0", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[1] = new FormalParameter("HomeClass", "1", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[2] = new FormalParameter("Method", "2", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[3] = new FormalParameter("Num1", "3", FormalParameter.Mode.IN,
FP_TYPE_INT);
fps[4] = new FormalParameter("Num2", "4", FormalParameter.Mode.IN,
FP_TYPE_INT);
fps[5] = new FormalParameter("Result", "5", FormalParameter.Mode.OUT,
FP_TYPE_INT);
Map act = new java.util.HashMap();
act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
act.put(fps[1].id(), TestHome.class.getName());
act.put(fps[2].id(), "add");
act.put(fps[3].id(), new Long(5));
act.put(fps[4].id(), new Long(3));
invokeTool(fps, act);
assertEquals(new Long(8), getToolResult(fps[5]));
}
/**
* Basic method call with integer arguments.
* @throws Exception
* Test failed.
*/
public void testInvokeDouble() throws Exception {
FormalParameter[] fps = new FormalParameter[5];
fps[0] = new FormalParameter("JndiName", "0", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[1] = new FormalParameter("HomeClass", "1", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[2] = new FormalParameter("Method", "2", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[3] = new FormalParameter("Value", "3", FormalParameter.Mode.IN,
FP_TYPE_FLOAT);
fps[4] = new FormalParameter("Result", "4", FormalParameter.Mode.OUT,
FP_TYPE_INT);
Map act = new java.util.HashMap();
act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
act.put(fps[1].id(), TestHome.class.getName());
act.put(fps[2].id(), "sqrt");
act.put(fps[3].id(), new Double(43.7));
invokeTool(fps, act);
assertEquals(new Double(Math.sqrt(43.7)), getToolResult(fps[4]));
}
/**
* Basic method call with integer arguments.
* @throws Exception
* Test failed.
*/
public void testInvokeXml() throws Exception {
FormalParameter[] fps = new FormalParameter[5];
fps[0] = new FormalParameter("JndiName", "0", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[1] = new FormalParameter("HomeClass", "1", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[2] = new FormalParameter("Method", "2", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[3] = new FormalParameter("Value", "3", FormalParameter.Mode.IN,
FP_TYPE_SCHEMA_SAX);
fps[4] = new FormalParameter("Result", "4", FormalParameter.Mode.OUT,
FP_TYPE_INT);
SAXEventBufferImpl sax = new SAXEventBufferImpl();
sax.startDocument();
AttributesImpl attrs = new AttributesImpl();
sax.startElement("", "test", "test", attrs);
sax.endElement("", "test", "test");
sax.endDocument();
Map act = new java.util.HashMap();
act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
act.put(fps[1].id(), TestHome.class.getName());
act.put(fps[2].id(), "toString");
act.put(fps[3].id(), sax);
invokeTool(fps, act);
assertEquals("<test/>", getToolResult(fps[4]));
}
/**
* Basic method call with integer arguments.
* @throws Exception
* Test failed.
*/
public void testInvokeBoolean() throws Exception {
FormalParameter[] fps = new FormalParameter[5];
fps[0] = new FormalParameter("JndiName", "0", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[1] = new FormalParameter("HomeClass", "1", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[2] = new FormalParameter("Method", "2", FormalParameter.Mode.IN,
FP_TYPE_STRING);
fps[3] = new FormalParameter("Value", "3", FormalParameter.Mode.IN,
FP_TYPE_BOOL);
fps[4] = new FormalParameter("Result", "4", FormalParameter.Mode.OUT,
FP_TYPE_STRING);
Map act = new java.util.HashMap();
act.put(fps[0].id(), "java:ejb/WfMOpenTestEJB");
act.put(fps[1].id(), TestHome.class.getName());
act.put(fps[2].id(), "toString");
act.put(fps[3].id(), Boolean.TRUE);
invokeTool(fps, act);
assertEquals(Boolean.TRUE.toString(), getToolResult(fps[4]));
}
}