Skip to content

Commit d4935da

Browse files
committed
Added test for state
1 parent fc40d0f commit d4935da

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.google.cloud.sqlcommenter.filter;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.junit.runners.JUnit4;
6+
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
7+
import org.springframework.mock.web.server.MockServerWebExchange;
8+
import org.springframework.web.reactive.result.method.RequestMappingInfo;
9+
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
10+
import org.springframework.web.server.WebFilterChain;
11+
12+
import reactor.core.publisher.Mono;
13+
import reactor.test.StepVerifier;
14+
15+
16+
@RunWith(JUnit4.class)
17+
public class SpringSQLCommenterWebFilterTest {
18+
19+
@Test
20+
public void testPreHandlePlacesStateInContextView() throws NoSuchMethodException {
21+
RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
22+
RequestMappingInfo info = RequestMappingInfo.paths("/test").build();
23+
requestMappingHandlerMapping.registerMapping(info, this, SpringSQLCommenterWebFilterTest.class.getMethod("testPreHandlePlacesStateInContextView"));
24+
25+
SpringSQLCommenterWebFilter springSQLCommenterWebFilter = new SpringSQLCommenterWebFilter(requestMappingHandlerMapping);
26+
27+
WebFilterChain filterChain = filterExchange -> Mono.empty();
28+
29+
MockServerWebExchange exchange = MockServerWebExchange.from(
30+
MockServerHttpRequest
31+
.get("/test"));
32+
33+
StepVerifier.create(springSQLCommenterWebFilter.filter(exchange, filterChain))
34+
.expectAccessibleContext()
35+
.hasKey("state")
36+
.then()
37+
.verifyComplete();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)