You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Duke <wa...@gmail.com> on 2014/04/11 05:30:26 UTC

Wicket CDI application junit test

Hi everyone.
I'm trying to write some tests for my wicket-cdi application. But I can't
init wicket WebApplication, resulting:

 javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager' in
SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
java.naming.factory.url.pkgs=com.sun.enterprise.naming,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
[Root exception is javax.naming.NamingException: Invocation exception: Got
null ComponentInvocation ]
in WebAdminApplication.java row:
manager = (BeanManager)new InitialContext().lookup("java:comp/BeanManager");

LoginPageTest.java
public class LoginPageTest {
    private static WicketTester tester;
    @BeforeClass
    public static void setUpClass() {
        tester = new WicketTester(new WebAdminApplication());
    }
    @AfterClass
    public static void tearDownClass() {
    }
    @Test
    public void testRenderLoginPage() {
        LoginPage p = tester.startPage(LoginPage.class);
        tester.assertRenderedPage(LoginPage.class);
        ...
    }
}

WebAdminApplication.java
public class WebAdminApplication extends WebApplication {
    protected void init() {
        super.init();
        BeanManager manager = null;
        try {
            manager = (BeanManager)new
InitialContext().lookup("java:comp/BeanManager");
        } catch (NamingException ex) {
            logger.error("Error while creating BeanManager. Error text: {}",
ex.toString());
        }
        new CdiConfiguration(manager).configure(this);
        ...
    }
}

How I can get BeanManager for tests?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Hi Stepan!
Do you try DeltaSpike yourself? I try to run cdi in tests just like in  this
guide
<http://struberg.wordpress.com/2012/03/27/unit-testing-strategies-for-cdi-based-projects/> 
. And weld-se is failed in a simple test debuuging on a cdiContainer.boot();
with many WELD-001409 exceptions, like this:
Testcase: LoginPageTest:	Caused an ERROR
Exception List with 5 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous
dependencies for type DeltaSpikeContextExtension with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private
org.apache.deltaspike.core.impl.scope.conversation.GroupedConversationArtifactProducer.deltaSpikeContextExtension
  at
org.apache.deltaspike.core.impl.scope.conversation.GroupedConversationArtifactProducer.deltaSpikeContextExtension(GroupedConversationArtifactProducer.java:0)
  Possible dependencies: 
  - Extension [class
org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension] with
qualifiers [@Default];
jar:file:/C:/projects/WebApplication1/lib/DeltaSpike-0.6/deltaspike-core-impl-0.6.jar!/META-INF/services/javax.enterprise.inject.spi.Extension@25[org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension@1571a74],
  - org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider$Hk2Bean@52b341

Can you show me the right way to find a solution? Where I may make mistakes?

PS I use NB8.0, GF4.0.1 with weld upgraded to 2.0.5Final, Ecipselink-2.5.2
and wicket 6.14 with wicket-cdi 1.1 module.

Best regards,
Andrey

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665459.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
I'm sorry, I did not immediately explained. 
At first I tried to create tests for an existing application that uses
wicket-cdi 1.0 and Glassfish 3.1.2. I did not succeed because of
'javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager''. 
Then I think that with wicket-cdi1.1 it will be easer to write tests, and
later I will whatever migrate to glassfish4.0. Thats why I try to create a
simple test application with wicket-cdi 1.1 from wicket v6.14 and
Glassfish4.0, to understand what is necessary to do in migration.
Can't build this simple application yet. It fails without any injections,
even I try to use at least one anonymous class. I must write a code without
any anonymous classes? Or what can I do?


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665415.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Found some info in mail archives. I will try to upgrade gf4 with weld 2.1.x
as I read. Thanks.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665416.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The ticket and its related ticket (
https://issues.apache.org/jira/browse/WICKET-5226) explain that using CDI
1.0 in container that supports CDI 1.1 leads to these errors.
wicket-cdi integration tries to process all components (even Wicket's own
ones) for CDI annotations.

If you use a container that supports CDI 1.1 (like JBoss WildFly, Glassfish
4.x, etc.) then use wicket-cdi-1.1 module.
Another solution is to upgrade WELD to a newer version. 2.1.2 has the fix I
believe.

Check Wicket mail archives for this error. There is better explanation
about the problem by Emond.

Martin Grigorov
Wicket Training and Consulting


On Tue, Apr 15, 2014 at 11:49 AM, Duke <wa...@gmail.com> wrote:

> Thanks Martin, I read WICKET-5264, but I don't understand... I havn't any
> injections in anonymous inner classes in my code. I try to inject
> EntityManager in public class LoginPage.
> If I remove any injections, fail remains. It disappers only if I remove
> { new CdiConfiguration().configure(this); } in Application.init(), but my
> injections are nulls in this case.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665412.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Thanks Martin, I read WICKET-5264, but I don't understand... I havn't any
injections in anonymous inner classes in my code. I try to inject
EntityManager in public class LoginPage.
If I remove any injections, fail remains. It disappers only if I remove 
{ new CdiConfiguration().configure(this); } in Application.init(), but my
injections are nulls in this case.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665412.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

See https://issues.apache.org/jira/browse/WICKET-5264

Martin Grigorov
Wicket Training and Consulting


On Tue, Apr 15, 2014 at 6:29 AM, Duke <wa...@gmail.com> wrote:

> Hi all.
> Tried to build simple example with EntityManager injection:
>
> public class LoginPage extends BasePage {
>
>     @Inject EntityManager em;
>     ...
> }
>
> public class Application extends WebApplication {
>     @Override
>     protected void init() {
>         super.init();
>         new CdiConfiguration().configure(this);
>     }
> }
>
> It fails on new CdiConfiguration().configure(this); with message:
> Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000070
> Simple
> bean [EnhancedAnnotatedTypeImpl]  class
> org.apache.wicket.markup.html.panel.FeedbackPanel$1 cannot be a non-static
> inner class
>         at
>
> org.jboss.weld.injection.producer.BasicInjectionTarget.checkType(BasicInjectionTarget.java:81)
>         at
>
> org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:69)
>         at
>
> org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:52)
>         at
>
> org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:95)
>         at
>
> org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:78)
>
> If I comment line with configuring of CdiConfiguration, all injections are
> nulls ((
> What I am doing wrong?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665402.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Hi all.
Tried to build simple example with EntityManager injection:

public class LoginPage extends BasePage {
    
    @Inject EntityManager em;
    ...
}

public class Application extends WebApplication {
    @Override
    protected void init() {
        super.init(); 
        new CdiConfiguration().configure(this);
    }
}

It fails on new CdiConfiguration().configure(this); with message:
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000070 Simple
bean [EnhancedAnnotatedTypeImpl]  class
org.apache.wicket.markup.html.panel.FeedbackPanel$1 cannot be a non-static
inner class
	at
org.jboss.weld.injection.producer.BasicInjectionTarget.checkType(BasicInjectionTarget.java:81)
	at
org.jboss.weld.injection.producer.BasicInjectionTarget.<init>(BasicInjectionTarget.java:69)
	at
org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:52)
	at
org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:95)
	at
