Class EmbeddedServerRunner
java.lang.Object
com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner
- All Implemented Interfaces:
TestRunner
An engine that will handle the embedded server lifecycle:
- Start embedded server before running any tests.
- Stop embedded server after all tests are run.
-
Constructor Summary
ConstructorDescriptionCreate rule with default embedded server.EmbeddedServerRunner
(AbstractConfiguration configuration) Create rule with embedded server configuration.EmbeddedServerRunner
(EmbeddedServer<?> server) Create rule with an embedded server. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll()
Run the AFTER step of the lifecycle test.void
Method called after running unit test.void
Run the BEFORE step of the lifecycle test.void
beforeEach
(Object target) Method called before running unit test.Returns HTTP client that can be used againstserver
.getClient
(HttpClientConfiguration configuration) Returns HTTP client that can be used againstserver
.getClient
(HttpClientStrategy strategy) Returns HTTP client that can be used againstserver
.getClient
(HttpClientStrategy strategy, HttpClientConfiguration configuration) Returns HTTP client that can be used againstserver
.getHost()
Get embedded server scheme (should be"localhost"
).getPath()
Get path defined on embedded server.int
getPort()
Get port used by embedded server.Get embedded server scheme (a.k.a"http"
or"https"
).Get embedded server.getUrl()
Get url used to query embedded server.boolean
Check if embedded server is started.void
restart()
Restart embedded server.void
start()
Start embedded server.void
stop()
Stop embedded server.toString()
-
Constructor Details
-
EmbeddedServerRunner
public EmbeddedServerRunner()Create rule with default embedded server.Embedded server implementation is chosen using classpath detection: jetty or tomcat will be instantiate if implementation is available on classpath (it means if sub-module is imported, it should be enough to instantiate embedded server).
The server will automatically use the default configuration, to specify a custom configuration, use
EmbeddedServerRunner(AbstractConfiguration)
constructor. -
EmbeddedServerRunner
Create rule with embedded server configuration.Embedded server implementation is chosen using classpath detection: jetty or tomcat will be instantiate if implementation is available on classpath (it means if sub-module is imported, it should be enough to instantiate embedded server !).
- Parameters:
configuration
- Server configuration.
-
EmbeddedServerRunner
Create rule with an embedded server.- Parameters:
server
- Embedded server, not null.- Throws:
NullPointerException
- Ifserver
isnull
.
-
-
Method Details
-
beforeAll
public void beforeAll()Run the BEFORE step of the lifecycle test.- Specified by:
beforeAll
in interfaceTestRunner
-
afterAll
public void afterAll()Run the AFTER step of the lifecycle test.- Specified by:
afterAll
in interfaceTestRunner
-
start
public void start()Start embedded server.- See Also:
-
stop
public void stop()Stop embedded server.- See Also:
-
restart
public void restart()Restart embedded server.- See Also:
-
isStarted
public boolean isStarted()Check if embedded server is started.- Returns:
true
if embedded server is started,false
otherwise.- See Also:
-
getScheme
Get embedded server scheme (a.k.a"http"
or"https"
).- Returns:
- Scheme.
- See Also:
-
getHost
Get embedded server scheme (should be"localhost"
).- Returns:
- Host.
- See Also:
-
getPort
public int getPort()Get port used by embedded server.Note that:
- If the server is not started, the returned port is the one set in the configuration.
- Otherwise, the "real" port is returned (the port used by the embedded server)
- Returns:
- The port.
- See Also:
-
getPath
Get path defined on embedded server.- Returns:
- Path.
- See Also:
-
getUrl
Get url used to query embedded server.- Returns:
- URL.
- See Also:
-
getServer
Get embedded server.- Returns:
- Server.
-
getClient
Returns HTTP client that can be used againstserver
.- Returns:
- The HTTP client.
- Throws:
UnsupportedOperationException
- If the client cannot be returned because of missing implementation.
-
getClient
Returns HTTP client that can be used againstserver
.- Parameters:
configuration
- The client configuration.- Returns:
- The HTTP client.
- Throws:
UnsupportedOperationException
- If the client cannot be returned because of missing implementation.
-
getClient
Returns HTTP client that can be used againstserver
.- Parameters:
strategy
- The strategy to use.- Returns:
- The HTTP client.
- Throws:
UnsupportedOperationException
- If the client cannot be returned because of missing implementation.
-
getClient
Returns HTTP client that can be used againstserver
.- Parameters:
strategy
- The strategy to use.configuration
- The client configuration.- Returns:
- The HTTP client.
- Throws:
UnsupportedOperationException
- If the client cannot be returned because of missing implementation.
-
toString
-
beforeEach
Description copied from interface:TestRunner
Method called before running unit test.- Specified by:
beforeEach
in interfaceTestRunner
- Parameters:
target
- The test class instance.
-
afterEach
Description copied from interface:TestRunner
Method called after running unit test.- Specified by:
afterEach
in interfaceTestRunner
- Parameters:
target
- The test class instance.
-