package org.jboss.test.jbossnet.ejbsimple;
import junit.framework.Test;
import org.jboss.test.jbossnet.JBossNetTestBase;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import java.net.URL;
import java.util.Arrays;
public class EJBEndpointTestCase extends JBossNetTestBase
{
private QName HELLO_REMOTE_SERVICE = new QName("http://" + getServerHost() + ":8080/jboss-net/services/HelloRemote", "HelloRemoteService");
private QName HELLO_LOCAL_SERVICE = new QName("http://" + getServerHost() + ":8080/jboss-net/services/HelloLocal", "HelloLocalService");
public EJBEndpointTestCase(String name)
{
super(name);
}
HelloRemote hello;
HelloRemote helloLocal;
public void setUp() throws Exception
{
super.setUp();
URL wsdlURL = new URL(SERVICES_LOCATION + "/HelloRemote?wsdl");
hello = (HelloRemote)createService(wsdlURL, HELLO_REMOTE_SERVICE).getPort(HelloRemote.class);
wsdlURL = new URL(SERVICES_LOCATION + "/HelloLocal?wsdl");
helloLocal = (HelloRemote)createService(wsdlURL, HELLO_LOCAL_SERVICE).getPort(HelloRemote.class);
}
protected String getAxisConfiguration()
{
return "jbossnet/ejbsimple/client/client-config.wsdd";
}
public void testClientParser() throws Exception
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
assertEquals("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl", docFactory.getClass().getName());
}
public void testHello() throws Exception
{
assertEquals("Hello World!", hello.hello("World"));
assertEquals("Hello World!", helloLocal.hello("World"));
}
public void testHowdy() throws Exception
{
HelloData data = new HelloData();
data.setName("CGJ");
assertEquals("Howdy CGJ!", hello.howdy(data));
assertEquals("Howdy CGJ!", helloLocal.howdy(data));
}
public void testTypedArrays() throws Exception
{
HelloData[] values = new HelloData[]{new HelloData(), new HelloData()};
assertTrue(Arrays.equals(hello.typedArrays(values), values));
assertTrue(Arrays.equals(helloLocal.typedArrays(values), values));
}
public void testArrays() throws Exception
{
Object[] values = new Object[]{new String("Test"), new Integer(1), new HelloData()};
assertTrue(Arrays.equals(hello.arrays(values), values));
assertTrue(Arrays.equals(helloLocal.arrays(values), values));
}
public void testReverse() throws Exception
{
Object[] values = new Object[]{new String("Test"), new Integer(1), new HelloData()};
Object[] expected = new Object[]{new HelloData(), new Integer(1), new String("Test")};
assertTrue(Arrays.equals(hello.reverse(values), expected));
assertTrue(Arrays.equals(helloLocal.reverse(values), expected));
}
public void testElement() throws Exception
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
Document doc = docFactory.newDocumentBuilder().newDocument();
Element testElement = doc.createElement("TestElement");
assertEquals(testElement.getNodeName(), hello.element(testElement).getNodeName());
assertEquals(testElement.getNodeName(), helloLocal.element(testElement).getNodeName());
}
public static Test suite() throws Exception
{
return getDeploySetup(EJBEndpointTestCase.class, "jbossnet-ejbsimple.ear");
}
public static void main(String[] args)
{
junit.textui.TestRunner.run(EJBEndpointTestCase.class);
}
}