Skip to content

Commit a79a35d

Browse files
committed
test: Add IT for decorator reading interceptor-bound ScopedValue
1 parent 84688bf commit a79a35d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/test/java/com/retailsvc/http/DecoratorAndInterceptorIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ void interceptorBindsScopedValueVisibleToHandler() throws Exception {
6666
assertThat(call("/api/v1/data").body()).isEqualTo("acme");
6767
}
6868

69+
@Test
70+
void decoratorReadsInterceptorBoundScopedValue() throws Exception {
71+
RequestHandler ok = req -> Response.text(HTTP_OK, "ok");
72+
server =
73+
newBuilder()
74+
.spec(spec)
75+
.handlers(stubAllHandlers(Map.of("get-data", ok, "post-data", ok)))
76+
.interceptor((request, next) -> ScopedValue.where(TENANT, "acme").call(next::proceed))
77+
.responseDecorator((req, resp) -> resp.withHeader("X-Tenant-Id", TENANT.get()))
78+
.port(0)
79+
.build();
80+
81+
var resp = call("/api/v1/data");
82+
83+
assertThat(resp.statusCode()).isEqualTo(HTTP_OK);
84+
assertThat(resp.headers().firstValue("X-Tenant-Id")).contains("acme");
85+
}
86+
6987
@Test
7088
void interceptorsRunInRegistrationOrder() throws Exception {
7189
List<String> trace = new CopyOnWriteArrayList<>();

0 commit comments

Comments
 (0)