【问题标题】:Write Junit Test for ServiceMix web-service为 ServiceMix 网络服务编写 Junit 测试
【发布时间】:2018-09-29 06:13:21
【问题描述】:

我习惯使用 Spring 和编写 Spring RESTful Web 服务。我编写 Spring 控制器、传入数据然后验证取回正确的 JSON 数据没有问题。

现在,我有一份新工作,他们将 RESTful Web 服务作为 OSGI jar 部署到 ServiceMix 4.5。

我的方法有如下定义:

   @GET
   @Path("myWebService")  
   @Trace
   @Override    
   @Produces({MediaType.APPLICATION_JSON})
   @WebResult(name="isDuplicate")
   public MyResponse myWebService(@QueryParam("field1") final String field1, @QueryParam("fieldData") final String fieldData) throws SOAPException  
   {
       final Session session = BundleActivator.getSessionFactory().getCurrentSession();
       Transaction transaction = session.beginTransaction();

       Boolean retVal = new SimpleTransaction<Boolean, Void>()
       {
           @Override
           public Boolean execute(Void nothing)
           {                   
               Criteria criteria = session.createCriteria(tableName);

               try
               {
                    // some logic here   
               }
               catch (JSONException e1)
               {
                   throw new RuntimeException(e1.getMessage());
               }

               List<Object> recordList = (List<Object>)criteria.list();
               if(recordList.size()  > 0)
               {
                   return true;
               }

               return false;
           }

       }.run(transaction, null);

   }
} 

这不是所有的代码,但非常接近。

所以,我需要做一些与我的 Spring 单元测试类似的事情。 在不了解所有深层细节的情况下,我知道我加载了 Spring 应用程序上下文,然后我向 RESTful Web 服务发出了一个模拟请求,并使用正确的 json 数据传入了我的动词(GET、POST、PUT DELETE),然后我取回模拟 http 响应。

当我使用 Google 搜索如何测试 Spring MVC RESTful Web 服务时,我可以轻松找到所有类型的示例。当我为 ServiceMix OSGI Web 服务做同样的事情时,我发现的不多。所以,我正在寻找可以接近和查看的示例或网址。

如果我需要提供更多信息,请告诉我。

非常感谢!

【问题讨论】:

    标签: rest junit apache-servicemix


    【解决方案1】:

    这是我们使用 CamelTestSupport 测试骆驼路线的链接,在您的情况下修改端点是 Web 服务 url。

    http://www.softwarepassion.com/servicemix-fuseesb-unit-testing-your-routes/

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 1970-01-01
      • 2011-02-13
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      • 2021-02-03
      相关资源
      最近更新 更多