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
ConstructorsModifierConstructorDescriptionprotected
Creates a new instance with auto-start enabled.protected
ServerExtension
(boolean autoStart) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
after
(ExtensionContext context) Callsstop()
, without waiting until theServer
is stopped completely.void
before
(ExtensionContext context) Callsstart()
if auto-start is enabled.void
beforeEach
(ExtensionContext context) com.linecorp.armeria.client.BlockingWebClient
Returns theBlockingWebClient
configured byconfigureWebClient(WebClientBuilder)
.com.linecorp.armeria.client.BlockingWebClient
blockingWebClient
(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer.protected abstract void
configure
(com.linecorp.armeria.server.ServerBuilder sb) Configures theServer
with the givenServerBuilder
.protected void
configureWebClient
(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) Configures theWebClient
with the givenWebClientBuilder
.com.linecorp.armeria.client.Endpoint
endpoint
(com.linecorp.armeria.common.SessionProtocol protocol) Returns theEndpoint
of the specifiedSessionProtocol
for theServer
.boolean
hasHttp()
Returnstrue
if theServer
is started and it has an HTTP port open.boolean
hasHttps()
Returnstrue
if theServer
is started and it has an HTTPS port open.com.linecorp.armeria.client.Endpoint
Returns the HTTPEndpoint
for theServer
.int
httpPort()
Returns the HTTP port number of theServer
.com.linecorp.armeria.client.Endpoint
Returns the HTTPSEndpoint
for theServer
.Returns the HTTPInetSocketAddress
of theServer
.int
Returns the HTTPS port number of theServer
.Returns the HTTPSInetSocketAddress
of theServer
.httpsUri()
Returns the HTTPSURI
for theServer
.httpsUri
(com.linecorp.armeria.common.SerializationFormat format) Returns the HTTPSURI
for theServer
.httpUri()
Returns the HTTPURI
for theServer
.httpUri
(com.linecorp.armeria.common.SerializationFormat format) Returns the HTTPURI
for theServer
.int
port
(com.linecorp.armeria.common.SessionProtocol protocol) Returns the port number of theServer
for the specifiedSessionProtocol
.Returns theServiceRequestContextCaptor
that captures all theServiceRequestContext
s in thisServer
.com.linecorp.armeria.client.RestClient
Returns theRestClient
configured byconfigureWebClient(WebClientBuilder)
.com.linecorp.armeria.client.RestClient
restClient
(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer.com.linecorp.armeria.server.Server
server()
Returns the startedServer
.protected boolean
shouldCapture
(com.linecorp.armeria.server.ServiceRequestContext ctx) Determines whether theServiceRequestContext
should be captured or not.socketAddress
(com.linecorp.armeria.common.SessionProtocol protocol) com.linecorp.armeria.server.Server
start()
Starts theServer
configured byconfigure(ServerBuilder)
.stop()
Stops theServer
asynchronously.uri
(com.linecorp.armeria.common.SessionProtocol protocol) uri
(com.linecorp.armeria.common.SessionProtocol protocol, com.linecorp.armeria.common.SerializationFormat format) com.linecorp.armeria.client.WebClient
Returns theWebClient
configured byconfigureWebClient(WebClientBuilder)
.com.linecorp.armeria.client.WebClient
Returns a newly createdWebClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer.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
-true
if theServer
should start automatically.false
if theServer
should start when a user callsstart()
.
-
-
Method Details
-
before
Callsstart()
if auto-start is enabled.- Specified by:
before
in classAbstractAllOrEachExtension
- Throws:
Exception
-
beforeEach
- Specified by:
beforeEach
in interfaceBeforeEachCallback
- Overrides:
beforeEach
in classAbstractAllOrEachExtension
- Throws:
Exception
-
after
Callsstop()
, without waiting until theServer
is stopped completely.- Specified by:
after
in classAbstractAllOrEachExtension
- Throws:
Exception
-
start
public com.linecorp.armeria.server.Server start()Starts theServer
configured byconfigure(ServerBuilder)
. If theServer
has been started up already, the existingServer
is returned. Note that this operation blocks until theServer
finished the start-up.- Returns:
- the started
Server
-
configure
Configures theServer
with the givenServerBuilder
.- Throws:
Exception
-
configureWebClient
protected void configureWebClient(com.linecorp.armeria.client.WebClientBuilder webClientBuilder) throws Exception Configures theWebClient
with the givenWebClientBuilder
. You can get the configuredWebClient
usingwebClient()
.- Throws:
Exception
-
stop
Stops theServer
asynchronously.- Returns:
- the
CompletableFuture
that will complete when theServer
is stopped.
-
server
public com.linecorp.armeria.server.Server server()Returns the startedServer
.- Throws:
IllegalStateException
- if theServer
is not started
-
httpPort
public int httpPort()Returns the HTTP port number of theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port
-
httpsPort
public int httpsPort()Returns the HTTPS port number of theServer
.- Throws:
IllegalStateException
- if theServer
is 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 theServer
for the specifiedSessionProtocol
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open a port of the specified protocol.
-
hasHttp
public boolean hasHttp()Returnstrue
if theServer
is started and it has an HTTP port open. -
hasHttps
public boolean hasHttps()Returnstrue
if theServer
is started and it has an HTTPS port open. -
endpoint
public com.linecorp.armeria.client.Endpoint endpoint(com.linecorp.armeria.common.SessionProtocol protocol) Returns theEndpoint
of the specifiedSessionProtocol
for theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open the port for the specifiedSessionProtocol
.
-
httpEndpoint
public com.linecorp.armeria.client.Endpoint httpEndpoint()Returns the HTTPEndpoint
for theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port.
-
httpsEndpoint
public com.linecorp.armeria.client.Endpoint httpsEndpoint()Returns the HTTPSEndpoint
for theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTPS port.
-
uri
- Returns:
- the absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is 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 theServer
is not started or it did not open the port for the specifiedSessionProtocol
.
-
httpUri
Returns the HTTPURI
for theServer
.- Returns:
- the absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port.
-
httpUri
Returns the HTTPURI
for theServer
.- Returns:
- the absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port.
-
httpsUri
Returns the HTTPSURI
for theServer
.- Returns:
- the absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTPS port.
-
httpsUri
Returns the HTTPSURI
for theServer
.- Returns:
- the absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTPS port.
-
socketAddress
- Throws:
IllegalStateException
- if theServer
is not started or it did not open a port for the specifiedSessionProtocol
.
-
httpSocketAddress
Returns the HTTPInetSocketAddress
of theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port
-
httpsSocketAddress
Returns the HTTPSInetSocketAddress
of theServer
.- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTPS port
-
requestContextCaptor
Returns theServiceRequestContextCaptor
that captures all theServiceRequestContext
s in thisServer
. -
webClient
public com.linecorp.armeria.client.WebClient webClient()Returns theWebClient
configured byconfigureWebClient(WebClientBuilder)
. -
webClient
public com.linecorp.armeria.client.WebClient webClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdWebClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer. -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient()Returns theBlockingWebClient
configured byconfigureWebClient(WebClientBuilder)
. -
blockingWebClient
@UnstableApi public com.linecorp.armeria.client.BlockingWebClient blockingWebClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdBlockingWebClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer. -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient()Returns theRestClient
configured byconfigureWebClient(WebClientBuilder)
. -
restClient
@UnstableApi public com.linecorp.armeria.client.RestClient restClient(Consumer<com.linecorp.armeria.client.WebClientBuilder> webClientCustomizer) Returns a newly createdRestClient
configured byconfigureWebClient(WebClientBuilder)
and then the specified customizer. -
shouldCapture
@UnstableApi protected boolean shouldCapture(com.linecorp.armeria.server.ServiceRequestContext ctx) Determines whether theServiceRequestContext
should be captured or not. This method returnstrue
by default. Override it to capture the contexts selectively.
-