2
votes

I have a number of test classes that are run using Arquillian (1.0.2.Final) using the 'arquillian-glassfish-embedded-3.1' container (1.0.0.CR3).

If I run any of the test classes in isolation they run as expected, if I attempt to run multiple test classes (TestSuite) I run into problems injecting EJB's into the classes.

java.lang.RuntimeException: Could not inject members

Caused by: java.lang.IllegalStateException: Exception attempting to inject Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager resolved to intra-app EJB PackageManagerBean in module test,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session into class com.dcp.transmission.TransmissionManagerBeanTest: Lookup failed for 'java:comp/env/PackageManagerBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager resolved to intra-app EJB PackageManagerBean in module test,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session into class com.dcp.transmission.TransmissionManagerBeanTest: Lookup failed for 'java:comp/env/PackageManagerBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/PackageManagerBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager resolved to intra-app EJB PackageManagerBean in module test,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'PackageManagerBean#com.dcp.pkg.PackageManager' [Root exception is javax.naming.NamingException: Lookup failed for 'PackageManagerBean#com.dcp.pkg.PackageManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.dcp.pkg.PackageManager [Root exception is java.lang.IllegalArgumentException: argument type mismatch]]]]

Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager resolved to intra-app EJB PackageManagerBean in module test,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session' . Actual (possibly internal) Remote JNDI name used for lookup is 'PackageManagerBean#com.dcp.pkg.PackageManager' [Root exception is javax.naming.NamingException: Lookup failed for 'PackageManagerBean#com.dcp.pkg.PackageManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.dcp.pkg.PackageManager [Root exception is java.lang.IllegalArgumentException: argument type mismatch]]]

Caused by: javax.naming.NamingException: Lookup failed for 'PackageManagerBean#com.dcp.pkg.PackageManager' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.dcp.pkg.PackageManager [Root exception is java.lang.IllegalArgumentException: argument type mismatch]]

Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.dcp.pkg.PackageManager [Root exception is java.lang.IllegalArgumentException: argument type mismatch]

Caused by: java.lang.IllegalArgumentException: argument type mismatch

The Package Manager Bean is defined as follows:

@Stateless(mappedName = "PackageManagerBean")
@Remote({ PackageManager.class })
@Local({ PackageManagerLocal.class })
public class PackageManagerBean implements PackageManager {

}

The Package Manager is injected into several of the test classes as per the example below:

@RunWith(Arquillian.class)
public class TransmissionManagerBeanTest {

      @Deployment
      public static Archive<?> createDeployment() {
                WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                                    .addPackages(true, TransmissionManager.class.getPackage(), Search.class.getPackage(), PackageManager.class.getPackage(), SiteManagerBean.class.getPackage())
                                    .addAsResource("test-persistence.xml", "META-INF/persistence.xml").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
                return war;
      }

  @EJB
  TransmissionManager transmissionManager;

  @EJB
  PackageManager packageManager;

  @EJB
  SiteManager siteManager;

  @PersistenceContext
  EntityManager entityManager;

  @Inject
  UserTransaction userTransaction;

}

I do not appear to be having problems with any of the other EJB's.

Does any one have any idea what the problem is and how I can get this working?

1
I'm not sure if this helps, but is there a reason why PackageManagerBean implements only the PackageManager remote interface? Any specific reason for omitting the local interface in the class declaration? Also, does this test work with the managed GF container (if yes, then it might be due to classpath issues)? - Vineet Reynolds
The tests do not currently work with either the managed or remote Glassfish container but for a completely different reason. The tests complain that one of the enums on my Entity bean is "not a valid type for a serialized mapping. The attribute type must implement the Serializable interface." even though the enum does implement Serializable. - lucasweb
I also see the following error: DeploymentContext does not contain any EJB. Check the archive to ensure correct packaging for /apps/glassfish3/glassfish/domains/domain1/applications/test. If you use EJB component annotations to define the EJB, and an ejb or web deployment descriptor is also used, please make sure that the deployment descriptor references a Java EE 5 or higher version schema, and that the metadata-complete attribute is not set to true, so the component annotations can be processed as expected. Please see server.log for more details. [status: CLIENT_ERROR reason: Bad Request] - lucasweb
I see this error for running a single class test! - Kalpesh Soni

1 Answers

4
votes

From what I can tell it appears to be an issue with cleaning up the resources deployed in the embedded Glassfish container between each test class. At this point I don't know if it is Arquillian, the embedded Glassfish container or my code that causes the problem.

I have found a workaround. By running in each test class in it's own JVM I avoid the issues above. It does add som additional overhead e.g. instead of re-using the embedded container for all of the test classes the container get's torn down and re-started for each test class but it does allow me to run all of my unit tests in one go.

I use maven to run the tests and use the following maven-surefire-plugin configuration to ensure each test class is run in it's own JVM:

<configuration><forkCount>1</forkCount><reuseForks>false</reuseForks>....</configuration>

For versions of maven-surefire-plugin older than 2.14 you can use forkMode=false