Skip to content

Support running test cases in offline environments #636

@D-0771

Description

@D-0771

Description:

Several test cases in mcp-test and other src/test rely on external HTTP endpoints, which cause test failures in offline CI/CD environments.

For example, test case testToolCallSuccess of AbstractStatelessIntegrationTest.java throws an AssertionError if a GET request to raw.githubusercontent.com/modelcontextprotocol/java-sdk/refs/heads/main/README.md has null or empty response.

Goal:

  • Support running maven test lifecycle for offline environments.
  • Specifically, all test cases shall pass when -o option is appended to mvn test command, provided that all required docker images have already been imported (the default container pull policy will allow this to work offline).

Proposed changes:

Instead of sending GET request using an HTTP client, use a mock client that reads README.md from local file.

HttpClient mockClient = mock(HttpClient.class);
HttpResponse<String> mockResponse = mock(HttpResponse.class);

// Relative path of README.md depending on project directory
when(mockResponse.body()).thenReturn(Files.readString(Path.of("../README.md").toAbsolutePath()));
when(mockResponse.statusCode()).thenReturn(200);
when(mockClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(mockResponse);

Environment:

  • MCP Java SDK: current main branch
  • JDK: 21
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions