ttt
ttt

Reputation: 4004

CXF (SOAP) Web Services integration test

Just implemented the SOAP Web Service using CXF. It is easy for me to write some unit tests using the mock framework. But not quite sure what's the best way to write some integration test for my web services. The implementation is something like this:

@Autowired
private InvoiceService invoiceService;

@Webservice(endpointinterface="xxx") 
public Invoice retrieveInvoiceById(String id) {
    Invoice invoice = invoiceService.getInvoiceById(id);
    return invoice;
}

The InvoiceService will invoke the method to retrieve the invoice from a text file or some file system and then return. So how should I write the integration test to test the whole?

Thanks guys.

Upvotes: 2

Views: 4704

Answers (1)

Paulius Matulionis
Paulius Matulionis

Reputation: 23415

Write your unit tests so that the actual test will start Jetty server and expose your web service as real endpoint during test run. If you are using any database, use Derby or some other database which supports in-memory feature.

For e.g. just declare your endpoint in your test context spring file:

<jaxws:endpoint id="someProxy"
                implementor="#yourWebServiceImplBean"
                wsdlLocation="src/main/webapp/WEB-INF/wsdl/InvoiceService.wsdl"
                address="http://0.0.0.0:12345/YourService/services/InvoiceService"/>

This is enough to start Jetty instance and expose your web service. This will start Jetty instance on port: 12345. Autowire this bean into your test class and you are ready to call methods.

Also you need to include this dependency in order Jetty to be run in unit tests.

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
    <scope>test</scope>
</dependency>

Upvotes: 1

Related Questions