Search in sources :

Example 1 with AnnotationsHandlerRunner

use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner 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 2 with AnnotationsHandlerRunner

use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner in project junit-servers by mjeanroy.

the class JunitServerExtension method afterEach.

@Override
public void afterEach(ExtensionContext context) {
    try {
        Object target = context.getRequiredTestInstance();
        AnnotationsHandlerRunner annotationsAdapter = findAnnotationsHandlerAdapterInStore(context);
        annotationsAdapter.afterEach(target);
    } finally {
        unregisterEmbeddedServer(context, false);
        removeAnnotationsHandlerAdapterFromStore(context);
    }
}
Also used : AnnotationsHandlerRunner(com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner)

Example 3 with AnnotationsHandlerRunner

use of com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner in project junit-servers by mjeanroy.

the class JunitServerExtension method beforeEach.

@Override
public void beforeEach(ExtensionContext context) {
    EmbeddedServerRunner serverAdapter = findEmbeddedServerAdapterInStore(context);
    // The extension was not declared as a static extension.
    if (serverAdapter == null) {
        serverAdapter = registerEmbeddedServer(context, false);
    }
    EmbeddedServer<?> server = serverAdapter.getServer();
    AbstractConfiguration configuration = server.getConfiguration();
    AnnotationsHandlerRunner annotationsAdapter = new AnnotationsHandlerRunner(server, configuration);
    annotationsAdapter.beforeEach(context.getRequiredTestInstance());
    putAnnotationsHandlerAdapterInStore(context, annotationsAdapter);
}
Also used : AbstractConfiguration(com.github.mjeanroy.junit.servers.servers.AbstractConfiguration) EmbeddedServerRunner(com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner) AnnotationsHandlerRunner(com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner)

Aggregations

AnnotationsHandlerRunner (com.github.mjeanroy.junit.servers.engine.AnnotationsHandlerRunner)3 EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)2 AbstractConfiguration (com.github.mjeanroy.junit.servers.servers.AbstractConfiguration)1 FixtureClass (com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass)1 Test (org.junit.jupiter.api.Test)1