|
| 1 | +/* |
| 2 | + * Copyright 2025-2026 the original author or authors. |
| 3 | + */ |
| 4 | + |
| 5 | +package com.agentclientprotocol.sdk.spring.boot.autoconfigure.agent; |
| 6 | + |
| 7 | +import java.net.URI; |
| 8 | + |
| 9 | +import com.agentclientprotocol.sdk.spring.boot.autoconfigure.agent.AcpAgentHttpAutoConfigurationTests.EchoAgentConfiguration; |
| 10 | +import com.agentclientprotocol.sdk.test.http.HttpProbes; |
| 11 | +import io.micrometer.observation.tck.TestObservationRegistry; |
| 12 | +import io.micrometer.observation.tck.TestObservationRegistryAssert; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; |
| 16 | +import org.springframework.boot.SpringBootConfiguration; |
| 17 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 18 | +import org.springframework.boot.test.context.SpringBootTest; |
| 19 | +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; |
| 20 | +import org.springframework.boot.test.web.server.LocalServerPort; |
| 21 | +import org.springframework.context.annotation.Bean; |
| 22 | +import org.springframework.context.annotation.Import; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * The application's own HTTP server observations cover {@code /acp}: the endpoint is mounted on |
| 28 | + * the application's server and filter chain, so Spring's {@code ServerHttpObservationFilter} |
| 29 | + * records an {@code http.server.requests} observation for an ACP request as for any other. |
| 30 | + */ |
| 31 | +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.acp.agent.transport.type=http") |
| 32 | +class AcpAgentHttpObservationTests { |
| 33 | + |
| 34 | + @LocalServerPort |
| 35 | + private int port; |
| 36 | + |
| 37 | + @Autowired |
| 38 | + private TestObservationRegistry observations; |
| 39 | + |
| 40 | + @Test |
| 41 | + void anAcpRequestIsObserved() throws Exception { |
| 42 | + URI endpoint = URI.create("http://127.0.0.1:" + this.port + "/acp"); |
| 43 | + assertThat(HttpProbes.initialize(endpoint, null).statusCode()).isEqualTo(200); |
| 44 | + TestObservationRegistryAssert.assertThat(this.observations) |
| 45 | + .hasObservationWithNameEqualTo("http.server.requests") |
| 46 | + .that() |
| 47 | + .hasLowCardinalityKeyValue("method", "POST") |
| 48 | + .hasLowCardinalityKeyValue("status", "200") |
| 49 | + .hasBeenStopped(); |
| 50 | + } |
| 51 | + |
| 52 | + @SpringBootConfiguration |
| 53 | + @EnableAutoConfiguration |
| 54 | + @Import(EchoAgentConfiguration.class) |
| 55 | + static class ObservedApplication { |
| 56 | + |
| 57 | + @Bean |
| 58 | + TestObservationRegistry observationRegistry() { |
| 59 | + return TestObservationRegistry.create(); |
| 60 | + } |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments