Question

I'm working on Junit tests do validate SessionBeans in my project. There are a local session bean with no interfaces and I want to lookup it in my test.

So, I put this dependence in pom.xml of my ejb module (same of the test):

<dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>4.0</version>
        <scope>test</scope>
</dependency>

So, I've build my test method:

 @Test
public void authenticateUser() throws NamingException {

    EJBContainer container = EJBContainer.createEJBContainer();
    AccessControlService service = (AccessControlService)container.getContext().lookup("java:global/app/module/AccessControlService");
    UserCredentials cred = new UserCredentials("admin", AccessControlUtil.getEncryptedPassword("adminadmin".toCharArray()));
    try {
        AccessControlSession session = service.authenticate(cred);
    } catch (Exception ex) {
        Logger.getLogger(AccessControlTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

After execute the test, I received this exception stacktrace:

SEVERE: EJB6001:Caught exception instantiating EmbeddedContainer.
java.lang.NoSuchMethodError: org.glassfish.hk2.utilities.AbstractActiveDescriptor.<init>(Ljava/util/Set;Ljava/lang/Class;Ljava/lang/String;Ljava/util/Set;Lorg/glassfish/hk2/api/DescriptorType;Lorg/glassfish/hk2/api/DescriptorVisibility;ILjava/lang/Boolean;Ljava/lang/String;Ljava/util/Map;)V
    at org.jvnet.hk2.config.DomDescriptor.<init>(DomDescriptor.java:56)
    at org.jvnet.hk2.config.Dom.register(Dom.java:210)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:245)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:238)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:231)
    at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:190)
    at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:100)
    at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:94)
    at org.glassfish.config.support.DomainXml.parseDomainXml(DomainXml.java:259)
    at org.glassfish.config.support.DomainXml.run(DomainXml.java:117)
    at org.jvnet.hk2.config.ConfigurationPopulator.populateConfig(ConfigurationPopulator.java:58)
    at org.glassfish.hk2.bootstrap.HK2Populator.populateConfig(HK2Populator.java:158)
    at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.populateConfig(AbstractModulesRegistryImpl.java:211)
    at com.sun.enterprise.module.bootstrap.Main.createServiceLocator(Main.java:273)
    at com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime.newGlassFish(StaticGlassFishRuntime.java:111)
    at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createContainer(EJBContainerProviderImpl.java:205)
    at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:129)
    at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:127)
    at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
    at br.com.dynavideo.AccessControlTest.authenticateUser(AccessControlTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

I also tried to set EJBContainer properties as provider, appname or module. But the same error occurs. Any ideas how to solve this problem? Thanks!

No correct solution

OTHER TIPS

Try this. Solved it for me (with a different approach):

<repositories>
    <repository>
        <id>maven.java.net</id>
        <name>Java.net Repository for Maven</name>
        <url>https://maven.java.net/content/groups/promoted/</url>
    </repository>
    <repository>
        <id>maven2-repository.dev.java.net</id>
       <name>Java.net Repository for Maven</name>
        <url>http://download.java.net/maven/glassfish/</url>
    </repository>
</repositories>

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>4.0.1-b02</version>
    <scope>test</scope>
</dependency>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top