暂存提交

This commit is contained in:
2026-07-31 16:53:07 +08:00
parent 45358ef40f
commit 704cb15ccf
98 changed files with 1944 additions and 134 deletions
@@ -3,6 +3,7 @@ package com.baiyue.common.event;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
@@ -12,11 +13,12 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("跨区域事件信封契约")
class EventEnvelopeTest {
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
@Test
void 标准Uuid事件可以通过校验并完成序列化往返() throws Exception {
void standardUuidEventPassesValidationAndSerializationRoundTrip() throws Exception {
EventEnvelope source = validEnvelope(EventIdentifiers.newUuid());
source.requireValid();
@@ -29,14 +31,14 @@ class EventEnvelopeTest {
}
@Test
void 合法Ulid可以作为事件标识() {
void validUlidCanBeUsedAsEventIdentifier() {
EventEnvelope envelope = validEnvelope("01J8Z4QX9K7M2N3P4R5S6T7V8W");
assertThat(EventEnvelopeValidator.validate(envelope)).isEmpty();
}
@Test
void 校验器一次返回全部基础错误() {
void validatorReturnsAllBasicErrorsAtOnce() {
EventEnvelope envelope = new EventEnvelope(
"bad-id", "bad_type", 0, null, null, null, " ", "bad-type", " ",
-1, 0L, " ", " ", "bad-cause", null, "bad-hash");
@@ -51,7 +53,7 @@ class EventEnvelopeTest {
}
@Test
void 负载摘要可计算并校验() {
void payloadDigestCanBeCalculatedAndValidated() {
byte[] payload = "{\"orderId\":\"90001\"}".getBytes(StandardCharsets.UTF_8);
String hash = EventPayloadHash.sha256(payload);
@@ -61,7 +63,7 @@ class EventEnvelopeTest {
}
@Test
void 对象字段顺序不同仍产生相同规范摘要() throws Exception {
void differentObjectFieldOrderProducesSameCanonicalDigest() throws Exception {
JsonNode first = objectMapper.readTree("{\"orderId\":\"90001\",\"route\":{\"country\":\"US\",\"city\":\"LA\"}}");
JsonNode second = objectMapper.readTree("{\"route\":{\"city\":\"LA\",\"country\":\"US\"},\"orderId\":\"90001\"}");
@@ -70,7 +72,7 @@ class EventEnvelopeTest {
}
@Test
void 数组顺序仍作为业务语义保留() throws Exception {
void arrayOrderIsPreservedAsBusinessSemantic() throws Exception {
JsonNode first = objectMapper.readTree("{\"steps\":[\"A\",\"B\"]}");
JsonNode second = objectMapper.readTree("{\"steps\":[\"B\",\"A\"]}");