ApplicationComposer Junit 5 extension

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ApplicationComposer Junit 5 extension

cocorossello
Hi,

Just in case somebody needs it I wrote Junit-jupiter extensions for
ApplicationComposer and SingleApplicationComposer. They are very simple
since all the work is already done, but they may save somebody's 10 minutes.

public class ApplicationComposerExtension implements BeforeEachCallback,
AfterEachCallback {

    private ApplicationComposers delegate;

    @Override
    public void beforeEach(ExtensionContext context) throws Exception {
        delegate = new
ApplicationComposers(context.getRequiredTestInstance());
        delegate.before(context.getRequiredTestInstance());
    }

    @Override
    public void afterEach(ExtensionContext context) throws Exception {
        delegate.after();
    }

}



public class SingleApplicationComposerExtension implements
BeforeEachCallback {


    private static volatile boolean started = false;
    private static final AtomicReference APP = new AtomicReference<>();
    private static final AtomicReference<Thread> HOOK = new
AtomicReference<>();

    @Override
    public void beforeEach(ExtensionContext context) throws Exception {
        start(context.getRequiredTestInstance().getClass());
        composerInject(context.getRequiredTestInstance());
    }


    public static void setApp(final Object o) {
        APP.set(o);
    }


    public static void close() {
        //Same as in SingleApplicationComposerRunner
        ...
    }


    private static void start(final Class<?> marker) throws Exception {
        //Same as in SingleApplicationComposerRunner
        ...
    }

    private static void composerInject(final Object target) throws
IllegalAccessException {
        //Same as in SingleApplicationComposerRunner
        ...
    }


}

Of course, I may not have taken into account all possibilities (it does work
in my project, that's all), so feel free to criticize or implement it some
other way.

If you want I can try to make a pull request with this (reusing code from
SingleApplicationComposerRunner) and some tests.


Best regards,
Vicente.



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: ApplicationComposer Junit 5 extension

jgallimore
> If you want I can try to make a pull request with this (reusing code from
SingleApplicationComposerRunner) and some tests.

That would be great. I'd love to try it out.

Jon

On Wed, Dec 19, 2018 at 10:14 PM cocorossello <[hidden email]>
wrote:

> Hi,
>
> Just in case somebody needs it I wrote Junit-jupiter extensions for
> ApplicationComposer and SingleApplicationComposer. They are very simple
> since all the work is already done, but they may save somebody's 10
> minutes.
>
> public class ApplicationComposerExtension implements BeforeEachCallback,
> AfterEachCallback {
>
>     private ApplicationComposers delegate;
>
>     @Override
>     public void beforeEach(ExtensionContext context) throws Exception {
>         delegate = new
> ApplicationComposers(context.getRequiredTestInstance());
>         delegate.before(context.getRequiredTestInstance());
>     }
>
>     @Override
>     public void afterEach(ExtensionContext context) throws Exception {
>         delegate.after();
>     }
>
> }
>
>
>
> public class SingleApplicationComposerExtension implements
> BeforeEachCallback {
>
>
>     private static volatile boolean started = false;
>     private static final AtomicReference APP = new AtomicReference<>();
>     private static final AtomicReference<Thread> HOOK = new
> AtomicReference<>();
>
>     @Override
>     public void beforeEach(ExtensionContext context) throws Exception {
>         start(context.getRequiredTestInstance().getClass());
>         composerInject(context.getRequiredTestInstance());
>     }
>
>
>     public static void setApp(final Object o) {
>         APP.set(o);
>     }
>
>
>     public static void close() {
>         //Same as in SingleApplicationComposerRunner
>         ...
>     }
>
>
>     private static void start(final Class<?> marker) throws Exception {
>         //Same as in SingleApplicationComposerRunner
>         ...
>     }
>
>     private static void composerInject(final Object target) throws
> IllegalAccessException {
>         //Same as in SingleApplicationComposerRunner
>         ...
>     }
>
>
> }
>
> Of course, I may not have taken into account all possibilities (it does
> work
> in my project, that's all), so feel free to criticize or implement it some
> other way.
>
> If you want I can try to make a pull request with this (reusing code from
> SingleApplicationComposerRunner) and some tests.
>
>
> Best regards,
> Vicente.
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
Reply | Threaded
Open this post in threaded view
|

Re: ApplicationComposer Junit 5 extension

cocorossello
Ok, please allow me this weekend to see what I can come up with



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: ApplicationComposer Junit 5 extension

cocorossello
This post was updated on .
Hi,

I'm running into problems here. I have added junit-jupiter dependencies and
made the extension, works fine. I have also upgraded surefire plugin.

However, when junit-jupiter artifacts are in the classpath the task
test-testng picks up all the tests, I don't know why the excludes are not
working, so each test is executed twice.

The PR is:
https://github.com/apache/tomee/pull/305



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html