如何解决生产者的合同消息 (kafka) 测试期望存在密钥,否则为空指针
在从 spring-cloud-contract-maven-plugin 生成的 ContractVerifierTest 中,需要密钥,否则我会得到空指针异常。我使用 kafkaTemplate.send(topic-name,pojo),故意省略了分区和键。
SuppressWarnings("rawtypes")
public class ContractVerifierTest extends BaseClass {
@Inject ContractVerifierMessaging contractVerifierMessaging;
@Inject ContractVerifierObjectMapper contractVerifierObjectMapper;
@Test
public void validate_shouldSendFoo() throws Exception {
// when:
trigger();
// then:
ContractVerifierMessage response = contractVerifierMessaging.receive("test-topic",contract(this,"shouldSendFoo.yml"));
assertthat(response).isNotNull();
// and:
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsstring(response.getPayload()));
assertthatJson(parsedJson).field("['specversion']").isEqualTo("1.0");
assertthatJson(parsedJson).field("['type']").isEqualTo("");
... assertions left out
...
如果没有key发送消息,则生成的测试失败并出现NullPointer异常。
对此有什么建议吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。