Hi Heiko!

Afaik all unit runners (junit, testng) do create and manage the test class 
instances themselfs. We only do injection into those existing instances. With 
other words: we just fill the injection points. Whenever I need to have an 
intercepted method, I create a public static inner class in my test. E.g. when 
I need a @Transactional DbHelper with a cleanup() method which should run in an 
own transaction. 

private @Inject DbHelper dbHelper;

pubic static class DbHelper {
  private @Inject EntityManager em;
   @Transactional
   public void cleanupDb() {
     em.....
  }
}

@Before
public void doCleanup() {
  cleanInstances() // restart session and request scoped context
  dbHelper.cleanupDb();

  cleanInstances() // again to ensure the test has clean instances and the em 
got closed

}

LieGrue,
strub




On Friday, 7 February 2014, 9:13, "it-media.k...@daimler.com" 
<it-media.k...@daimler.com> wrote:
 
Hey Romain,
>
>that was the missing piece of the puzzle and lets me step down in 
>embarrassment for such an idiotic mistake. I've had the assumtion that for a 
>maven surefire test, the beans.xml provided in src/main/resources/META-INF 
>which IS obviously used, is enough, but after you pointed this out, I simply 
>added another one under src/test/resources/META-INF and voilá, getBeans() 
>returns a Bean that I can retrieve an instance from, that indeed will make 
>interceptors work.
>
>Thank you very much for your help,
>
>Heiko
>
>> -----Ursprüngliche Nachricht-----
>> Von: Romain Manni-Bucau [mailto:rmannibu...@gmail.com]
>> Gesendet: Freitag, 7. Februar 2014 08:55
>> An: dev@deltaspike.apache.org
>> Betreff: Re: Interceptors not being called in JUnit-aware CDI environment
>>
>> =========================================================
>> ======
>>
>> ATTENTION! This message contains suspicious URL(s) possibly redirecting to
>> malicious content. Our security gateways target known problem URLs like
>> freeweb or URL Shorteners that are being abused by spammers. Some
>> examples would be groups.google.com or tinyurl.com. Please check the sender
>> and hyperlinks in the e-mail accurately before clicking on a link. If this 
>> email
>> seems obviously bad to you please delete it.  More information is available 
>> on
>> our website Information Security @ Daimler: http://intra.corpintra.net/intra-
>> is-e/spam
>>
>> =========================================================
>> ======
>>
>> ACHTUNG! Diese E-Mail enthält verdächtige URLs welche möglicherweise auf
>> schädlichen Inhalt verweisen. Die Security Gateways prüfen auf bekannte
>> Problem-URLs  wie zum Beispiel URL-Abkürzungen, die bevorzugt von
>> Spammern mißbraucht werden (tinyurl.com, groups.google.com, ...). Bitte
>> prüfen Sie den Absender und die URLs in dieser E-Mail gewissenhaft bevor sie
>> die verknüpften Inhalte aufrufen. Bitte löschen Sie diese E-Mail, wenn Sie 
>> der
>> Meinung sind, daß sich der Verdacht bestätigt. Weitere Informationen zu
>> unerwünschter E-Mail / SPAM finden Sie auf den Seiten der
>> Informationssicherheit bei Daimler unter: 
>> http://intra.corpintra.net/intra-is-
>> d/spam
>>
>> =========================================================
>> ======
>>
>>
>> is you test class scanned by cdi? I mean did you provide a META-
>> INF/beans.xml for tests?
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014-02-07  <it-media.k...@daimler.com>:
>> > Hello Romain,
>> >
>> > thank you for your fast response. Yes I want to intercept the test itself.
>> >
>> > I've checked into various ways on how to actually create a bean, however
>> nothing worked out. You mention to call beanManager.getXXX() but for my
>> point that is not enough information.
>> >
>> > I tried to retrieve the beans of the test class via beanManager.getBeans() 
>> > but
>> regardless of what I try as annotation literals there (non, Any, etc.) 
>> nothing
>> works, the list is always empty. What method exactly did you have in mind
>> here?
>> >
>> > Thanks,
>> >
>> > Heiko
>> >
>> >> -----Ursprüngliche Nachricht-----
>> >> Von: Romain Manni-Bucau [mailto:rmannibu...@gmail.com]
>> >> Gesendet: Freitag, 7. Februar 2014 08:26
>> >> An: dev@deltaspike.apache.org
>> >> Betreff: Re: Interceptors not being called in JUnit-aware CDI
>> >> environment
>> >>
>> >>
>> =========================================================
>> >> ======
>> >>
>> >> ATTENTION! This message contains suspicious URL(s) possibly
>> >> redirecting to malicious content. Our security gateways target known
>> >> problem URLs like freeweb or URL Shorteners that are being abused by
>> >> spammers. Some examples would be groups.google.com or tinyurl.com.
>> >> Please check the sender and hyperlinks in the e-mail accurately
>> >> before clicking on a link. If this email seems obviously bad to you
>> >> please delete it.  More information is available on our website
>> >> Information Security @ Daimler: http://intra.corpintra.net/intra-
>> >> is-e/spam
>> >>
>> >>
>> =========================================================
>> >> ======
>> >>
>> >> ACHTUNG! Diese E-Mail enthält verdächtige URLs welche möglicherweise
>> >> auf schädlichen Inhalt verweisen. Die Security Gateways prüfen auf
>> >> bekannte Problem-URLs  wie zum Beispiel URL-Abkürzungen, die
>> >> bevorzugt von Spammern mißbraucht werden (tinyurl.com,
>> >> groups.google.com, ...). Bitte prüfen Sie den Absender und die URLs
>> >> in dieser E-Mail gewissenhaft bevor sie die verknüpften Inhalte
>> >> aufrufen. Bitte löschen Sie diese E-Mail, wenn Sie der Meinung sind,
>> >> daß sich der Verdacht bestätigt. Weitere Informationen zu
>> >> unerwünschter E-Mail / SPAM finden Sie auf den Seiten der
>> >> Informationssicherheit bei Daimler unter:
>> >> http://intra.corpintra.net/intra-is-
>> >> d/spam
>> >>
>> >>
>> =========================================================
>> >> ======
>> >>
>> >>
>> >> HI
>> >>
>> >> You want to intercept the test? so it means the runner needs to
>> >> invoke "business" methods of the test class which is not the case by
>> >> default (ie result shouldn't be built from a newInstance() but from a
>> beanManager.getXXX()).
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >>
>> >> 2014-02-07  <it-media.k...@daimler.com>:
>> >> > Hello,
>> >> >
>> >> > I've been trying to start the CDI container during Junit-Testing as
>> >> > described at the following page,
>> >> >
>> >> > http://struberg.wordpress.com/2012/03/27/unit-testing-strategies-fo
>> >> > r-c
>> >> > di-based-projects/
>> >> >
>> >> > though I'm using Junit 4 and implemented everything using a new
>> >> > Runner (to
>> >> annotate tests with @RunWith). I kind of got inspired by he CDIUnit
>> >> project, but it works only with Weld and I want to use OpenWebBeans.
>> >> > The major things like injection work perfectly, however, I
>> >> > realized, that even
>> >> though I implemented the following code to provided a CDI aware
>> >> Test-Class, an interceptor annotation on a test method is completely
>> >> ignored, thus the interceptors AroundInvoke annotated method is not 
>> >> called.
>> >> >
>> >> >     private <T> T createTest(final Class<T> testClass) throws Exception
>> >> >     {
>> >> >         final BeanManager beanManager =
>> >> > cdiContainer.getBeanManager();
>> >> >
>> >> >         final CreationalContext<T> creationalContext =
>> >> > beanManager.createCreationalContext(null);
>> >> >
>> >> >         final AnnotatedType<T> annotatedType =
>> >> beanManager.createAnnotatedType(testClass);
>> >> >         final InjectionTarget<T> injectionTarget =
>> >> > beanManager.createInjectionTarget(annotatedType);
>> >> >
>> >> >         final T result = (T)
>> >> > getTestClass().getOnlyConstructor().newInstance();
>> >> >
>> >> >         injectionTarget.inject(result, creationalContext);
>> >> >
>> >> >         return result;
>> >> >     }
>> >> >
>> >> > Is this expected behaviour? I'm not so familiar with how
>> >> > interceptors are really implemented, but I would have guest that
>> >> > after providing a creational context and complete injection for the
>> >> > test class, interceptor annotations should work too. The
>> >> > interceptor itself is registered correctly. It is listed among all
>> >> > interceptors when calling
>> >> >
>> >> > WebBeansContext.currentInstance().getInterceptorsManager().getCdiIn
>> >> > ter
>> >> > ceptors()
>> >> >
>> >> > however, a test annotated with the interceptor does not trigger
>> >> > execution of
>> >> the AroundInvoke-method.
>> >> >
>> >> > Would be great, if somebody has a thought or a hint on this.
>> >> >
>> >> > Thanks,
>> >> >
>> >> > Heiko
>> >> >
>> >> >
>> >> > If you are not the addressee, please inform us immediately that you
>> >> > have
>> >> received this e-mail by mistake, and delete it. We thank you for your
>> support.
>
>> >> >
>> >
>> > If you are not the addressee, please inform us immediately that you have
>> received this e-mail by mistake, and delete it. We thank you for your 
>> support.
>> >
>
>If you are not the addressee, please inform us immediately that you have 
>received this e-mail by mistake, and delete it. We thank you for your support.
>
>
>

Reply via email to