spring-cloud-contract - 生产者的合同消息(kafka)测试期望密钥存在,否则为空指针
问题描述
在从spring-cloud-contract-maven-plugin生成的ContractVerifierTest中,密钥是预期的,否则我会得到 nullpointer 异常。我使用 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
...
如果消息在没有密钥的情况下发送,则生成的测试将失败并出现 NullPointer 异常。
对此有什么建议吗?
解决方案
推荐阅读
- java - Java:处理 Gui 表单
- c# - C#中的常量字符串的嵌套列表
- javascript - 排序表中的数字
- angular - 复杂的 Angular 元素(Web 组件)或 Angular 库
- mongodb - MongoDB 中多个位置标识符最经济的替代方案是什么?
- android - recyclerView 滚动滞后
- ionic3 - 错误:未捕获(承诺):TypeError:无法读取未定义的属性“拆分”->在使用离子sqlite创建本地数据库时
- java - 连接两个数组 Stream 时出现 ArrayStoreException
- javascript - 将应用程序制造商服务器脚本与云存储桶连接
- ios - 如何使用 NumberFormatter 保持相同位置的前数和后零?