Class ServerExtension
java.lang.Object
com.linecorp.armeria.testing.junit5.common.AbstractAllOrEachExtension
com.linecorp.armeria.testing.junit5.server.ServerExtension
- All Implemented Interfaces:
AfterAllCallback,AfterEachCallback,BeforeAllCallback,BeforeEachCallback,Extension
- Direct Known Subclasses:
MockWebServerExtension
An
Extension that allows easy set-up and tear-down of a Server.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance with auto-start enabled.protectedServerExtension(boolean autoStart) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidafter(ExtensionContext context) Callsstop(), without waiting until theServeris stopped completely.voidbefore(ExtensionContext context) Callsstart()if auto-start is enabled.voidbeforeEach(ExtensionContext context) com.linecorp.armeria.client.BlockingWebClientReturns theBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.BlockingWebClientblockingWebClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.protected abstract voidconfigure(com.linecorp.armeria.server.ServerBuilder sb) Configures theServerwith the givenServerBuilder.protected voidconfigureWebClient(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) Configures theWebClientwith the givenWebClientBuilder.protected voidconfigureWebSocketClient(com.linecorp.armeria.client.websocket.WebSocketClientBuilder webSocketClientBuilder) Configures theWebSocketClientwith the givenWebSocketClientBuilder.com.linecorp.armeria.client.Endpointendpoint(com.linecorp.armeria.common.SessionProtocol protocol) Returns theEndpointof the specifiedSessionProtocolfor theServer.booleanhasHttp()Returnstrueif theServeris started and it has an HTTP port open.booleanhasHttps()Returnstrueif theServeris started and it has an HTTPS port open.com.linecorp.armeria.client.EndpointReturns the HTTPEndpointfor theServer.inthttpPort()Returns the HTTP port number of theServer.com.linecorp.armeria.client.EndpointReturns the HTTPSEndpointfor theServer.Returns the HTTPInetSocketAddressof theServer.intReturns the HTTPS port number of theServer.Returns the HTTPSInetSocketAddressof theServer.httpsUri()Returns the HTTPSURIfor theServer.httpsUri(com.linecorp.armeria.common.SerializationFormat format) Returns the HTTPSURIfor theServer.httpUri()Returns the HTTPURIfor theServer.httpUri(com.linecorp.armeria.common.SerializationFormat format) Returns the HTTPURIfor theServer.intport(com.linecorp.armeria.common.SessionProtocol protocol) Returns the port number of theServerfor the specifiedSessionProtocol.Returns theServiceRequestContextCaptorthat captures all theServiceRequestContexts in thisServer.com.linecorp.armeria.client.RestClientReturns theRestClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.RestClientrestClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.com.linecorp.armeria.server.Serverserver()Returns the startedServer.protected booleanshouldCapture(com.linecorp.armeria.server.ServiceRequestContext ctx) Determines whether theServiceRequestContextshould be captured or not.socketAddress(com.linecorp.armeria.common.SessionProtocol protocol) com.linecorp.armeria.server.Serverstart()Starts theServerconfigured byconfigure(ServerBuilder).stop()Stops theServerasynchronously.uri(com.linecorp.armeria.common.SessionProtocol protocol) uri(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format) com.linecorp.armeria.client.WebClientReturns theWebClientconfigured byconfigureWebClient(WebClientBuilder).com.linecorp.armeria.client.WebClientReturns a newly createdWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer.com.linecorp.armeria.client.websocket.WebSocketClientReturns theWebSocketClientconfigured byconfigureWebSocketClient(WebSocketClientBuilder).Methods inherited from class com.linecorp.armeria.testing.junit5.common.AbstractAllOrEachExtension
afterAll, afterEach, beforeAll, runForEachTest
-
Constructor Details
-
ServerExtension
protected ServerExtension()Creates a new instance with auto-start enabled. -
ServerExtension
protected ServerExtension(boolean autoStart) Creates a new instance.- Parameters:
autoStart-trueif theServershould start automatically.falseif theServershould start when a user callsstart().
-
-
Method Details
-
before
Callsstart()if auto-start is enabled.- Specified by:
beforein classAbstractAllOrEachExtension- Throws:
Exception
-
beforeEach
- Specified by:
beforeEachin interfaceBeforeEachCallback- Overrides:
beforeEachin classAbstractAllOrEachExtension- Throws:
Exception
-
after
Callsstop(), without waiting until theServeris stopped completely.- Specified by:
afterin classAbstractAllOrEachExtension- Throws:
Exception
-
start
public com.linecorp.armeria.server.Server start()Starts theServerconfigured byconfigure(ServerBuilder). If theServerhas been started up already, the existingServeris returned. Note that this operation blocks until theServerfinished the start-up.- Returns:
- the started
Server
-
configure
Configures theServerwith the givenServerBuilder.- Throws:
Exception
-
configureWebClient
protected void configureWebClient(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) throws Exception Configures theWebClientwith the givenWebClientBuilder. You can get the configuredWebClientusingwebClient().- Throws:
Exception
-
configureWebSocketClient
protected void configureWebSocketClient(com.linecorp.armeria.client.websocket.WebSocketClientBuilder webSocketClientBuilder) throws Exception Configures theWebSocketClientwith the givenWebSocketClientBuilder. You can get the configuredWebSocketClientusingwebSocketClient().- Throws:
Exception
-
stop
Stops theServerasynchronously.- Returns:
- the
CompletableFuturethat will complete when theServeris stopped.
-
server
public com.linecorp.armeria.server.Server server()Returns the startedServer.- Throws:
IllegalStateException- if theServeris not started
-
httpPort
public int httpPort()Returns the HTTP port number of theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port
-
httpsPort
public int httpsPort()Returns the HTTPS port number of theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port
-
port
public int port(com.linecorp.armeria.common.SessionProtocol protocol) Returns the port number of theServerfor the specifiedSessionProtocol.- Throws:
IllegalStateException- if theServeris not started or it did not open a port of the specified protocol.
-
hasHttp
public boolean hasHttp()Returnstrueif theServeris started and it has an HTTP port open. -
hasHttps
public boolean hasHttps()Returnstrueif theServeris started and it has an HTTPS port open. -
endpoint
public com.linecorp.armeria.client.Endpoint endpoint(com.linecorp.armeria.common.SessionProtocol protocol) Returns theEndpointof the specifiedSessionProtocolfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
httpEndpoint
public com.linecorp.armeria.client.Endpoint httpEndpoint()Returns the HTTPEndpointfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpsEndpoint
public com.linecorp.armeria.client.Endpoint httpsEndpoint()Returns the HTTPSEndpointfor theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
uri
- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
uri
public URI uri(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format) - Throws:
IllegalStateException- if theServeris not started or it did not open the port for the specifiedSessionProtocol.
-
httpUri
Returns the HTTPURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpUri
Returns the HTTPURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port.
-
httpsUri
Returns the HTTPSURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
httpsUri
Returns the HTTPSURIfor theServer.- Returns:
- the absolute
URIwithout a path. - Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port.
-
socketAddress
- Throws:
IllegalStateException- if theServeris not started or it did not open a port for the specifiedSessionProtocol.
-
httpSocketAddress
Returns the HTTPInetSocketAddressof theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTP port
-
httpsSocketAddress
Returns the HTTPSInetSocketAddressof theServer.- Throws:
IllegalStateException- if theServeris not started or it did not open an HTTPS port
-
requestContextCaptor
Returns theServiceRequestContextCaptorthat captures all theServiceRequestContexts in thisServer. -
webClient
public com.linecorp.armeria.client.WebClient webClient()Returns theWebClientconfigured byconfigureWebClient(WebClientBuilder). -
webClient
public com.linecorp.armeria.client.WebClient webClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer. -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient()Returns theBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder). -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer. -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient()Returns theRestClientconfigured byconfigureWebClient(WebClientBuilder). -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClientconfigured byconfigureWebClient(WebClientBuilder)and then the specified customizer. -
webSocketClient
@UnstableApi public com.linecorp.armeria.client.websocket.WebSocketClient webSocketClient()Returns theWebSocketClientconfigured byconfigureWebSocketClient(WebSocketClientBuilder). -
shouldCapture
@UnstableApi protected boolean shouldCapture(com.linecorp.armeria.server.ServiceRequestContext ctx) Determines whether theServiceRequestContextshould be captured or not. This method returnstrueby default. Override it to capture the contexts selectively.
-