【发布时间】:2021-03-28 16:22:33
【问题描述】:
我是单元/集成测试的新手。因此寻找给定场景的最佳方法。 我有用 Spring Integration 编写的遗留应用程序 (REST)。我已迁移到 Spring Boot 的同一应用程序。现在我想知道,如何在控制器中模拟网关以及如何测试网关、路由器。应用结构为:
控制器:
@RestController
@RequestMapping(value = "/acct")
public class AcctOpenImpl implements AcctOpen {
/**
* AcctMgmt Gateway Interface.
*/
@Autowired
AcctOpenService acctopenmgmtServiceGateway;
@Override
@RequestMapping(value = "/product/{product_id_num}", method = RequestMethod.GET)
public ResponseEntity<RetrieveAppProdAplnResponse> rtrvAppProdAplnByQueryParam(
@PathVariable("product_id_num") final Long productIdNum) throws BusinessException,
TechnicalException {
Map<String, Object> headers = getHeaders();
RetrieveAppProdAplnResponse response = this.acctopenmgmtServiceGateway.rtrvAppProdApln(request, headers);
ResponseEntity<RetrieveAppProdAplnResponse> retrieveAppProdResponse = new ResponseEntity<RetrieveAppProdAplnResponse>(
response, HttpStatus.OK);
return retrieveAppProdResponse;
}
}
服务接口:
public interface AcctOpenService {
public RetrieveAppProdAplnResponse rtrvAppProdApln(RetrieveAppProdAplnRequest retrieveAppProdAplnRequest,
@Headers Map<String, Object> customHeaderMap) throws BusinessException, TechnicalException;
}
geteways.xml:
<int:gateway id="acctopenmgmtServiceGateway" service-interface="com.hsbc.group.depositproduct.svc.gateway.AcctOpenService"
default-reply-channel="acctopenmgmtReplyChannel" error-channel="acctopenmgmtErrorChannel">
<int:method name="rtrvAppProdApln" request-channel="rtrvAppProdAplnRequestChannel" />
</int:gateway>
si-channels.xml:
<int:channel id="rtrvAppProdAplnRequestChannel"/>
si-routers.xml:
<int:router input-channel="rtrvAppProdAplnRequestChannel" default-output-channel="acctopenmgmtReplyChannel" expression="headers.SERVICE_HEADER.consumerEntyId.ctryCde.toLowerCase()+headers.SERVICE_HEADER.consumerEntyId.groupMbr+'RtrvAppProdAplnRequestChannel'" />
si-chain.xml:
<int:chain input-channel="usMMBIRtrvAppProdAplnRequestChannel" output-channel="acctopenmgmtReplyChannel">
<int:transformer method="formatRequest" ref="usRtrvAppProdAplnTransformer"/>
<int:service-activator method="rtrvAppProdApln" ref="rtrvAppProdAplnActivator" />
<int:transformer method="parseResponse" ref="usRtrvAppProdAplnTransformer"/>
</int:chain>
si-transformers.xml:
<bean id="usRtrvAppProdAplnTransformer" class="com.hsbc.group.depositproduct.us.svc.transformer.RetrieveAppProdAplnTransformer">
</bean>
您能否建议给定场景的最佳方法(单元测试或集成测试)。另外,如果有人举出任何例子说明我该如何开始,那将不胜感激。 提前致谢。
【问题讨论】:
标签: spring-boot unit-testing spring-integration integration-testing