Search in sources :

Example 11 with FixtureClass

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

the class JunitServerExtensionTest method it_should_reset_injected_http_client_after_each_test.

@Test
void it_should_reset_injected_http_client_after_each_test() {
    final JunitServerExtension extension = new JunitServerExtension();
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    extension.beforeAll(context);
    extension.beforeEach(context);
    final HttpClient client = testInstance.client;
    final FakeStore store = context.getSingleStore();
    extension.afterEach(context);
    assertThat(store.get("annotationsAdapter")).isNull();
    assertThat(testInstance.client).isNull();
    assertThat(client.isDestroyed()).isTrue();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient) NingAsyncHttpClient(com.github.mjeanroy.junit.servers.client.impl.ning.NingAsyncHttpClient) Test(org.junit.jupiter.api.Test)

Example 12 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_all_tests.

@Test
void it_should_start_server_before_all_tests() {
    final JunitServerExtension extension = new JunitServerExtension();
    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();
    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 FixtureClass

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

the class AnnotationsHandlerRuleTest method it_should_implement_to_string.

@Test
void it_should_implement_to_string() {
    final AbstractConfiguration configuration = new AbstractConfigurationMockBuilder().build();
    final EmbeddedServer<?> embeddedServer = new EmbeddedServerMockBuilder().build();
    final FixtureClass target = new FixtureClass();
    final AnnotationsHandlerRule rule = new AnnotationsHandlerRule(target, embeddedServer, configuration);
    assertThat(rule).hasToString("AnnotationsHandlerRule{" + "target: FixtureClass, " + "annotationHandlers: AnnotationsHandlerRunner{" + "handlers: [" + "ServerAnnotationHandler{" + "annotationKlass: interface com.github.mjeanroy.junit.servers.annotations.TestServer, " + "server: MockEmbeddedServer" + "}, " + "ConfigurationAnnotationHandler{" + "annotationKlass: interface com.github.mjeanroy.junit.servers.annotations.TestServerConfiguration, " + "configuration: MockAbstractConfiguration" + "}, " + "HttpClientAnnotationHandler{" + "annotationKlass: interface com.github.mjeanroy.junit.servers.annotations.TestHttpClient, " + "server: MockEmbeddedServer" + "}" + "]" + "}" + "}");
}
Also used : AbstractConfiguration(com.github.mjeanroy.junit.servers.servers.AbstractConfiguration) AbstractConfigurationMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.AbstractConfigurationMockBuilder) FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with FixtureClass

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

the class AnnotationsHandlerRuleTest method it_should_process_handlers.

@Test
void it_should_process_handlers() {
    final AbstractConfiguration configuration = new AbstractConfigurationMockBuilder().build();
    final EmbeddedServer<?> embeddedServer = new EmbeddedServerMockBuilder().build();
    final FixtureClass target = new FixtureClass();
    final AnnotationsHandlerRule rule = new AnnotationsHandlerRule(target, embeddedServer, configuration);
    verifyBeforeTest(configuration, embeddedServer, target, rule);
    verifyAfterTest(configuration, embeddedServer, target, rule);
}
Also used : AbstractConfiguration(com.github.mjeanroy.junit.servers.servers.AbstractConfiguration) AbstractConfigurationMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.AbstractConfigurationMockBuilder) FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test)

Example 15 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_configuration_parameter.

@Test
void it_should_resolve_configuration_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_configuration", AbstractConfiguration.class);
    final Object result = extension.resolveParameter(parameterContext, context);
    assertThat(result).isNotNull().isSameAs(serverAdapter.getServer().getConfiguration());
}
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)

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