Search in sources :

Example 6 with FixtureClass

use of com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass 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 7 with FixtureClass

use of com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass 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 8 with FixtureClass

use of com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass 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 9 with FixtureClass

use of com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass 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)

Example 10 with FixtureClass

use of com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass in project junit-servers by mjeanroy.

the class JunitServerExtensionTest method it_should_initialize_extension_with_given_configuration_and_start_given_server_before_all_tests.

@Test
void it_should_initialize_extension_with_given_configuration_and_start_given_server_before_all_tests() {
    final AbstractConfiguration configuration = new FakeEmbeddedServerConfiguration();
    final JunitServerExtension extension = new JunitServerExtension(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().isInstanceOf(FakeEmbeddedServer.class);
    assertThat(serverAdapter.getServer().getConfiguration()).isSameAs(configuration);
    assertThat(serverAdapter.getServer().isStarted()).isTrue();
}
Also used : AbstractConfiguration(com.github.mjeanroy.junit.servers.servers.AbstractConfiguration) FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

FixtureClass (com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass)18 Test (org.junit.jupiter.api.Test)17 EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)10 ParameterContext (org.junit.jupiter.api.extension.ParameterContext)6 AbstractConfiguration (com.github.mjeanroy.junit.servers.servers.AbstractConfiguration)4 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)4 AbstractConfigurationMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.AbstractConfigurationMockBuilder)3 TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)1 HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)1 NingAsyncHttpClient (com.github.mjeanroy.junit.servers.client.impl.ning.NingAsyncHttpClient)1 AnnotationsHandlerRunner (com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner)1 FakeEmbeddedServerConfiguration (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1