javaeclipseweb-servicesfitnessewsimport

FitNesse: Enabling a FitNesse Fixture to call a method on the Server Side


I have implemented a Web Service with certain methods using Eclipse.

Then I exported it to a WAR file, which is to be to be used with Tomcat.

Then I used wsimport to create 'stubs' for my web service.

The 'stubs' are just interfaces.

Now I want to know how to call the web service through my FitNesse fixture I'll be writing.

I'm coding in JAVA.

Is there any method through which I can call the web service method from my FitNesse fixture, keeping in mind the 'stubs' generated for the web service?


Solution

  • There are many ways to do what you describe. You could, for instance, create your own fixture (i.e. class containing test code) in Java that uses the stubs you generated to call your service. Or (what I prefer) is to call the services directly using HTTP posts, configured in the wiki, and execute XPath queries, configuring the XPaths either by writing Java code or on the wiki, on the responses you receive to check you service implementation.

    The latter approach is supported by fixtures (and ready to run FitNesse installation) I put on GitHub (https://github.com/fhoeben/hsac-fitnesse-fixtures). For specific information on how to call a web service see https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki/4.-XmlHttpTest-Examples and https://github.com/fhoeben/hsac-fitnesse-fixtures/wiki/6.-SoapCallMapColumnFixture-Examples depending on whether you want to use Slim or Fit.

    Sample for Slim:

    !2 Body via scenario
    
    Using a scenario allows us to generate multiple request, only changing certain values.
    
    !*> Scenario definition
    !define POST_BODY_2 { {{{
    <s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
      <s11:Body>
        <ns1:GetCityWeatherByZIP xmlns:ns1="http://ws.cdyne.com/WeatherWS/">
          <ns1:ZIP>@{zip}</ns1:ZIP>
        </ns1:GetCityWeatherByZIP>
      </s11:Body>
     </s11:Envelope>
    }}} }
    
     |script|xml http test|
    
     |table template |send request                                                            |
     |post           |${POST_BODY_2} |to                   |${URL}                            |
     |check          |response status|200                                                      |
     |show           |response                                                                 |
     |register prefix|weather        |for namespace             |http://ws.cdyne.com/WeatherWS/|
     |check          |xPath          |//weather:City/text()|@{City}                       |
    *!
    
     |send request       |
     |zip  |City         |
     |10007|New York     |
     |94102|San Francisco|