org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:78)

If I comment line with configuring of CdiConfiguration, all injections are
nulls ((
What I am doing wrong?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665402.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Found your thread, David :) Many thanks.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665373.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by David Beer <da...@gmail.com>.
Hi

See my earlier thread on CDI 1.1. A lot the problems related to 1.1 come
from not setting your beans.xml file up correctly for your environment. In
General CDI 1.0 is for EE 6 and 1.1 is for EE 7. This is why 1.0 has
dificulties with GF 4 as it is designed for Java EE 7. If you get a
stacktrace use the first part to search, there are lots of answers out
there. 1.1 is quite different.


On 11 April 2014 10:31, Duke <wa...@gmail.com> wrote:

> Thanks, Stephan. I will try to use DeltaSpike with wicket-cdi1.0 in tests.
>
> PS Maybe using wicket-cdi1.1 version will be more easy and it will not need
> any additional libraries?
> PPS I don't understand about wicket-cdi 1.1 version. Will it work correctly
> with glassfish 4.0? I tryed cdi1.0, but it don't work. Then I found an
> issue
> about this problem.
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665371.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Wicket CDI application junit test

Posted by Duke <wa...@gmail.com>.
Thanks, Stephan. I will try to use DeltaSpike with wicket-cdi1.0 in tests.

PS Maybe using wicket-cdi1.1 version will be more easy and it will not need
any additional libraries?
PPS I don't understand about wicket-cdi 1.1 version. Will it work correctly
with glassfish 4.0? I tryed cdi1.0, but it don't work. Then I found an issue
about this problem.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366p4665371.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket CDI application junit test

Posted by Stephan Schrader <zs...@gmail.com>.
Hi,

maybe you can use DeltaSpike to get the BeanManager reference:
http://deltaspike.apache.org/core.html#beanmanagerprovider

Stephan


2014-04-11 5:30 GMT+02:00 Duke <wa...@gmail.com>:

> Hi everyone.
> I'm trying to write some tests for my wicket-cdi application. But I can't
> init wicket WebApplication, resulting:
>
>  javax.naming.NamingException: Lookup failed for 'java:comp/BeanManager' in
>
> SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
> java.naming.factory.url.pkgs=com.sun.enterprise.naming,
>
> java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
> [Root exception is javax.naming.NamingException: Invocation exception: Got
> null ComponentInvocation ]
> in WebAdminApplication.java row:
> manager = (BeanManager)new
> InitialContext().lookup("java:comp/BeanManager");
>
> LoginPageTest.java
> public class LoginPageTest {
>     private static WicketTester tester;
>     @BeforeClass
>     public static void setUpClass() {
>         tester = new WicketTester(new WebAdminApplication());
>     }
>     @AfterClass
>     public static void tearDownClass() {
>     }
>     @Test
>     public void testRenderLoginPage() {
>         LoginPage p = tester.startPage(LoginPage.class);
>         tester.assertRenderedPage(LoginPage.class);
>         ...
>     }
> }
>
> WebAdminApplication.java
> public class WebAdminApplication extends WebApplication {
>     protected void init() {
>         super.init();
>         BeanManager manager = null;
>         try {
>             manager = (BeanManager)new
> InitialContext().lookup("java:comp/BeanManager");
>         } catch (NamingException ex) {
>             logger.error("Error while creating BeanManager. Error text:
> {}",
> ex.toString());
>         }
>         new CdiConfiguration(manager).configure(this);
>         ...
>     }
> }
>
> How I can get BeanManager for tests?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-CDI-application-junit-test-tp4665366.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>