Class ServiceRequestContextCaptor

java.lang.Object
com.linecorp.armeria.testing.server.ServiceRequestContextCaptor

@UnstableApi public final class ServiceRequestContextCaptor extends Object
Captures the ServiceRequestContexts.

Example:


 class ServiceRequestContextCaptorTest {
     @RegisterExtension
     static final ServerExtension server = new ServerExtension() {
         @Override
         protected void configure(ServerBuilder sb) throws Exception {
             sb.service("/hello", (ctx, req) -> HttpResponse.of(200));
         }
     };

     @Test
     void test() {
         final WebClient client = WebClient.of(server.httpUri());
         final ServiceRequestContextCaptor captor = server.requestContextCaptor();
         client.get("/hello").aggregate().join();
         assertThat(captor.size()).isEqualTo(1);
     }
 }
 

Example: use ServiceRequestContextCaptor manually


 class ServiceRequestContextCaptorTest {
     static final ServiceRequestContextCaptor captor = new ServiceRequestContextCaptor();
     static final Server server = Server.builder()
                                        .decorator(captor.newDecorator())
                                        .service("/hello", (ctx, req) -> HttpResponse.of(200))
                                        .build();

     @BeforeAll
     static void beforeClass() {
         server.start().join();
     }

     @AfterAll
     static void afterClass() {
         server.stop().join();
     }

     @Test
     void test() {
         final WebClient client = WebClient.builder("http://127.0.0.1:" + server.activeLocalPort()).build();
         client.get("/hello").aggregate().join();
         assertThat(captor.size()).isEqualTo(1);
     }

     @AfterEach
     void tearDown() {
         captor.clear();
     }
 }