繁体   English   中英

弹簧集成的集成测试

[英]Integration testing with spring integration

我有个问题 :

我有两个组件A和B(两场战争):

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

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

这是Spring集成的MY配置文件:服务器A(存储)

<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:

    <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

我不确定你是否想进行集成测试。

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

@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配置编入不同的xmls(例如,仅针对InboundGateway的a-http-gateway.xml)。

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

有关如何独立测试流的想法,请参阅测试示例高级测试示例

暂无
暂无

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

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