You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by cocorossello <co...@gmail.com> on 2018/12/19 22:07:20 UTC
ApplicationComposer Junit 5 extension
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
Re: ApplicationComposer Junit 5 extension
Posted by cocorossello <co...@gmail.com>.
Hi,
I'm running in 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
Re: ApplicationComposer Junit 5 extension
Posted by cocorossello <co...@gmail.com>.
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
Re: ApplicationComposer Junit 5 extension
Posted by Jonathan Gallimore <jo...@gmail.com>.
> 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 <co...@gmail.com>
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
>