Search in sources :

Example 1 with FakeEmbeddedServerConfiguration

use of com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration in project junit-servers by mjeanroy.

the class ServersTest method it_should_instantiate_server_with_configuration.

@Test
void it_should_instantiate_server_with_configuration() {
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().build();
    final EmbeddedServer<?> server = Servers.instantiate(configuration);
    assertThat(server).isNotNull().isExactlyInstanceOf(FakeEmbeddedServer.class);
    assertThat(server.getConfiguration()).isNotNull().isSameAs(configuration);
}
Also used : FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with FakeEmbeddedServerConfiguration

use of com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration in project junit-servers by mjeanroy.

the class AbstractEmbeddedServerTest method it_should_execute_hook.

@Test
void it_should_execute_hook() {
    final Hook hook = mock(Hook.class);
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().withHook(hook).build();
    server = new FakeEmbeddedServer(configuration);
    server.start();
    verify(hook).pre(server);
    verify(hook).onStarted(server, server.getServletContext());
    verify(hook, never()).post(server);
    server.stop();
    verify(hook).post(server);
    verify(hook, times(1)).pre(server);
    verify(hook, times(1)).pre(server);
}
Also used : FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) FakeEmbeddedServer(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer) Test(org.junit.jupiter.api.Test)

Example 3 with FakeEmbeddedServerConfiguration

use of com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration in project junit-servers by mjeanroy.

the class AbstractEmbeddedServerTest method it_should_get_url_and_do_not_encode_custom_path.

@Test
void it_should_get_url_and_do_not_encode_custom_path() {
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().withPath("/foo bar").build();
    final FakeEmbeddedServer server = new FakeEmbeddedServer(configuration);
    final String url = server.getUrl();
    assertThat(url).isEqualTo(localUrl(server.getPort(), "/foo bar"));
}
Also used : FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) FakeEmbeddedServer(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer) Test(org.junit.jupiter.api.Test)

Example 4 with FakeEmbeddedServerConfiguration

use of com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration in project junit-servers by mjeanroy.

the class EmbeddedServerRunnerTest method it_should_instantiate_server_from_service_loader_with_custom_configuration.

@Test
void it_should_instantiate_server_from_service_loader_with_custom_configuration() {
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(configuration);
    final EmbeddedServer<?> server = adapter.getServer();
    assertThat(server).isNotNull().isExactlyInstanceOf(FakeEmbeddedServer.class);
    assertThat(server.getConfiguration()).isSameAs(configuration);
}
Also used : FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with FakeEmbeddedServerConfiguration

use of com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration 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

FakeEmbeddedServerConfiguration (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration)10 Test (org.junit.jupiter.api.Test)10 FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)9 FakeEmbeddedServer (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer)6 FakeServer (com.github.mjeanroy.junit.servers.utils.impl.FakeServer)2 EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)1 AbstractConfiguration (com.github.mjeanroy.junit.servers.servers.AbstractConfiguration)1 FakeWorker.startWorker (com.github.mjeanroy.junit.servers.servers.FakeWorker.startWorker)1 FakeWorker.stopWorker (com.github.mjeanroy.junit.servers.servers.FakeWorker.stopWorker)1 TestUtils.localUrl (com.github.mjeanroy.junit.servers.utils.commons.TestUtils.localUrl)1 FixtureClass (com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.never (org.mockito.Mockito.never)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1