Class TestHttpServer

java.lang.Object
cloud.opencode.base.test.http.TestHttpServer
All Implemented Interfaces:
AutoCloseable

public final class TestHttpServer extends Object implements AutoCloseable
Test HTTP Server — Lightweight in-process HTTP server for unit testing. 测试 HTTP 服务器 — 用于单元测试的轻量级进程内 HTTP 服务器。

Uses jdk.httpserver (included in JDK), no external dependencies. Implements AutoCloseable for use in try-with-resources.

使用 jdk.httpserver(JDK 内置),无外部依赖。

Features | 主要功能:

  • In-process HTTP server for testing - 用于测试的进程内HTTP服务器
  • Request recording and route matching - 请求录制和路由匹配

Usage Examples | 使用示例:

try (TestHttpServer server = TestHttpServer.start()) {
    server.when(RequestMatcher.get("/api")).thenRespond(MockResponse.ok());
    String url = server.url("/api");
}

Security | 安全性:

  • Thread-safe: Yes (concurrent data structures) - 线程安全: 是(并发数据结构)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: