HttpClientStreamHttpTransport: add authorization error handler (#861)
HttpClientStreamHttpTransport: add authorization error handler - Closes #240 Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This commit is contained in:
parent
6e4ce1c1a3
commit
abcd19c0c2
1 changed files with 771 additions and 131 deletions
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2026-2026 the original author or authors.
|
||||
*/
|
||||
package io.modelcontextprotocol.client.transport.customizer;
|
||||
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import io.modelcontextprotocol.common.McpTransportContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Daniel Garnier-Moiroux
|
||||
*/
|
||||
class McpHttpClientAuthorizationErrorHandlerTest {
|
||||
|
||||
private final HttpResponse.ResponseInfo responseInfo = mock(HttpResponse.ResponseInfo.class);
|
||||
|
||||
private final McpTransportContext context = McpTransportContext.EMPTY;
|
||||
|
||||
@Test
|
||||
void whenTrueThenRetry() {
|
||||
McpHttpClientAuthorizationErrorHandler handler = McpHttpClientAuthorizationErrorHandler
|
||||
.fromSync((info, ctx) -> true);
|
||||
StepVerifier.create(handler.handle(responseInfo, context)).expectNext(true).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenFalseThenError() {
|
||||
McpHttpClientAuthorizationErrorHandler handler = McpHttpClientAuthorizationErrorHandler
|
||||
.fromSync((info, ctx) -> false);
|
||||
StepVerifier.create(handler.handle(responseInfo, context)).expectNext(false).verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenExceptionThenPropagate() {
|
||||
McpHttpClientAuthorizationErrorHandler handler = McpHttpClientAuthorizationErrorHandler
|
||||
.fromSync((info, ctx) -> {
|
||||
throw new IllegalStateException("sync handler error");
|
||||
});
|
||||
StepVerifier.create(handler.handle(responseInfo, context))
|
||||
.expectErrorMatches(t -> t instanceof IllegalStateException && t.getMessage().equals("sync handler error"))
|
||||
.verify();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue