Search in sources :

Example 1 with HttpHandler

use of cn.taketoday.http.server.reactive.HttpHandler in project today-infrastructure by TAKETODAY.

the class UndertowReactiveWebServerFactoryTests method builderCustomizersShouldBeInvoked.

@Test
void builderCustomizersShouldBeInvoked() {
    UndertowReactiveWebServerFactory factory = getFactory();
    HttpHandler handler = mock(HttpHandler.class);
    UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4];
    Arrays.setAll(customizers, (i) -> mock(UndertowBuilderCustomizer.class));
    factory.setBuilderCustomizers(Arrays.asList(customizers[0], customizers[1]));
    factory.addBuilderCustomizers(customizers[2], customizers[3]);
    this.webServer = factory.getWebServer(handler);
    InOrder ordered = inOrder((Object[]) customizers);
    for (UndertowBuilderCustomizer customizer : customizers) {
        ordered.verify(customizer).customize(any(Undertow.Builder.class));
    }
}
Also used : HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 2 with HttpHandler

use of cn.taketoday.http.server.reactive.HttpHandler in project today-infrastructure by TAKETODAY.

the class AnnotationConfigReactiveWebServerApplicationContextTests method verifyContext.

private void verifyContext() {
    MockReactiveWebServerFactory factory = this.context.getBean(MockReactiveWebServerFactory.class);
    HttpHandler expectedHandler = this.context.getBean(HttpHandler.class);
    HttpHandler actualHandler = factory.getWebServer().getHttpHandler();
    if (actualHandler instanceof DelayedInitializationHttpHandler) {
        actualHandler = ((DelayedInitializationHttpHandler) actualHandler).getHandler();
    }
    assertThat(actualHandler).isEqualTo(expectedHandler);
}
Also used : HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) DelayedInitializationHttpHandler(cn.taketoday.framework.web.reactive.context.WebServerManager.DelayedInitializationHttpHandler) MockReactiveWebServerFactory(cn.taketoday.framework.web.reactive.server.MockReactiveWebServerFactory) DelayedInitializationHttpHandler(cn.taketoday.framework.web.reactive.context.WebServerManager.DelayedInitializationHttpHandler)

Example 3 with HttpHandler

use of cn.taketoday.http.server.reactive.HttpHandler in project today-infrastructure by TAKETODAY.

the class TomcatReactiveWebServerFactoryTests method tomcatConnectorCustomizersShouldBeInvoked.

@Test
void tomcatConnectorCustomizersShouldBeInvoked() {
    TomcatReactiveWebServerFactory factory = getFactory();
    HttpHandler handler = mock(HttpHandler.class);
    TomcatConnectorCustomizer[] customizers = new TomcatConnectorCustomizer[4];
    Arrays.setAll(customizers, (i) -> mock(TomcatConnectorCustomizer.class));
    factory.setTomcatConnectorCustomizers(Arrays.asList(customizers[0], customizers[1]));
    factory.addConnectorCustomizers(customizers[2], customizers[3]);
    this.webServer = factory.getWebServer(handler);
    InOrder ordered = inOrder((Object[]) customizers);
    for (TomcatConnectorCustomizer customizer : customizers) {
        then(customizer).should(ordered).customize(any(Connector.class));
    }
}
Also used : HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) Connector(org.apache.catalina.connector.Connector) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 4 with HttpHandler

use of cn.taketoday.http.server.reactive.HttpHandler in project today-framework by TAKETODAY.

the class UndertowReactiveWebServerFactoryTests method builderCustomizersShouldBeInvoked.

@Test
void builderCustomizersShouldBeInvoked() {
    UndertowReactiveWebServerFactory factory = getFactory();
    HttpHandler handler = mock(HttpHandler.class);
    UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4];
    Arrays.setAll(customizers, (i) -> mock(UndertowBuilderCustomizer.class));
    factory.setBuilderCustomizers(Arrays.asList(customizers[0], customizers[1]));
    factory.addBuilderCustomizers(customizers[2], customizers[3]);
    this.webServer = factory.getWebServer(handler);
    InOrder ordered = inOrder((Object[]) customizers);
    for (UndertowBuilderCustomizer customizer : customizers) {
        ordered.verify(customizer).customize(any(Undertow.Builder.class));
    }
}
Also used : HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Example 5 with HttpHandler

use of cn.taketoday.http.server.reactive.HttpHandler in project today-framework by TAKETODAY.

the class TomcatReactiveWebServerFactoryTests method tomcatProtocolHandlerCustomizersShouldBeInvoked.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void tomcatProtocolHandlerCustomizersShouldBeInvoked() {
    TomcatReactiveWebServerFactory factory = getFactory();
    HttpHandler handler = mock(HttpHandler.class);
    TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol<?>>[] customizers = new TomcatProtocolHandlerCustomizer[4];
    Arrays.setAll(customizers, (i) -> mock(TomcatProtocolHandlerCustomizer.class));
    factory.setTomcatProtocolHandlerCustomizers(Arrays.asList(customizers[0], customizers[1]));
    factory.addProtocolHandlerCustomizers(customizers[2], customizers[3]);
    this.webServer = factory.getWebServer(handler);
    InOrder ordered = inOrder((Object[]) customizers);
    for (TomcatProtocolHandlerCustomizer customizer : customizers) {
        then(customizer).should(ordered).customize(any(ProtocolHandler.class));
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) InOrder(org.mockito.InOrder) Test(org.junit.jupiter.api.Test)

Aggregations

HttpHandler (cn.taketoday.http.server.reactive.HttpHandler)10 Test (org.junit.jupiter.api.Test)8 InOrder (org.mockito.InOrder)8 DelayedInitializationHttpHandler (cn.taketoday.framework.web.reactive.context.WebServerManager.DelayedInitializationHttpHandler)2 MockReactiveWebServerFactory (cn.taketoday.framework.web.reactive.server.MockReactiveWebServerFactory)2 Connector (org.apache.catalina.connector.Connector)2 ProtocolHandler (org.apache.coyote.ProtocolHandler)2 Server (org.eclipse.jetty.server.Server)2