### XFire Home Bug/Issue Reporting Download FAQ Get Involved License News Stack Comparison Support User's Guide XFire Team ### M5 Javadocs Reports ### M6-SNAPSHOT Javadocs Reports ### Developers Developer Space CVS Building Architecture Interesting Projects Release Process | Testing is of critical importance for any web service, yet it is often a pain to do. The class AbstractXFireTest is designed to help simplify this process. ## Creating Request Messages Testing is a two step process. First you must create or gather some request messages for your service. These are often written by hand, but they can also be gathered with a tool such as SOAPScope or Apache Axis's TCPMon. To use TCPMon you must first generate some client code. This can be in .NET or Axis or GLUE or whatever. Then follow these instructions on the Axis website to set TCPMon up. Once that is set up, invoke the service with your client code and capture the message. Now every time you build your code you can verify that it does indeed function with a particular client (at least the request portion - the response is another animal). Take the messages that you have captured or written, and save them as files in your classpath (i.e. in src/test/your/app/Message1.xml). ## Testing and Verification Next, create your unit test class.
    public class TestServiceTest
        extends AbstractXFireTest
    {
        public void testBeanService() throws Exception
        {
            Document response =
                invokeService( "Test", "/org/your/classpath/Message1.xml" );

            addNamespace( "test", "urn:Test" );
            assertInvalid( "//s:Fault" );
            assertValid( "//test:Response", response );
            assertValid( "//test:Response[text()='howdy']", response );
        }
    }
From the above, you see it is simply a matter of invoking the method "invokeService" where the first parameter is the name of the service and the second parameter is the classpath location of your xml message. The fun part occurs in the validation though. Using XPath we can verify that message contain or don't contain various elements, attributes, and text. In the first assertion, we verify that no fault occurred. In the second that the "test:Response" element exists. In the last instance, we assert that the element contains the text "howdy" (SOAP message often contain that word if you aren't aware). Also, be aware that assertValid() returns the Node that it finds which can be handy in some situations. There are other fun methods that you can use as well for testing. Lets say that your message needs to change throughout the test. There is a convenient little method called "setNode" that lets you set values on particular nodes:
    SAXReader reader = new SAXReader();
    Document doc = reader.read( getResourceAsStream("/your/app/Message2.xml") );
    setNode( doc, "//m:SomeId", m.getId().toString() );
    Document response = invokeService("TestService", doc);
Here we're reading in a document on the classpath, then we set the node which matches "//m:SomeId" to the id that we desire. We get out the response and can test to our hearts content.