Search in sources :

Example 1 with EmbeddedTomcatConfiguration

use of com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration 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();
}
Also used : EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) EmbeddedTomcatConfiguration(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with EmbeddedTomcatConfiguration

use of com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration in project junit-servers by mjeanroy.

the class EmbeddedTomcatMockBuilder method build.

/**
 * Build mock instance of {@link EmbeddedTomcat}.
 *
 * @return The mock instance.
 */
public EmbeddedTomcat build() {
    final EmbeddedTomcat tomcat = mock(EmbeddedTomcat.class);
    when(tomcat.getScheme()).thenReturn(scheme);
    when(tomcat.getHost()).thenReturn(host);
    when(tomcat.getPort()).thenReturn(port);
    when(tomcat.getPath()).thenReturn(path);
    when(tomcat.isStarted()).thenReturn(false);
    String url = this.url == null ? url(scheme, host, port, path) : this.url;
    when(tomcat.getUrl()).thenReturn(url);
    EmbeddedTomcatConfiguration configuration = this.configuration == null ? new EmbeddedTomcatConfigurationMockBuilder().build() : this.configuration;
    when(tomcat.getConfiguration()).thenReturn(configuration);
    doAnswer(new IsStartedAnswer(tomcat, true)).when(tomcat).start();
    doAnswer(new IsStartedAnswer(tomcat, false)).when(tomcat).stop();
    return tomcat;
}
Also used : EmbeddedTomcat(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcat) EmbeddedTomcatConfiguration(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration)

Example 3 with EmbeddedTomcatConfiguration

use of com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration in project junit-servers by mjeanroy.

the class TomcatServerJunit4RuleTest method it_should_create_server_from_configuration.

@Test
void it_should_create_server_from_configuration() throws Throwable {
    final EmbeddedTomcatConfiguration configuration = EmbeddedTomcatConfiguration.defaultConfiguration();
    final TomcatServerJunit4Rule rule = createRule(configuration);
    assertThat(rule.getServer()).isNotNull();
    assertThat(rule.getScheme()).isEqualTo("http");
    assertThat(rule.getHost()).isEqualTo("localhost");
    assertThat(rule.getPath()).isEqualTo(configuration.getPath());
    // not started
    assertThat(rule.getPort()).isZero();
    assertThat(rule.getUrl()).isNotEmpty();
    assertRule(rule);
}
Also used : EmbeddedTomcatConfiguration(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with EmbeddedTomcatConfiguration

use of com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration in project junit-servers by mjeanroy.

the class TomcatServerJunit4RuleTest method it_should_create_rule_with_server.

@Test
void it_should_create_rule_with_server() throws Throwable {
    final EmbeddedTomcatConfiguration config = mock(EmbeddedTomcatConfiguration.class);
    final EmbeddedTomcat tomcat = new EmbeddedTomcatMockBuilder().withConfiguration(config).build();
    final TomcatServerJunit4Rule rule = createRule(tomcat);
    assertThat(rule.getServer()).isSameAs(tomcat);
    assertThat(rule.getScheme()).isEqualTo(tomcat.getScheme());
    assertThat(rule.getHost()).isEqualTo(tomcat.getHost());
    assertThat(rule.getPort()).isEqualTo(tomcat.getPort());
    assertThat(rule.getPath()).isEqualTo(tomcat.getPath());
    assertThat(rule.getUrl()).isEqualTo(tomcat.getUrl());
    verify(tomcat, never()).start();
    verify(tomcat, never()).stop();
    evaluateRule(rule);
    InOrder inOrder = inOrder(tomcat);
    inOrder.verify(tomcat).start();
    inOrder.verify(tomcat).stop();
}
Also used : InOrder(org.mockito.InOrder) EmbeddedTomcat(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcat) EmbeddedTomcatConfiguration(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration) EmbeddedTomcatMockBuilder(com.github.mjeanroy.junit.servers.tomcat.tests.builders.EmbeddedTomcatMockBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with EmbeddedTomcatConfiguration

use of com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration in project junit-servers by mjeanroy.

the class ServerRuleTest method it_should_start_jetty_with_custom_configuration_because_of_classpath_detection.

@Test
void it_should_start_jetty_with_custom_configuration_because_of_classpath_detection() {
    final EmbeddedTomcatConfiguration configuration = EmbeddedTomcatConfiguration.builder().withPort(9000).build();
    rule = new ServerRule(configuration);
    assertThat(rule.getServer()).isExactlyInstanceOf(EmbeddedTomcat.class);
    assertThat(rule.getServer().getConfiguration()).isEqualTo(configuration);
}
Also used : EmbeddedTomcatConfiguration(com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

EmbeddedTomcatConfiguration (com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcatConfiguration)5 Test (org.junit.jupiter.api.Test)4 EmbeddedTomcat (com.github.mjeanroy.junit.servers.tomcat.EmbeddedTomcat)2 EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)1 EmbeddedTomcatMockBuilder (com.github.mjeanroy.junit.servers.tomcat.tests.builders.EmbeddedTomcatMockBuilder)1 InOrder (org.mockito.InOrder)1