优化
This commit is contained in:
+20
@@ -8,12 +8,32 @@ import org.junit.jupiter.api.Test;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class EventBridgeMetricsTest {
|
||||
|
||||
@Test
|
||||
void productionConstructorIsExplicitForSpringWhenTestClockConstructorAlsoExists() throws Exception {
|
||||
assertThat(EventBridgeMetrics.class.getConstructor(MeterRegistry.class)
|
||||
.isAnnotationPresent(Autowired.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void springContextCreatesMetricsBeanWithTheAnnotatedProductionConstructor() {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.registerBean(MeterRegistry.class, SimpleMeterRegistry::new);
|
||||
context.register(EventBridgeMetrics.class);
|
||||
context.refresh();
|
||||
|
||||
assertThat(context.getBean(EventBridgeMetrics.class)).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void collapsesUnboundedRegionAndEventTypeLabelsToOther() {
|
||||
SimpleMeterRegistry registry = new SimpleMeterRegistry();
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.baiyue.eventbridge.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class HttpSecurityProjectionEventClientTest {
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void onlyMatchingLastlegAcknowledgementCompletesBridgeDelivery() throws Exception {
|
||||
var acknowledged = objectMapper.readTree("""
|
||||
{"code":"200","data":{"eventId":"event-1","result":"APPLIED"}}
|
||||
""");
|
||||
var businessFailure = objectMapper.readTree("""
|
||||
{"code":"A0409","message":"payloadHash 冲突","data":{"eventId":"event-1"}}
|
||||
""");
|
||||
var wrongEvent = objectMapper.readTree("""
|
||||
{"code":"200","data":{"eventId":"event-2","result":"DUPLICATE"}}
|
||||
""");
|
||||
|
||||
assertThatCode(() -> HttpSecurityProjectionEventClient.requireAcknowledgement(
|
||||
200, acknowledged, "event-1")).doesNotThrowAnyException();
|
||||
assertThatThrownBy(() -> HttpSecurityProjectionEventClient.requireAcknowledgement(
|
||||
200, businessFailure, "event-1")).isInstanceOf(IllegalStateException.class);
|
||||
assertThatThrownBy(() -> HttpSecurityProjectionEventClient.requireAcknowledgement(
|
||||
200, wrongEvent, "event-1")).isInstanceOf(IllegalStateException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultConsumerUrlTargetsLastlegSecurityEndpoint() throws Exception {
|
||||
String application = Files.readString(Path.of("src/main/resources/application.yml"));
|
||||
|
||||
assertThat(application).contains(
|
||||
"LASTLEG_SECURITY_EVENT_CONSUMER_URL:http://127.0.0.1:9303/internal/lastleg/security/v1/events")
|
||||
.doesNotContain("/internal/overseas-security/v1/events");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user