Question

I have an ADF application which running on my server. I was trying to run some integration test cases on it. I used to use apache cactus framework to run testing on normal web applications. My test cases would extend CactusStrutsTestCase and will be run. I tried to approach, ADF application with same concept. But I am getting connection refused error

java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)

So my question is that , is it possible to do testing in ADF application with a ServletTestcase which is part of Cactus framework ?

Thanks Jijoy

Was it helpful?

Solution

What you are doing is possible. I know, because I've done it.

First off, ditch genuine Apache Cactus. It's not being supported anymore. You want to download JSFUnit and use that instead. It makes use of Apache Cactus but is still being actively maintained.

I suggest you create your own test case which extends ServletTestCase instead of using ServletTestCase directly.

public class EJBTestCase extends ServletTestCase {
protected InitialContext context;

public static final String userId = "demouser";


public EJBTestCase(String string) {
    super(string);
}

private InitialContext getInitialContext() throws NamingException {
  Hashtable env = new Hashtable();

  env.put(Context.SECURITY_PRINCIPAL, "username");
  env.put(Context.SECURITY_CREDENTIALS, "password");


     return new InitialContext(env);
}

public void setUp() throws Exception {
    super.setUp();

    context = getInitialContext();

}

public void tearDown() throws Exception {
    super.tearDown();

    context.close();
}

public EJBTestCase() {
    super();
}
}

Next, you need to setup your web.xml file:

  <filter>
    <filter-name>JSFUnitFilter</filter-name>
    <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>
  </filter>
...

    <filter-mapping>
        <filter-name>JSFUnitFilter</filter-name>
        <servlet-name>ServletTestRunner</servlet-name>
      </filter-mapping>
      <filter-mapping>
        <filter-name>JSFUnitFilter</filter-name>
        <servlet-name>ServletRedirector</servlet-name>
      </filter-mapping>

...

  <servlet>
    <servlet-name>ServletRedirector</servlet-name>
    <servlet-class>org.jboss.jsfunit.framework.JSFUnitServletRedirector</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>ServletTestRunner</servlet-name>
    <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>
  </servlet>

...

  <servlet-mapping>
    <servlet-name>ServletRedirector</servlet-name>
    <url-pattern>/ServletRedirector</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletTestRunner</servlet-name>
    <url-pattern>/ServletTestRunner</url-pattern>
  </servlet-mapping>

Finally, when you run your test cases you must pass in the cactus.contextURL parameter.

-Dcactus.contextURL=http://127.0.0.1:7101/MyApp

I assume you are using JDeveloper. You can then set this under Project Properties > Run/Debug/Profile -> Edit > Launch Settings -> Java Options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top