我正在使用httpunit来访问服务器.
我需要为此配置代理设置(http和https).
我在settings.xml文件中设置了配置,但是确定似乎忽略了它!?
我想避免尽可能复制配置.
在surefire插件配置中我试过:
<systemPropertyVariables>
    <http.proxyHost>${http.proxyHost}</http.proxyHost>
</systemPropertyVariables>
和
<argLine>-Dhttp.proxyHost=${http.proxyHost}</argLine>
和
<argLine>-Dhttp.proxyHost=${settings.proxies[protocol=http].host}</argLine>
和其他几个组合.
我在单元测试中打印系统属性:
for (String propertyName : new TreeSet<String>(System.getProperties().stringPropertyNames())){
        System.out.println(propertyName + ": " + System.getProperty(propertyName));
    }
到目前为止唯一有效的是显式值,例如:
<systemPropertyVariables>
    <http.proxyHost>myProxy</http.proxyHost>
</systemPropertyVariables>
要么
<argLine>-Dhttp.proxyHost=myProxy</argLine>
但正如我所说,如果可能的话,我不想复制配置.
如何在单元测试中使用settings.xml文件中设置的代理设置?
我正在使用Web客户端.并通过Web客户端成功登录.但是当我发送第二个获取数据的请求时.我有一个例外
com.gargoylesoftware.htmlunit.UnexpectedPage@6d8d73`
但是当我通过url thruogh brouser时,我得到了一个数据Json格式.
码:
webClient.getPage("http://ajax/stream/refresh-box?r=new&id=2323222&")
Thx在先进
当我在3年前探索和使用HttpUnit时,我喜欢它的功能.虽然在3年之后没有跟踪它,但当我向我的同事提出基于它的解决方案时,他告诉我它已被弃用了?apache状态告诉它处于活动状态.如果这是真的,我无法找到.如果这是真的,我会感到震惊.在错误列表中找到并且在过去1年没有找到任何受让人.我应该从这个推断中得出结论,它已被弃用了吗?
我基本上是问的确切同样的问题在这里.如您所见,没有可靠的答案.我想要做的就是发送一个文件HTTPUnit来测试java servlet.
所以,我有一个Java Servlet这个代码(dumbed down):
@WebServlet("/properties/StorePropertyAttachment")
@MultipartConfig
public class StorePropertyAttachment {
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        final Part p = req.getPart("propertyImage");
         ....
    }
}
这是我的测试用例的重要部分:
    ServletRunner servletRunner = new ServletRunner();
    servletRunner.registerServlet("StorePropertyAttachment", StorePropertyAttachment.class.getName());
    WebRequest webRequest = new PostMethodWebRequest(WEB_REQUEST_BASE_URL + STORE_PROPERTIES_ENDPOINT);
    UploadFileSpec spec = new UploadFileSpec(new File("C:/test.jpg"), "multipart/form-data");
    webRequest.setParameter("propertyImage", new UploadFileSpec[] {spec});
    ^^^^^  line 68  ^^^^^
    ServletUnitClient servletClient = servletRunner.newClient();
    WebResponse webResponse = servletClient.getResponse(webRequest);
当我运行它时,我收到此错误:
com.meterware.httpunit.IllegalNonFileParameterException: Parameter 'propertyImage' is not a …我想使用maven 运行这里提供的servlet测试示例.Javaee web api应声明为provided:
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>httpunit</groupId>
        <artifactId>httpunit</artifactId>
        <version>1.7</version>
        <scope>test</scope>
    </dependency>
但是,示例中的一个测试抛出ServletException.NetBeans抱怨说java ee api is missing on project classpath.如何解决这个问题?
编辑
它不是NetBeans问题,而是一个maven问题.