Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding demo showing how to use CDI + JPA + JTA (@Transactional, trans… #39

Merged
merged 2 commits into from
Jan 22, 2019

Conversation

gunnarmorling
Copy link
Member

…actional observer methods) in unittests

Hey @gsmet, could you take a look at this one? The other day I wanted to run CDI and Hibernate ORM in unit tests and it was quite some effort. So I thought I'd share my findings in a blog post, for which this will be the accompanying code.

@gunnarmorling
Copy link
Member Author

@manovotn, @mkouba, I'm using Weld JUnit in this example; could you take a look and let me know whether I'm doing something stupid?

Also is there no simpler way than this (specifically, hooking up Narayana and a JNDI server) for using @Transactional and transactional observer methods in JUnit tests that don't run in WildFly proper (via Arquillian)?

I'd like to blog about this, hoping it's useful to others, too. But at the same time I'm wondering whether these bits should be added to Weld JUnit eventually, making the experience much simpler out of the box. WDYT?

@gunnarmorling
Copy link
Member Author

Also filed weld/weld-testing#65 to see whether this all could be baked right into Weld JUnit, giving a smoother experience out-of-the-box.

@manovotn
Copy link

@manovotn, @mkouba, I'm using Weld JUnit in this example; could you take a look and let me know whether I'm doing something stupid?

Scanned the code, weld-junit bits are looking good!

I'd like to blog about this, hoping it's useful to others, too. But at the same time I'm wondering whether these bits should be added to Weld JUnit eventually, making the experience much simpler out of the box. WDYT?

Sounds like a good idea to me, let's discuss that in the weld-junit issue you created.

private static NamingBeanImpl NAMING_BEAN;

@Rule
public WeldInitiator weld = WeldInitiator.from(((Weld) SeContainerInitializer.newInstance()))
Copy link

@manovotn manovotn Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid type cast here, you can simply use Weld API instead of CDI itself.
Just doing WeldInitiator.from(new Weld())... should do the trick.

Also note that by doing this (e.g. by using pure new Weld()), you are running with enabled discovery (your CP wll be scanned for beans) whereas commonly a synthetic archive is used to reduce bootstrap time. Not sure you intended that, so just pointing it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, didn't know it'd be as simple as calling new Weld() :-)

you are running with enabled discovery...

Yes, I did this intentionally. Having to specify all the classes explicitly is one of the things I find a bit cumbersome when using Arquillian. Bootstrap time was perfectly fine when I ran the test. But it's definitely good to keep this in mind. Thanks!

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an interesting addition to me.

@gunnarmorling
Copy link
Member Author

Cool, thanks for reviewing. I'll merge it then and write something for in.relation.to within the next few days.

@gunnarmorling gunnarmorling merged commit a97abd9 into hibernate:master Jan 22, 2019
@gunnarmorling
Copy link
Member Author

Merged. Thanks, everone.

@gunnarmorling gunnarmorling deleted the cdijpatesting branch January 20, 2020 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants