Reputation: 1811
I have a problem :
I have two component A and B (Two wars ) :
A for storage(Neo4J) and B for search(Elasticsearch).
the communication between the components is managed by Spring Integration using HTTP Inbound/Outbound .
Here is MY configuration files for spring integration : Server A (Storage)
<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"/>
In the other side : Server 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"/>
My question :
I want to do an integration test from the server A to Server B To server A .
What's the best strategy ? It's possible to do it without mocking ? It's possible to do it without starting the servers ? (Servers A and B down)
Best Regards Nabil Belakbir
Upvotes: 1
Views: 2678
Reputation: 174484
See the testing examples and advanced testing examples for ideas about how to test flows independently.
Upvotes: 1
Reputation: 7283
I'm not sure is this you want for integration tests.
You can use Spring mvc test framework to test inbound gateway without starting up any server.
@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());
}
But if you want to test the gateway only, you'd better sperate the spring configuration into different xmls(a-http-gateway.xml for the InboundGateway alone, for example).
On the other hand, A server has to be started up for test outbound gateway without stubbing or mocking. Maybe you are interested in https://github.com/dreamhead/moco, it's a simple framework to stub http server.
Upvotes: 2