HTTPTransportError - 使用模拟代理对象的意外WS调用

时间:2013-03-21 19:05:55

标签: spring junit mocking jax-ws easymock

我试图运行一个发出Web服务请求的单元测试。我正在使用EasyMock在我的JUnit测试中模拟jax-ws请求的代理对象。

我在应用程序上下文中使用DI定义了bean,如下所示:

<bean id="mockOrderPort" name="mockOrderPort" class="org.easymock.EasyMock" factory-method="createStrictMock" >
    <constructor-arg value="com.proyecti.perama.siman.replica.integration.schema.OrderPort" />
</bean>

这是失败的测试用例:

//II. Fill the authentication response will be used to mock the server calling
final AuthenticationResponse authenticationResponse = new AuthenticationResponse();
authenticationResponse.setToken(encode(TestConstants.EMPTY_TOKEN));

//III. When authentication is called, mock must return the authentication request object created earlier
expect(mockOrderPort.authentication(EasyMock.anyObject(AuthenticationRequest.class))).andReturn(authenticationResponse);

//IV. Make the mock object available for executing the test
replay(mockOrderPort);

//V. Execute the test (call to server is produced inside this method)
executeTest();

//VI. Verify mock behaviour is correct
verify(mockOrderPort);

在executeTest方法中,使用模拟代理对象调用WS:

authenticationResponse = portToServer.authentication(authenticationRequest);

无论我尝试什么,但它总是试图连接到实际的WS,引发以下异常:

authentication request has not been successful. Exception: com.sun.xml.ws.client.ClientTransportException: HTTP Transport error: java.net.ConnectException: Connection refused: connect

为什么模拟对象试图连接而不是返回我创建的对象?

谢谢!

0 个答案:

没有答案