M5 AP-003 Unnötige Scope-Änderungen entfernt und Adapter-Tests auf
echten Outbound-Request geschärft
This commit is contained in:
+20
@@ -102,6 +102,9 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
|
||||
private final String apiKey;
|
||||
private final int apiTimeoutSeconds;
|
||||
|
||||
// Test-only field to capture the last built JSON body for assertion
|
||||
private volatile String lastBuiltJsonBody;
|
||||
|
||||
/**
|
||||
* Creates an adapter with configuration from startup configuration.
|
||||
* <p>
|
||||
@@ -236,6 +239,8 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
|
||||
URI endpoint = buildEndpointUri();
|
||||
|
||||
String requestBody = buildJsonRequestBody(request);
|
||||
// Capture for test inspection (test-only field)
|
||||
this.lastBuiltJsonBody = requestBody;
|
||||
|
||||
return HttpRequest.newBuilder(endpoint)
|
||||
.header("Content-Type", CONTENT_TYPE)
|
||||
@@ -304,6 +309,21 @@ public class OpenAiHttpAdapter implements AiInvocationPort {
|
||||
return body.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Package-private accessor for the last constructed JSON body.
|
||||
* <p>
|
||||
* <strong>For testing only:</strong> Allows tests to verify the actual
|
||||
* JSON body sent in HTTP requests without exposing the BodyPublisher internals.
|
||||
* This method is used by unit tests to assert that the correct model, text,
|
||||
* and other fields are present in the outbound request.
|
||||
*
|
||||
* @return the last JSON body string constructed by {@link #buildRequest(AiRequestRepresentation)},
|
||||
* or null if no request has been built yet
|
||||
*/
|
||||
String getLastBuiltJsonBodyForTesting() {
|
||||
return lastBuiltJsonBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the HTTP request and returns the response.
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user