对 Oracle ADF 应用程序进行集成测试

发布于 2024-10-10 02:48:44 字数 528 浏览 3 评论 0原文

我的服务器上运行着一个 ADF 应用程序。我试图在其上运行一些集成测试用例。我曾经使用 apache cactus 框架在普通 Web 应用程序上运行测试。我的测试用例将扩展 CactusStrutsTestCase 并将运行。 我尝试使用相同的概念来处理 ADF 应用程序。但我收到连接被拒绝错误

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)

所以我的问题是,是否可以使用属于 Cactus 框架一部分的 ServletTestcase 在 ADF 应用程序中进行测试?

谢谢 吉乔伊

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不咬妳我踢妳 2024-10-17 02:48:45

你正在做的事情是可能的。我知道,因为我已经做到了。

首先,放弃真正的 Apache Cactus。它不再受到支持。您想要下载 JSFUnit 并使用它。它使用 Apache Cactus,但仍在积极维护中。

我建议您创建自己的测试用例来扩展 ServletTestCase,而不是直接使用 ServletTestCase。

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();
}
}

接下来,您需要设置 web.xml 文件:

  <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>

最后,当您运行测试用例时,您必须传入 cactus.contextURL 参数。

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

我假设您正在使用 JDeveloper。然后,您可以在“项目属性”>“项目属性”下进行设置。运行/调试/配置文件 ->编辑>启动设置-> Java 选项。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文