首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用spring集成进行集成测试

使用spring集成进行集成测试
EN

Stack Overflow用户
提问于 2013-07-16 07:50:41
回答 2查看 2.6K关注 0票数 1

我有个问题:

我有两个组件A和B(两个wars ):

A用于存储(Neo4J),B用于搜索(Elasticsearch)。

组件之间的通信由Spring Integration使用HTTP Inbound/Outbound进行管理。

下面是我的spring集成配置文件:服务器A(存储)

代码语言:javascript
复制
<int:annotation-config/>
<bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>

 <int:gateway id="searchGateway"
             service-interface="xxxxx.IAuditSearchService"/>

<int-http:outbound-gateway auto-startup="true"
                           request-channel="sendRequest"
                           url="http://localhost:8081/B/api/es"
                           extract-request-payload="true"/>

<int-http:inbound-gateway request-channel="searchResult"
                          request-payload-type="xxxxx.SearchResult"
                          path="/api/searchResult"
                          supported-methods="POST"/>

<int:object-to-json-transformer auto-startup="true"
                                id="objectToJson" input-channel="searchRequest"
                                output-channel="sendRequest">
</int:object-to-json-transformer>

<int:json-to-object-transformer input-channel="searchReply"
                                auto-startup="true"
                                id="jsonToObject" output-channel="searchResult"
                                type="xxxxxxxx.SearchResult">
</int:json-to-object-transformer>

<int:channel id="searchRequest"/>
<int:channel id="sendRequest"/>
<int:channel id="searchReply"/>
<int:channel id="searchResult"/>

在另一端:服务器B:

代码语言:javascript
复制
    <int:annotation-config/>
<beans:bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>

<int-http:inbound-gateway request-channel="searchRequest"
                          reply-channel="searchReply"
                          path="/api/es"
                          request-payload-type="xxxx.AuditChange"
                          supported-methods="POST"/>


<int:gateway id="searchGateway"
             service-interface="xxxx.IAbSearchResult"/>

<int-http:outbound-gateway auto-startup="true"
                           request-channel="searchResult"
                           url="http://localhost:9080/A/api/searchResult"/>


<int:json-to-object-transformer id="jsonToObject" input-channel="searchRequest"
                                type="xxxxxx.AuditChange"/>
<int:object-to-json-transformer id="objectToJson" input-channel="searchReply" output-channel="searchResult"/>

<int:channel id="searchRequest"/>
<!--<int:channel id="esDelete"/>-->
<int:channel id="searchReply"/>
<int:channel id="searchResult"/>

我的问题是:

我想做一个从服务器A到服务器B再到服务器A的集成测试。

最好的策略是什么?可以在不嘲笑的情况下做到这一点吗?可以在不启动服务器的情况下完成吗?(服务器A和B已关闭)

最好的问候Nabil Belakbir

EN

回答 2

Stack Overflow用户

发布于 2013-07-16 09:18:15

我不确定这是不是你想要的集成测试。

您可以使用Spring mvc测试框架来测试入站网关,而无需启动任何服务器。

代码语言:javascript
复制
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { /*omitted*/ })
@WebAppConfiguration
public class HttpInboundGatewayIntegrationTests {
    private MockMvc mockMvc;

    @Autowired
    private WebApplicationContext wac;

    @Before
    public void setup() throws Exception {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    @Test
    public void testInboundGateway()
        throws Exception {
    //

        mockMvc.perform(get("/api/searchResult").
            param("aParam", aParam).
            param("anotherParam",anotherParam)).
            andExpect(status().isForbidden());
}

但是,如果您只想测试网关,那么最好将spring配置放入不同的InboundGateway (例如,只针对xmls的a-http-gateway.xml)。

另一方面,必须为测试出站网关启动服务器,而不使用存根或模拟。也许你对https://github.com/dreamhead/moco感兴趣,它是一个用来存根http服务器的简单框架。

票数 2
EN

Stack Overflow用户

发布于 2013-07-16 11:14:36

有关如何独立测试流的想法,请参阅testing examplesadvanced testing examples

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17665812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档