use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.
the class TomcatServerExtensionTest method it_should_start_server_with_default_configuration_before_all_tests.
@Test
void it_should_start_server_with_default_configuration_before_all_tests() {
final TomcatServerExtension extension = new TomcatServerExtension();
final FixtureClass testInstance = new FixtureClass();
final FakeExtensionContext context = new FakeExtensionContext(testInstance);
extension.beforeAll(context);
final FakeStore store = context.getSingleStore();
final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
assertThat(serverAdapter).isNotNull();
assertThat(serverAdapter.getServer()).isNotNull().isExactlyInstanceOf(EmbeddedTomcat.class);
assertThat(serverAdapter.getServer().isStarted()).isTrue();
}
use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.
the class TomcatServerExtensionTest method it_should_start_tomcat_server_using_given_configuration_before_all_tests.
@Test
void it_should_start_tomcat_server_using_given_configuration_before_all_tests() {
final EmbeddedTomcatConfiguration configuration = EmbeddedTomcatConfiguration.defaultConfiguration();
final TomcatServerExtension extension = new TomcatServerExtension(configuration);
final FixtureClass testInstance = new FixtureClass();
final FakeExtensionContext context = new FakeExtensionContext(testInstance);
extension.beforeAll(context);
final FakeStore store = context.getSingleStore();
final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
assertThat(serverAdapter).isNotNull();
assertThat(serverAdapter.getServer()).isNotNull().isExactlyInstanceOf(EmbeddedTomcat.class);
assertThat(serverAdapter.getServer().getConfiguration()).isSameAs(configuration);
assertThat(serverAdapter.getServer().isStarted()).isTrue();
}
use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.
the class JunitServerExtension method registerEmbeddedServer.
/**
* Start and register the embedded server.
*
* The embedded server may be used in two modes:
*
* <ul>
* <li>Started before all tests, and stopped after all tests, this is the static mode (the extension has been used as a static extension).</li>
* <li>Started before each tests, and stopped after eacg tests, this is the non static mode (the extension has not been used as a static extension).</li>
* </ul>
*
* @param context The test context.
* @param staticMode {@code true} if the extension has been registered as a static extension, {@code false} otherwise.
* @return The registered adapter.
*/
private EmbeddedServerRunner registerEmbeddedServer(ExtensionContext context, boolean staticMode) {
log.debug("Register embedded server to junit extension context");
Class<?> testClass = context.getRequiredTestClass();
EmbeddedServer<?> server = this.server == null ? instantiateServer(testClass, configuration) : this.server;
EmbeddedServerRunner serverAdapter = new EmbeddedServerRunner(server);
serverAdapter.beforeAll();
putEmbeddedServerAdapterInStore(context, serverAdapter, staticMode);
return serverAdapter;
}
use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.
the class JunitServerExtension method beforeEach.
@Override
public void beforeEach(ExtensionContext context) {
EmbeddedServerRunner serverAdapter = findEmbeddedServerAdapterInStore(context);
// The extension was not declared as a static extension.
if (serverAdapter == null) {
serverAdapter = registerEmbeddedServer(context, false);
}
EmbeddedServer<?> server = serverAdapter.getServer();
AbstractConfiguration configuration = server.getConfiguration();
AnnotationsHandlerRunner annotationsAdapter = new AnnotationsHandlerRunner(server, configuration);
annotationsAdapter.beforeEach(context.getRequiredTestInstance());
putAnnotationsHandlerAdapterInStore(context, annotationsAdapter);
}
use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.
the class JunitServerExtension method unregisterEmbeddedServer.
/**
* Stop and remove from the store the started embedded server.
*
* @param context The test context.
* @param staticMode {@code true} if the extension has been registered as a static extension, {@code false} otherwise.
* @see #registerEmbeddedServer(ExtensionContext, boolean)
*/
private void unregisterEmbeddedServer(ExtensionContext context, boolean staticMode) {
log.debug("Attempt to unregister embedded server to junit extension context");
boolean registeredAsStatic = findInStore(context, SERVER_RUNNER_STATIC_MODE);
if (registeredAsStatic == staticMode) {
try {
EmbeddedServerRunner serverAdapter = findEmbeddedServerAdapterInStore(context);
serverAdapter.afterAll();
} finally {
removeEmbeddedServerAdapterFromStore(context);
}
}
}
Aggregations