Search in sources :

Example 1 with FixtureClass

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

the class AnnotationsHandlerRunnerTest 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 AnnotationsHandlerRunner adapter = new AnnotationsHandlerRunner(embeddedServer, configuration);
    verifyBeforeTest(configuration, embeddedServer, target, adapter);
    verifyAfterTest(configuration, embeddedServer, target, adapter);
}
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 2 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_http_client_parameter_with_custom_strategy.

@Test
void it_should_resolve_http_client_parameter_with_custom_strategy() throws Exception {
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    final JunitServerExtension extension = initializeExtension(context);
    final ParameterContext parameterContext = createParameterContext("method_http_client_custom", HttpClient.class);
    final Object result = extension.resolveParameter(parameterContext, context);
    assertThat(result).isNotNull().isExactlyInstanceOf(NingAsyncHttpClient.class);
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Test(org.junit.jupiter.api.Test)

Example 3 with FixtureClass

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

the class JunitServerExtensionTest method verifySupportsParameter.

private void verifySupportsParameter(String methodName, Class<?> klass) throws Exception {
    final JunitServerExtension extension = new JunitServerExtension();
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    extension.beforeAll(context);
    final Method method = getClass().getMethod(methodName, klass);
    final Parameter parameter = method.getParameters()[0];
    final ParameterContext parameterContext = new FakeParameterContext(parameter);
    assertThat(extension.supportsParameter(parameterContext, context)).isTrue();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) Parameter(java.lang.reflect.Parameter) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Method(java.lang.reflect.Method)

Example 4 with FixtureClass

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

the class JunitServerExtensionTest method it_should_inject_annotated_field_before_each_test.

@Test
void it_should_inject_annotated_field_before_each_test() {
    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);
    extension.beforeEach(context);
    final AnnotationsHandlerRunner annotationsAdapter = store.get("annotationsAdapter", AnnotationsHandlerRunner.class);
    assertThat(annotationsAdapter).isNotNull();
    assertThat(testInstance.server).isNotNull().isSameAs(serverAdapter.getServer());
    assertThat(testInstance.configuration).isNotNull().isSameAs(serverAdapter.getServer().getConfiguration());
    assertThat(testInstance.client).isNotNull();
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) AnnotationsHandlerRunner(com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner) Test(org.junit.jupiter.api.Test)

Example 5 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_http_client_parameter_with_auto_strategy.

@Test
void it_should_resolve_http_client_parameter_with_auto_strategy() throws Exception {
    final FixtureClass testInstance = new FixtureClass();
    final FakeExtensionContext context = new FakeExtensionContext(testInstance);
    final JunitServerExtension extension = initializeExtension(context);
    final ParameterContext parameterContext = createParameterContext("method_http_client", HttpClient.class);
    final Object result = extension.resolveParameter(parameterContext, context);
    assertThat(result).isNotNull().isInstanceOf(HttpClient.class);
}
Also used : FixtureClass(com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass) 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