Class AbstractEmbeddedServer<S,T extends AbstractConfiguration>
java.lang.Object
com.github.mjeanroy.junit.servers.servers.AbstractEmbeddedServer<S,T>
- All Implemented Interfaces:
EmbeddedServer<T>
public abstract class AbstractEmbeddedServer<S,T extends AbstractConfiguration>
extends Object
implements EmbeddedServer<T>
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractEmbeddedServer
(T configuration) Build default embedded server. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract int
Get port once server is started.protected abstract void
doStart()
Start embedded server.protected abstract void
doStop()
Stop embedded server.Return server configuration.abstract S
Get internal server implementation.getHost()
Get the host, should be"localhost"
, unless specific configuration.getPath()
Get server context path.int
getPort()
Get port used by embedded server.Get the protocol scheme ("http"
,"https"
).getUrl()
Get URL 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.mjeanroy.junit.servers.servers.EmbeddedServer
getServletContext
-
Field Details
-
configuration
Server configuration.
-
-
Constructor Details
-
AbstractEmbeddedServer
Build default embedded server.- Parameters:
configuration
- Server configuration.
-
-
Method Details
-
start
public void start()Description copied from interface:EmbeddedServer
Start embedded server. If server is already started, this method should do nothing.- Specified by:
start
in interfaceEmbeddedServer<S>
-
stop
public void stop()Description copied from interface:EmbeddedServer
Stop embedded server. If server is already stopped, this method should do nothing.- Specified by:
stop
in interfaceEmbeddedServer<S>
-
isStarted
public boolean isStarted()Description copied from interface:EmbeddedServer
Check if embedded server is started.- Specified by:
isStarted
in interfaceEmbeddedServer<S>
- Returns:
true
if embedded server is started,false
otherwise.
-
restart
public void restart()Description copied from interface:EmbeddedServer
Restart embedded server.- Specified by:
restart
in interfaceEmbeddedServer<S>
-
getPort
public int getPort()Description copied from interface:EmbeddedServer
Get port used by embedded server.Note that:
- If the server is not started, the returned port should be the one set in the configuration.
- Otherwise, the "real" port should be returned (the port used by the embedded server)
- Specified by:
getPort
in interfaceEmbeddedServer<S>
- Returns:
- Port.
-
getPath
Description copied from interface:EmbeddedServer
Get server context path.- Specified by:
getPath
in interfaceEmbeddedServer<S>
- Returns:
- Server context path.
-
getScheme
Description copied from interface:EmbeddedServer
Get the protocol scheme ("http"
,"https"
).- Specified by:
getScheme
in interfaceEmbeddedServer<S>
- Returns:
- Protocol scheme.
-
getHost
Description copied from interface:EmbeddedServer
Get the host, should be"localhost"
, unless specific configuration.- Specified by:
getHost
in interfaceEmbeddedServer<S>
- Returns:
- The server hostname.
-
getUrl
Description copied from interface:EmbeddedServer
Get URL to query embedded server.- Specified by:
getUrl
in interfaceEmbeddedServer<S>
- Returns:
- URL.
-
getConfiguration
Description copied from interface:EmbeddedServer
Return server configuration.- Specified by:
getConfiguration
in interfaceEmbeddedServer<S>
- Returns:
- Configuration.
-
getDelegate
Get internal server implementation. Note that this method should not be used to start or stop internal server, use dedicated method instead. This method can be used to do some custom configuration on original implementation.- Returns:
- Original server implementation.
-
doStart
protected abstract void doStart()Start embedded server. Must block until server is fully started. -
doStop
protected abstract void doStop()Stop embedded server. Must block until server is fully stopped. -
doGetPort
protected abstract int doGetPort()Get port once server is started.- Returns:
- The port.
-