Search in sources :

Example 11 with EmbeddedServerRunner

use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.

the class JunitServerExtension method resolveParameter.

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    final Parameter parameter = parameterContext.getParameter();
    final Class<?> parameterClass = parameter.getType();
    final EmbeddedServerRunner serverAdapter = findEmbeddedServerAdapterInStore(extensionContext);
    // Fast case: a perfect match.
    if (RESOLVERS.containsKey(parameterClass)) {
        return RESOLVERS.get(parameterClass).resolve(parameterContext, serverAdapter);
    }
    for (Class<?> klass : RESOLVERS.keySet()) {
        if (klass.isAssignableFrom(parameterClass)) {
            return RESOLVERS.get(klass).resolve(parameterContext, serverAdapter);
        }
    }
    // method `supportsParameter` has previously returned `true`.
    return null;
}
Also used : EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) Parameter(java.lang.reflect.Parameter)

Example 12 with EmbeddedServerRunner

use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.

the class JunitServerExtensionTest method it_should_start_server_before_each_tests.

@Test
void it_should_start_server_before_each_tests() {
    final JunitServerExtension extension = new JunitServerExtension();
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    extension.beforeEach(context);
    final FakeStore store = context.getSingleStore();
    final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
    assertThat(serverAdapter).isNotNull();
    assertThat(serverAdapter.getServer()).isNotNull();
    assertThat(serverAdapter.getServer().isStarted()).isTrue();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) Test(org.junit.jupiter.api.Test)

Example 13 with EmbeddedServerRunner

use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.

the class JunitServerExtensionTest method it_should_resolve_embedded_server_parameter.

@Test
void it_should_resolve_embedded_server_parameter() throws Exception {
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    final JunitServerExtension extension = initializeExtension(context);
    final FakeStore store = context.getSingleStore();
    final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
    final ParameterContext parameterContext = createParameterContext("method_server", EmbeddedServer.class);
    final Object result = extension.resolveParameter(parameterContext, context);
    assertThat(result).isNotNull().isSameAs(serverAdapter.getServer());
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Test(org.junit.jupiter.api.Test)

Example 14 with EmbeddedServerRunner

use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.

the class JunitServerExtensionTest method it_should_stop_server_after_each_tests.

@Test
void it_should_stop_server_after_each_tests() {
    final JunitServerExtension extension = new JunitServerExtension();
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    extension.beforeEach(context);
    final FakeStore store = context.getSingleStore();
    final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
    extension.afterEach(context);
    assertThat(store.isEmpty()).isTrue();
    assertThat(serverAdapter.getServer().isStarted()).isFalse();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) Test(org.junit.jupiter.api.Test)

Example 15 with EmbeddedServerRunner

use of com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner in project junit-servers by mjeanroy.

the class JunitServerExtensionTest method it_should_detect_if_server_must_be_started_and_stopped_after_all_tests.

@Test
void it_should_detect_if_server_must_be_started_and_stopped_after_all_tests() {
    final JunitServerExtension extension = new JunitServerExtension();
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    extension.beforeAll(context);
    extension.beforeEach(context);
    final FakeStore store = context.getSingleStore();
    final EmbeddedServerRunner serverAdapter = store.get("serverAdapter", EmbeddedServerRunner.class);
    extension.afterEach(context);
    assertThat(store.isEmpty()).isFalse();
    assertThat(serverAdapter.getServer().isStarted()).isTrue();
    extension.afterAll(context);
    assertThat(store.isEmpty()).isTrue();
    assertThat(serverAdapter.getServer().isStarted()).isFalse();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) Test(org.junit.jupiter.api.Test)

Aggregations

EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)23 Test (org.junit.jupiter.api.Test)16 FixtureClass (com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass)10 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 AnnotationsHandlerRunner (com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner)2 AbstractConfiguration (com.github.mjeanroy.junit.servers.servers.AbstractConfiguration)2 ParameterContext (org.junit.jupiter.api.extension.ParameterContext)2 EmbeddedJetty (com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty)1 EmbeddedJettyConfiguration (com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration)1 EmbeddedJettyMockBuilder (com.github.mjeanroy.junit.servers.jetty.tests.EmbeddedJettyMockBuilder)1 EmbeddedTomcat (com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcat)1 EmbeddedTomcatConfiguration (com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration)1 EmbeddedTomcatMockBuilder (com.github.mjeanroy.junit.servers.tomcat.tests.builders.EmbeddedTomcatMockBuilder)1 FakeEmbeddedServerConfiguration (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration)1 Parameter (java.lang.reflect.Parameter)1