简体   繁体   English

创建一个简单的SOAP服务器

[英]creating a simple SOAP server

I have a Java project which talks to a SOAP server. 我有一个与SOAP服务器对话的Java项目。 I need to debug my application on my local machine. 我需要在本地计算机上调试应用程序。 I do not want my application to get connected to the main SOAP server. 我不希望我的应用程序连接到主SOAP服务器。 I need to have a fake SOAP web server to which my application gets connected. 我需要有一个与应用程序连接的伪SOAP Web服务器。

I want it to be as simple as possible. 我希望它尽可能简单。 So, I want the server to returns a specific response for any request it receives! 因此,我希望服务器为收到的任何请求返回特定的响应! Is there any way by which I can reach my goal? 有什么方法可以实现我的目标?

You don't have to build a real server for testing/debuging your code. 您不必构建用于测试/调试代码的真实服务器。 you can use a Mock. 您可以使用模拟。

This way: 这条路:

  • you don't change your real code, 您不会更改您的真实代码,
  • the testing code is reusable, 测试代码是可重用的,
  • you don't need to implement logic, just tell it what is the expected call results 您不需要实现逻辑,只需告诉它预期的通话结果是什么
  • you test only your own class (there might be bugs in the soap server) 您只测试自己的课程(肥皂服务器中可能存在错误)

The most popular mocking framework is Mockito. 最受欢迎的模拟框架是Mockito。

It can be as simple as: 它可以很简单:

import static org.mockito.Mockito.*;
import static org.junit.Assert.*;

@Test
public void test1()  {
        //  create mock
        MyClass test = mock(MyClass.class);

        // define return value for method createSoapCall()
        when(test.createSoapCall()).thenReturn(43);

        // use mock in test....
        assertEquals(test.createSoapCall(), 43);
}

tutorial: http://www.vogella.com/tutorials/Mockito/article.html 教程: http//www.vogella.com/tutorials/Mockito/article.html

official site: http://site.mockito.org/ 官方网站: http//site.mockito.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM