Class ServerRule
java.lang.Object
org.junit.rules.ExternalResource
com.linecorp.armeria.testing.junit4.server.ServerRule
- All Implemented Interfaces:
TestRule
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new instance with auto-start enabled.protected
ServerRule(boolean autoStart)
Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
after()
protected void
before()
Callsstart()
if auto-start is enabled.protected abstract void
configure(ServerBuilder sb)
Configures theServer
with the givenServerBuilder
.endpoint(SessionProtocol protocol)
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.int
httpPort()
Returns the HTTP port number of theServer
.Returns the HTTPInetSocketAddress
of theServer
.int
Returns the HTTPS port number of theServer
.Returns the HTTPSInetSocketAddress
of theServer
.httpsUri()
httpsUri(SerializationFormat format)
httpUri()
httpUri(SerializationFormat format)
int
port(SessionProtocol protocol)
Returns the port number of theServer
for the specifiedSessionProtocol
.server()
Returns the startedServer
.socketAddress(SessionProtocol protocol)
start()
Starts theServer
configured byconfigure(ServerBuilder)
.stop()
Stops theServer
asynchronously.uri(SessionProtocol protocol)
uri(SessionProtocol protocol, SerializationFormat format)
Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
Method Details
-
before
Callsstart()
if auto-start is enabled.- Overrides:
before
in classExternalResource
- Throws:
Throwable
-
after
protected void after()- Overrides:
after
in classExternalResource
-
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
-
stop
Stops theServer
asynchronously.- Returns:
- the
CompletableFuture
that will complete when theServer
is stopped.
-
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
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
- Throws:
IllegalStateException
- if theServer
is not started or it did not open the port for the specifiedSessionProtocol
.
-
httpEndpoint
- Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port.
-
httpsEndpoint
- 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
- Throws:
IllegalStateException
- if theServer
is not started or it did not open the port for the specifiedSessionProtocol
.
-
httpUri
- 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 absolute
URI
without a path. - Throws:
IllegalStateException
- if theServer
is not started or it did not open an HTTP port.
-
httpsUri
- 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 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
-