4 Replies Latest reply on May 13, 2011 3:16 AM by jaikiran pai

    Is it possible to test StatefulSessionBeans with Arquillian?!

    Markus Welser Newbie

      Hi,

      i can run Arquillian tests with Stateless Session Beans but is it also possible to Inject stateful sessions beans in an arquillian test?!

       

      is what i get after trying to inject a SFSB into an Arquillian Test!

      java.lang.RuntimeException: It is illegal to inject an EXTENDED PC into something other than a SFSB

       

      thx

        • 1. Is it possible to test StatefulSessionBeans with Arquillian?!
          Aslak Knutsen Master

          The lookup code should be the same, so yes. But you will get a new SFSB pr @Test method. We currently can't keep the state.

           

          As to your specific exception, i would need to see some code. TestClass, Deployment and SFSB

          • 2. Re: Is it possible to test StatefulSessionBeans with Arquillian?!
            Markus Welser Newbie

            THX !

            Deployed on a JBoss 6.0 AS

            ------------------------THE TEST CLASS------------------------------------------

            @RunWith(Arquillian.class)

            public class TestRules {

             

                @EJB

                VehicleService vs;

             

                @Deployment(testable = true, managed = true)

                public static Archive<?> createDeployment() {

                    return ShrinkWrap

                            .create(JavaArchive.class, "rulestest.jar")

                            .addPackage("com/hji/hibernate/types")

                            .addPackage("com/hji/hibernate/idgen")

                            .addPackage("com/hji/hibernate/idgen/as400")

                            .addPackage("com/hji/as400/db")

                            .addPackage("com/hji/as400")

                            .addPackage("com/hji/utils")

                            .addPackage("com/hji/utils/lang")

                            .addPackage("com/hji/common/domain")

                            .addPackage("com/hji/common/domain/masterdata")

                            .addClasses(LogUtils.class, Logger.class, StaleStateException.class,

                                    HibernatePersistenceEx.class, EntityBase.class, ManagedEntity.class,

                                    Repository.class, ClaimPK.class, ResultHandler.class, RuleEngine.class,

                                    RuleEngineRemote.class, SupplyInfo.class, VehicleEntryData.class,

                                    History.class, ReEntryVehicleEntryData.class, HistoryPK.class,

                                    History.class, HistoryState.class, VehicleService.class,

                                    VehicleServiceBean.class, DomainService.class, DomainServiceBean.class,

                                    VehicleRepository.class, Aviso.class, Compound.class, Location.class,

                                    AvisoRepository.class, VehicleNote.class)

                            .addAsManifestResource("test-persistence.xml", "persistence.xml")

                            .addAsManifestResource("beans.xml")

                            .addAsResource("test-as400.properties", "as400.properties");

                }

             

                @Test

                public void testRules() {

                }

            }

             

            --------------------------------VehicleServiceBean-------------------------------------------------

             

            @Stateful

            @SerializedConcurrentAccess

            public class VehicleServiceBean extends DomainServiceBean<Vehicle> implements VehicleService {

             

                private VehicleRepository repository;

                private AvisoRepository avisoRepository;

             

                @PostConstruct

                public void init() {

                    repository = new VehicleRepository(em);

                    avisoRepository = new AvisoRepository(em);

                }

             

                @Override

                public Class<Vehicle> getDomainClass() {

                    return Vehicle.class;

                }

             

                /**

                 * {@inheritDoc}

                 */

                @Override

                public List<Vehicle> findBy(FindBy findBy, String what) {

                    if (what == null)

                        throw new IllegalArgumentException("what is null");

                    List<Vehicle> result = new ArrayList<Vehicle>();

                    Vehicle vehicle = null;

                    switch (findBy) {

                    case Vin:

                        vehicle = repository.findByVin(what);

                        if (vehicle != null)

                            result.add(vehicle);

                        return result;

                    case Last6OfVin:

                        return repository.findByLast6OfVin(what);

                    case EntryNr:

                        vehicle = repository.findByEntryNr(NumberUtils.safeParseLong(what));

                        if (vehicle != null)

                            result.add(vehicle);

                        return result;

                    case OrderNr:

                        return repository.findByOrderNr(what);

                    case JobNr:

                        return findByJobNr(what);

                    case IdentNr:

                        return repository.findByIdentNr(NumberUtils.safeParseLong(what));

                    }

                    throw new RuntimeException("unhandled case in VehicleRepository.findBy");

                }

            }

            -----------------------------DomainServiceBean------------------------------------------

            public abstract class DomainServiceBean<E extends ManagedEntity<?>> implements DomainService<E> {

             

                private static final long serialVersionUID = 1L;

             

                @PersistenceContext(type = PersistenceContextType.EXTENDED)

                protected EntityManager em;

             

                private transient Logger log;

             

                @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

                public E find(Object id) {

                    if (id == null)

                        return null;

                    return em.find(getDomainClass(), id);

                }

             

                public E createNew() {

                    try {

                        return getDomainClass().newInstance();

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                    return null;

                }

             

                public E save(E entity) throws StaleStateException {

                    if (entity == null)

                        throw new IllegalArgumentException("entity is null");

                    return Entity.save(em, entity);

                }

             

                public boolean delete(E entity) {

                    if (entity == null)

                        throw new IllegalArgumentException("entity is null");

                    return Entity.delete(em, entity);

                }

             

                @Remove

                public void remove() {

                }

             

                private synchronized Logger log() {

                    if (log == null) {

                        log = Logger.getLogger(getClass());

                    }

                    return log;

                }

             

                protected final void debug(String msg, Object... args) {

                    log().debug(MessageFormat.format(msg, args));

                }

             

                protected final void error(String msg, Object... args) {

                    log().error(MessageFormat.format(msg, args));

                }

             

                protected final void error(String msg, Throwable t, Object... args) {

                    log().error(MessageFormat.format(msg, args), t);

                }

             

                public boolean refresh(E entity) {

                    if (entity == null)

                        throw new IllegalArgumentException("entity is null");

             

                    if (em.contains(entity)) {

                        em.refresh(entity);

                        return true;

                    } else

                        return false;

                }

            }

            --------------------------THE EXCEPTION i GET ----------------------------------

            13:36:52,215 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

             

                VehicleServiceBean/local - EJB3.x Default Local Business Interface

                VehicleServiceBean/local-com.hji.common.service.VehicleService - EJB3.x Local Business Interface

             

            13:36:52,216 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:jar=test.war,name=RuleEngine,service=EJB3

            13:36:52,216 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: com.hji.rules.RuleEngine ejbName: RuleEngine

            13:36:52,220 INFO  [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/test

            13:36:52,234 ERROR [org.jboss.web.tomcat.service.deployers.TomcatDeployment] ENC setup failed: java.lang.RuntimeException: It is illegal to inject an EXTENDED PC into something other than a SFSB

                at org.jboss.injection.PcEncInjector.inject(PcEncInjector.java:90) [:1.7.17]

                at org.jboss.web.tomcat.service.TomcatInjectionContainer.populateEnc(TomcatInjectionContainer.java:528) [:6.0.0.Final]

                at org.jboss.web.tomcat.service.deployers.TomcatDeployment$EncListener.lifecycleEvent(TomcatDeployment.java:431) [:6.0.0.Final]

                at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:115) [:6.0.0.Final]

                at org.apache.catalina.core.StandardContext.start(StandardContext.java:3823) [:6.0.0.Final]

                at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:294) [:6.0.0.Final]

                at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:146) [:6.0.0.Final]

                at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:477) [:6.0.0.Final]

                at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118) [:6.0.0.Final]

                at org.jboss.web.deployers.WebModule.start(WebModule.java:95) [:6.0.0.Final]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_21]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_21]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_21]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_21]

                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157) [:6.0.0.GA]

                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96) [:6.0.0.GA]

                at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) [:6.0.0.GA]

                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:271) [:6.0.0.GA]

                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:670) [:6.0.0.GA]

                at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206) [:2.2.0.GA]

                at $Proxy41.start(Unknown Source)    at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:53) [:2.2.0.GA]

                at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:41) [:2.2.0.GA]

                at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:301) [:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:894) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:641) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:103) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar.install(Ejb3McRegistrar.java:394) [:1.0.2]

                at org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar.bind(Ejb3McRegistrar.java:245) [:1.0.2]

                at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.registerProxyFactory(JndiSessionRegistrarBase.java:1169) [:1.0.11]

                at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.createJndiReferenceBindingSet(JndiSessionRegistrarBase.java:510) [:1.0.11]

                at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.bindEjb(JndiSessionRegistrarBase.java:156) [:1.0.11]

                at org.jboss.ejb3.session.SessionContainer.lockedStart(SessionContainer.java:223) [:1.7.17]

                at org.jboss.ejb3.session.SessionSpecContainer.lockedStart(SessionSpecContainer.java:725) [:1.7.17]

                at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:1105) [:1.7.17]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_21]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_21]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_21]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_21]

                at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:60) [jboss-reflect.jar:2.2.0.GA]

                at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:168) [jboss-reflect.jar:2.2.0.GA]

                at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66) [jboss-reflect.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:257) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:125) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:72) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:202) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) [jboss-kernel.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983) [:2.2.0.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076) [:2.2.0.GA]

                at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.0.GA]

                at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106) [:6.0.0.Final]

                at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:143) [:0.2.2]

                at org.jboss.profileservice.plugins.deploy.actions.DeploymentStartAction.doPrepare(DeploymentStartAction.java:98) [:0.2.2]

                at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.prepare(AbstractTwoPhaseModificationAction.java:101) [:0.2.2]

                at org.jboss.profileservice.management.ModificationSession.prepare(ModificationSession.java:87) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.internalPerfom(AbstractActionController.java:234) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.performWrite(AbstractActionController.java:213) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.perform(AbstractActionController.java:150) [:0.2.2]

                at org.jboss.profileservice.plugins.deploy.AbstractDeployHandler.startDeployments(AbstractDeployHandler.java:168) [:0.2.2]

                at org.jboss.profileservice.management.upload.remoting.DeployHandlerDelegate.startDeployments(DeployHandlerDelegate.java:74) [:6.0.0.Final]

                at org.jboss.profileservice.management.upload.remoting.DeployHandler.invoke(DeployHandler.java:156) [:6.0.0.Final]

                at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:898) [:6.0.0.Final]

                at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:791) [:6.0.0.Final]

                at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:744) [:6.0.0.Final]

                at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:548) [:6.0.0.Final]

                at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:234) [:6.0.0.Final]

            • 3. Re: Is it possible to test StatefulSessionBeans with Arquillian?!
              jaikiran pai Master

              This is actually a bug in JBoss AS 6.0.0.Final and is being tracked in https://issues.jboss.org/browse/JBAS-8318. It will be fixed in JBoss AS 6.1.0. In the meantime, you can workaround the issue by moving the @PersistenceContext injection from the base class to the @Stateful bean implementation class.

              • 4. Re: Is it possible to test StatefulSessionBeans with Arquillian?!
                jaikiran pai Master

                jaikiran pai wrote:

                 

                This is actually a bug in JBoss AS 6.0.0.Final and is being tracked in https://issues.jboss.org/browse/JBAS-8318.

                The latest AS6 trunk has a fix for this now https://issues.jboss.org/browse/JBAS-8318?focusedCommentId=12601825&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12601825. If you want to give it a try, follow the thread referenced in that latest JIRA comment.