Endpoint tests
The responsibility of endpoint tests is to verify that the wiring and configuration of the endpoints works as intended.
It is often a good idea to use stubs instead of the actual services. We recommend Mockito for stubbing the services behind the endpoints.
JMS
-
Start ActiveMQ (in-mem) programmatically
HTTP
To verify that the HTTP endpoints work as expected it is of course necessary to start a web server. The approach taken here is to run the application (which embeds a web server), but override the implementation behind the endpoints.
REST
- Start Jetty application with stubbed services
- Run requests against the service and verify the expected response (both response code and content).
- REST-assured can simplify the request and assert parts of this.
SOAP
- Start Jetty application with stubbed services
- Run requests against the service and verify the expected response (both response code and content).
CXF example:
@BeforeMethod
public void setUpWSClient() {
ReceiptControlService_Service ss = new ReceiptControlService_Service(wsdlLocation, serviceName);
port = ss.getReceipt();
Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
Map<String,Object> outProps = new HashMap<>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, "userNameTestUser");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
//Password in WSClientPasswordHandlerForTests must match password known/added to WS-server
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, WSClientPasswordHandlerForTests.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
}
@Test
public void testPing() throws Exception {
final String pingResponse = port.ping();
assertEquals(pingResponse, "pong");
}
class WSClientPasswordHandlerForTests implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword("someTestPasswordHere");
}
}