XFire Web服务的单元测试
你不必发布到tomcat等容器中就可以进行测试,常用的测试类常继承abstractxfirespringtest 抽象类。abstractxfirespringtest 类又实现了abstractxfiretest 类,abstractxfiretest 类是testcase的子类,所以你可以使用junit进行单元测试。
下面看一个例子:
|
package com.kuaff.xfire.samples; import java.net.url; import org.apache.xbean.spring.context.classpathxmlapplicationcontext; import org.codehaus.xfire.client.client; import org.codehaus.xfire.service.endpoint; import org.codehaus.xfire.spring.abstractxfirespringtest; import org.jdom.document; import org.springframework.context.applicationcontext; public class mathclienttest extends abstractxfirespringtest { public void testservice() throws exception { document wsdl = getwsdldocument("mathservice"); printnode(wsdl); } protected applicationcontext createcontext() { return new classpathxmlapplicationcontext(new string[] { "/org/codehaus/xfire/spring/xfire.xml", "/meta-inf/xfire/services.xml" }); } } |
你必须实现createcontext方法,这个方法将得到应用上下文。在这个例子中返回了一个classpathxmlapplicationcontext上下文,它通过类路径的下配置文件生成这个上下文对象。
剩下的工具就是写单元测试的方法,和junit的方式一样。getwsdldocument方法可以获取指定web服务的wsdl文档。如果你要测试发布的服务,还可以通过
invokeservice方法测试:
|
document response = invokeservice("mathservice", "add.xml"); addnamespace("k", "http://www.kuaff.com/xfire/mathservice"); assertvalid("//soap:body/k:addresponse", response); printnode(response); |
文章整理:iocblog
Tag:
XFire
,TOMCAT
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。