PS: updated the rule and added TransactionRule if you want to have another try
Romain Manni-Bucau @rmannibucau http://www.tomitribe.com http://rmannibucau.wordpress.com https://github.com/rmannibucau 2014-10-31 20:32 GMT+01:00 Romain Manni-Bucau <[email protected]>: > if you want to do it you have to do as in Injector and extract the > BeanContext (new BeanContext() is a blocker for me since it can break > several features). > > Note also it means transactions are not handled and could be the same > way. Means we can surely do a basic ContextRuleRunner allowing to run > in the right context then just implement the init/clear part in > RunAsRule and TxRule. > > > > Romain Manni-Bucau > Twitter: @rmannibucau > Blog: http://rmannibucau.wordpress.com/ > LinkedIn: http://fr.linkedin.com/in/rmannibucau > Github: https://github.com/rmannibucau > > > > 2014-10-31 17:31 GMT+01:00 Xavier Dury <[email protected]>: >> Indeed, but if you take a look at >> org.apache.openejb.junit.LocalClientRunner, the ThreadContext is always >> created by the Runner/Rule. >> >> Here's an example I made from what I found in LocalClientRunner: >> http://gist.github.com/kalgon/8ba09a6238955d4d1584 >> >> It works with both ApplicationComposerRule and EJBContainerRule but I don't >> know if there could be undesired side-effects. >> >> Xavier >> >> ---------------------------------------- >>> From: [email protected] >>> Date: Fri, 31 Oct 2014 17:17:41 +0100 >>> Subject: Re: EJBContainerRule and @RunTestAs >>> To: [email protected] >>> >>> Yes but with EJBContainerRule you don't have any "context" so you >>> can't "RunAs" out of the box. You can define your own SecurityService >>> (as property) and use a thread local to set it. But I didn't go this >>> way cause it can break easily tests with custom security services or >>> based on security environment >>> Romain Manni-Bucau >>> Twitter: @rmannibucau >>> Blog: http://rmannibucau.wordpress.com/ >>> LinkedIn: http://fr.linkedin.com/in/rmannibucau >>> Github: https://github.com/rmannibucau >>> >>> >>> >>> 2014-10-31 17:09 GMT+01:00 Xavier Dury <[email protected]>: >>>> Nice! >>>> >>>> It works fine with ApplicationComposerRule but not with EJBContainerRule >>>> (the ThreadContext is null). >>>> >>>> Xavier >>>> >>>> ---------------------------------------- >>>>> From: [email protected] >>>>> Date: Fri, 31 Oct 2014 16:11:08 +0100 >>>>> Subject: Re: EJBContainerRule and @RunTestAs >>>>> To: [email protected] >>>>> >>>>> Hello >>>>> >>>>> sorry for the delay: >>>>> https://git-wip-us.apache.org/repos/asf/tomee/?p=tomee.git;a=blob;f=container/openejb-core/src/test/java/org/apache/openejb/testing/RunAsRuleTest.java;h=deb838c4d95be85b5b3d299ac3c4f5b311816027;hb=5cede8c77a6336bd24ecea65f61e87d71ecbec66 >>>>> >>>>> If needed we can backport to 1.7.x >>>>> Romain Manni-Bucau >>>>> Twitter: @rmannibucau >>>>> Blog: http://rmannibucau.wordpress.com/ >>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau >>>>> Github: https://github.com/rmannibucau >>>>> >>>>> >>>>> >>>>> 2014-10-30 12:50 GMT+01:00 Xavier Dury <[email protected]>: >>>>>> Hi, >>>>>> >>>>>> While using EJBContainerRule, I have seen no easy way (~ @Run(Test)As) >>>>>> to invoke my EJBs with a particular user/role in my tests. >>>>>> >>>>>> There is already an InjectRule and a TransactionRule so would it be >>>>>> possible to add some kind of Run(Test)AsRule as well? >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Xavier >>>> >>
