如何使用 JUnit 测试 Java EE Web 服务端点方法?
我在Eclipse中使用Spring和MyBatis框架和标准Maven目录结构。我知道我可以通过为它创建一个 JUnit 测试用例来简单地测试每个方法。但是,我想知道如何使用@WebService、@WebMethod、@WebResult 标签进行测试。
@WebService(endpointInterface = "com.ws.BrowserService", name = "BrowserService", targetNamespace = "http://abc.def.com")
public interface BrowserService {
/**
* Runs the provided SQL query and returns the result.
* @param queryText is the SQL query text.
* @return The query result is returned in the form of List<Object>.
*/
@WebMethod
@WebResult(name = "Object")
public List<Object> runQuery(
@WebParam(name = "QueryText") String queryText);
}
编辑
执行
@WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {
@Autowired
private QueryMapper queryMapper;
public List<Object> runQuery(String queryText) {
List<Object> queryResult= new ArrayList<Object>();
queryResult = queryMapper.runQuery(queryText);
return queryResult;
}
}