Search in sources :

Example 6 with FakeEmbeddedServerConfigurationBuilder

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

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

the class AbstractEmbeddedServerTest method it_should_get_url_with_custom_path.

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

Example 8 with FakeEmbeddedServerConfigurationBuilder

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

the class AbstractEmbeddedServerTest method it_should_execute_hook_before_doStop.

@Test
void it_should_execute_hook_before_doStop() {
    final Hook hook = mock(Hook.class);
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().withHook(hook).build();
    final Answer<Object> ensureIsStillStartedAnswer = invocation -> {
        FakeEmbeddedServer server = invocation.getArgument(0);
        assertThat(server).isNotNull();
        assertThat(server.getNbStop()).isZero();
        return null;
    };
    doAnswer(ensureIsStillStartedAnswer).when(hook).post(any(EmbeddedServer.class));
    server = spy(new FakeEmbeddedServer(configuration));
    server.start();
    assertThat(server.isStarted()).isTrue();
    verify(hook, never()).post(any(EmbeddedServer.class));
    server.stop();
    assertThat(server.isStarted()).isFalse();
    assertThat(server.getNbStop()).isEqualTo(1);
}
Also used : FakeEmbeddedServerConfiguration(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.times(org.mockito.Mockito.times) FakeWorker.stopWorker(com.github.mjeanroy.junit.servers.servers.FakeWorker.stopWorker) Mockito.spy(org.mockito.Mockito.spy) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Answer(org.mockito.stubbing.Answer) CountDownLatch(java.util.concurrent.CountDownLatch) FakeEmbeddedServer(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer) FakeWorker.startWorker(com.github.mjeanroy.junit.servers.servers.FakeWorker.startWorker) Mockito.never(org.mockito.Mockito.never) TestUtils.localUrl(com.github.mjeanroy.junit.servers.utils.commons.TestUtils.localUrl) Mockito.doAnswer(org.mockito.Mockito.doAnswer) FakeServer(com.github.mjeanroy.junit.servers.utils.impl.FakeServer) Mockito.mock(org.mockito.Mockito.mock) FakeEmbeddedServer(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer) 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 9 with FakeEmbeddedServerConfigurationBuilder

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

the class AbstractEmbeddedServerTest method it_should_have_custom_configuration.

@Test
void it_should_have_custom_configuration() {
    final String path = "/foo";
    final int port = 8080;
    final String webapp = "/foo/bar";
    final FakeEmbeddedServerConfiguration configuration = new FakeEmbeddedServerConfigurationBuilder().withPath(path).withPort(port).withWebapp(webapp).build();
    server = new FakeEmbeddedServer(configuration);
    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) FakeEmbeddedServer(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer) Test(org.junit.jupiter.api.Test)

Example 10 with FakeEmbeddedServerConfigurationBuilder

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

the class ServerRuleTest 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 ServerRule rule = createRule(configuration);
    final EmbeddedServer<?> server = rule.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)

Aggregations

FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)12 Test (org.junit.jupiter.api.Test)12 FakeEmbeddedServer (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServer)9 FakeEmbeddedServerConfiguration (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfiguration)9 FakeServer (com.github.mjeanroy.junit.servers.utils.impl.FakeServer)2 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 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 Answer (org.mockito.stubbing.Answer)1