I'm stuck trying to run a unit test that makes a web service request. I'm mocking the proxy object of the jax-ws request in my JUnit test using EasyMock.
I have defined the bean using DI in my application-context as follows:
<bean id="mockOrderPort" name="mockOrderPort" class="org.easymock.EasyMock" factory-method="createStrictMock" >
<constructor-arg value="com.proyecti.perama.siman.replica.integration.schema.OrderPort" />
</bean>
This is the test case that is failing:
//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);
Inside the executeTest method, there is the call to the WS using the mocked proxy object:
authenticationResponse = portToServer.authentication(authenticationRequest);
No matter what I try, but it ALWAYS tries to connect to the actual WS, raising the following exception:
authentication request has not been successful. Exception: com.sun.xml.ws.client.ClientTransportException: HTTP Transport error: java.net.ConnectException: Connection refused: connect
Why is the mock object trying to connect instead of returning the object I have created?
Thanks!