11 Replies Latest reply: Sep 16, 2010 5:21 AM by Stephan B RSS

    Using OpenEJB for integration testing

    Stephan B Newbie

      Hi,


      I'm wondering if anyone tried and succeeded using OpenEJB (or even Glassfish) for integration testing instead of JBoss Embedded (didn't work out for me). I found an interesting post in the AndroMDA forum, but it's quite old. I tried applying the code from it. I managed to use Component.getInstance(..) successfully, however, when it came to JPA/DB related things it would crash:


      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: userDAO.em



      Looking at the log, no JPA/Hibernate stuff is initialized. I'm not sure why, a persistence.xml and the appropriate Hibernate JARs are on the classpath. Weird.


      Suggestions welcome!


      PS: If anybody is interested in the code that got me so far, just tell me and I can post it (simply saves the time of fitting the several .diff's at AndroMDA together).


      Cheers,
      Stephan

        • 1. Re: Using OpenEJB for integration testing
          joerg doneit Newbie

          Hi,


          I am also trying to use OpenEJB for testing Seam Components. I would be glad if you could post your code.


          doneit

          • 2. Re: Using OpenEJB for integration testing
            Stephan B Newbie

            Sure. Most part of the code is from the post in the above mentioned AndroMDA forum. I haven't worked on it for a while so meanwhile I get a new Exception (must be because of update to 2.1.1): java.lang.UnsupportedOperationException: no transaction.
            I haven't the slightest idea why it doesn't apparently pick up my persistence.xml (see console log at the bottom).


            I have no clue about the stuff behind the scenes so I wasn't able to figure it out on my own (and yet the community didn't seem to be interested in it)...



            The pom entries:


                    <dependency>
                        <groupId>org.apache.openejb</groupId>
                        <artifactId>openejb-core</artifactId>
                        <version>3.0</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.apache.openjpa</groupId>
                                <artifactId>openjpa</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>hsqldb</groupId>
                                <artifactId>hsqldb</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>junit</groupId>
                                <artifactId>junit</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
            
                    <dependency>
                        <groupId>org.jboss.logging</groupId>
                        <artifactId>jboss-logging-spi</artifactId>
                        <version>2.0.5.GA</version>
                    </dependency>



            The base class:



            public class ContainerEnvironment
                    extends AbstractSeamTest {
            
                private static boolean started = false;
            
                private static InitialContext initialContext = null;
            
                private static InitialContext securedInitialContext = null;
            
                /**
                 * ********* Setup ***********
                 */
                @BeforeSuite
                // needs a WEB-INF/web.xml in resources!!!
                public void beforeSuite () throws Exception {
                    startSeam ();
                }
            
                @BeforeClass
                public void beforeClass () throws Exception {
                    setupClass ();
                }
            
                @BeforeMethod
                @Override
                public void begin () {
                    super.begin ();
                    //TestLifecycle.beginTest (servletContext, new ServletSessionMap (getSession ()));
                }
            
                @AfterMethod
                @Override
                public void end () {
                    //TestLifecycle.endTest ();
                    super.end ();
                }
            
                @AfterClass
                public void afterClass () throws Exception {
                    cleanupClass ();
                }
            
                @AfterSuite
                public void afterSuite () throws Exception {
                    stopSeam ();
                }
            
                /**
                 * ********* Methods ***********
                 */
            
                @Override
                protected void startJbossEmbeddedIfNecessary ()
                        throws Exception {
            
                    if (!started && openEjbAvailable ()) {
                        new OpenEjbBootstrap ().startAndDeployResources ();
                    }
                    started = true;
                }
            
                private boolean openEjbAvailable () {
            
                    try {
                        Class.forName ("org.apache.openejb.OpenEJB");
                        return true;
                    } catch (ClassNotFoundException e) {
                        return false;
                    }
                }
            
                @Override
                protected InitialContext getInitialContext ()
                        throws NamingException {
            
                    return getStaticInitialContext ();
                }
            
                public static InitialContext getStaticInitialContext ()
                        throws NamingException {
            
                    if (initialContext == null) {
                        loadInitialContext ();
                    }
                    return initialContext;
                }
            
                /**
                 * Return a new InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory,
                 * setting the the default context.
                 *
                 * @return javax.naming.InitialContext
                 * @throws Exception
                 */
                public InitialContext newInitialContext ()
                        throws Exception {
            
                    final Hashtable<String, String> props = getInitialContextProperties ();
                    initialContext = new InitialContext (props);
                    return initialContext;
                }
            
                /**
                 * Return a new InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory,
                 * setting the default context. Use the specified username and password to set the security context.
                 *
                 * @param pPrincipal
                 * @param credential
                 * @return javax.naming.InitialContext
                 * @throws Exception
                 */
                public InitialContext newInitialContext (final String pPrincipal,
                                                         final String pCredential)
                        throws Exception {
            
                    final Hashtable<String, String> props =
                            getInitialContextProperties (pPrincipal, pCredential);
                    securedInitialContext = new InitialContext (props);
                    return securedInitialContext;
                }
            
                /**
                 * Return the default InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory
                 * if one is already instantiated, otherwise create a new InitialContext and set as the default.
                 *
                 * @return javax.naming.InitialContext
                 * @throws javax.naming.NamingException
                 */
                public static InitialContext loadInitialContext ()
                        throws NamingException {
            
                    if (initialContext == null) {
                        final Hashtable props = getInitialContextProperties ();
            
            //            URL config = this.getClass ().getClassLoader ().getResource ("openejb.xml");
            //            props.put ("openejb.configuration", config.toExternalForm ());
            
                        initialContext = new InitialContext (props);
                    }
                    return initialContext;
                }
            
                /**
                 * Return the default InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory
                 * if one is already instantiated, otherwise create a new InitialContext and set as the default.
                 * Use the specified username and password to set the security context.
                 *
                 * @param pPrincipal
                 * @param pCredential
                 * @return
                 * @throws javax.naming.NamingException
                 */
                public InitialContext loadInitialContext (final String pPrincipal,
                                                          final String pCredential)
                        throws NamingException {
            
                    if (securedInitialContext == null) {
                        final Hashtable<String, String> props =
                                getInitialContextProperties (pPrincipal, pCredential);
                        securedInitialContext = new InitialContext (props);
                    }
                    return securedInitialContext;
                }
            
                private static Hashtable<String, String> getInitialContextProperties () {
            
                    final Hashtable<String, String> props = new Hashtable<String, String> (1);
                    props.put (Context.INITIAL_CONTEXT_FACTORY,
                               "org.apache.openejb.client.LocalInitialContextFactory");
                    return props;
                }
            
                private Hashtable<String, String> getInitialContextProperties (final String pPrincipal,
                                                                               final String pCredential) {
            
                    final Hashtable<String, String> props = new Hashtable<String, String> (2);
                    props.put (Context.INITIAL_CONTEXT_FACTORY,
                               "org.apache.openejb.client.LocalInitialContextFactory");
                    props.put (Context.SECURITY_PRINCIPAL, pPrincipal);
                    props.put (Context.SECURITY_CREDENTIALS, pCredential);
                    return props;
                }



            The test class:



            public class FunctionalTesting
                    extends ContainerEnvironment {
            
                public void test () throws Exception {
            
                    new ComponentTest() {
            
                        @Override
                        protected void testComponents () throws Exception {
            
                            final Identity identity = (Identity) Component.getInstance (Identity.class);
                            assert identity != null;
                        }
                    }.run ();
                }



            and finally my current console log:



            Apache OpenEJB 3.0    build: 20080408-04:13
            http://openejb.apache.org/
            INFO - openejb.home = /home/stephan/dev/workspace/vilea.author.portal.lib
            INFO - openejb.base = /home/stephan/dev/workspace/vilea.author.portal.lib/src/test/resources
            INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
            INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
            INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory, type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
            INFO - Namespace: http://jboss.com/products/seam/framework, package: org.jboss.seam.framework, prefix: org.jboss.seam.core.framework
            INFO - Namespace: http://jboss.com/products/seam/async, package: org.jboss.seam.async, prefix: org.jboss.seam.async
            INFO - Namespace: http://jboss.com/products/seam/theme, package: org.jboss.seam.theme, prefix: org.jboss.seam.theme
            INFO - Namespace: http://jboss.com/products/seam/security, package: org.jboss.seam.security.management, prefix: org.jboss.seam.security
            INFO - Namespace: http://jboss.com/products/seam/mail, package: org.jboss.seam.mail, prefix: org.jboss.seam.mail
            INFO - Namespace: http://jboss.com/products/seam/bpm, package: org.jboss.seam.bpm, prefix: org.jboss.seam.bpm
            INFO - Namespace: http://jboss.com/products/seam/security, package: org.jboss.seam.security, prefix: org.jboss.seam.security
            INFO - Namespace: http://jboss.com/products/seam/web, package: org.jboss.seam.web, prefix: org.jboss.seam.web
            INFO - Namespace: http://jboss.com/products/seam/captcha, package: org.jboss.seam.captcha, prefix: org.jboss.seam.captcha
            INFO - Namespace: http://jboss.com/products/seam/navigation, package: org.jboss.seam.navigation, prefix: org.jboss.seam.navigation
            INFO - Namespace: http://jboss.com/products/seam/resteasy, package: org.jboss.seam.resteasy, prefix: 
            INFO - Namespace: http://jboss.com/products/seam/core, package: org.jboss.seam.core, prefix: org.jboss.seam.core
            INFO - Namespace: http://jboss.com/products/seam/international, package: org.jboss.seam.international, prefix: org.jboss.seam.international
            INFO - Namespace: http://jboss.com/products/seam/cache, package: org.jboss.seam.cache, prefix: org.jboss.seam.cache
            INFO - Namespace: http://jboss.com/products/seam/jms, package: org.jboss.seam.jms, prefix: org.jboss.seam.jms
            INFO - Namespace: http://jboss.com/products/seam/ui, package: org.jboss.seam.ui, prefix: org.jboss.seam.ui
            INFO - Namespace: http://jboss.com/products/seam/transaction, package: org.jboss.seam.transaction, prefix: org.jboss.seam.transaction
            INFO - Namespace: http://jboss.com/products/seam/security, package: org.jboss.seam.security.permission, prefix: org.jboss.seam.security
            INFO - Namespace: http://jboss.com/products/seam/drools, package: org.jboss.seam.drools, prefix: org.jboss.seam.drools
            INFO - Namespace: http://jboss.com/products/seam/persistence, package: org.jboss.seam.persistence, prefix: org.jboss.seam.persistence
            INFO - Namespace: http://jboss.com/products/seam/document, package: org.jboss.seam.document, prefix: org.jboss.seam.document
            INFO - reading properties from: /seam.properties
            INFO - reading properties from: /jndi.properties
            INFO - initializing Seam
            INFO - Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init
            INFO - two components with same name, higher precedence wins: org.jboss.seam.web.parameters
            INFO - two components with same name, higher precedence wins: userActivationService
            INFO - two components with same name, higher precedence wins: org.jboss.seam.persistence.persistenceProvider
            INFO - two components with same name, higher precedence wins: org.jboss.seam.captcha.captcha
            INFO - two components with same name, higher precedence wins: org.jboss.seam.transaction.synchronizations
            INFO - two components with same name, higher precedence wins: org.jboss.seam.web.isUserInRole
            INFO - two components with same name, higher precedence wins: org.jboss.seam.core.resourceLoader
            INFO - two components with same name, higher precedence wins: org.jboss.seam.web.userPrincipal
            INFO - two components with same name, higher precedence wins: org.jboss.seam.core.manager
            INFO - two components with same name, higher precedence wins: org.jboss.seam.core.locale
            INFO - two components with same name, higher precedence wins: org.jboss.seam.core.expressions
            INFO - two components with same name, higher precedence wins: org.jboss.seam.core.locale
            INFO - Installing components...
            [...my stuff...]
            INFO - Component: org.jboss.seam.async.asynchronousExceptionHandler, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.async.AsynchronousExceptionHandler
            INFO - Component: org.jboss.seam.async.dispatcher, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.async.ThreadPoolDispatcher
            INFO - Component: org.jboss.seam.captcha.captcha, scope: SESSION, type: JAVA_BEAN, class: com.sunshock.portal.action.AdvancedCaptcha
            INFO - Component: org.jboss.seam.captcha.captchaImage, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.captcha.CaptchaImage
            INFO - Component: org.jboss.seam.core.ConversationIdGenerator, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationIdGenerator
            INFO - Component: org.jboss.seam.core.contexts, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.core.Contexts
            INFO - Component: org.jboss.seam.core.conversation, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.Conversation
            INFO - Component: org.jboss.seam.core.conversationEntries, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationEntries
            INFO - Component: org.jboss.seam.core.conversationListFactory, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationList
            INFO - Component: org.jboss.seam.core.conversationPropagation, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationPropagation
            INFO - Component: org.jboss.seam.core.conversationStackFactory, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.core.ConversationStack
            INFO - Component: org.jboss.seam.core.events, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.core.Events
            INFO - Component: org.jboss.seam.core.expressions, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.faces.FacesExpressions
            INFO - Component: org.jboss.seam.core.interpolator, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.core.Interpolator
            INFO - Component: org.jboss.seam.core.locale, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.international.Locale
            INFO - Component: org.jboss.seam.core.manager, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.faces.FacesManager
            INFO - Component: org.jboss.seam.core.resourceBundle, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.core.ResourceBundle
            INFO - Component: org.jboss.seam.core.resourceLoader, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.faces.ResourceLoader
            INFO - Component: org.jboss.seam.core.validators, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Validators
            INFO - Component: org.jboss.seam.document.documentStore, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.document.DocumentStore
            INFO - Component: org.jboss.seam.exception.exceptions, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.exception.Exceptions
            INFO - Component: org.jboss.seam.faces.dataModels, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.faces.DataModels
            INFO - Component: org.jboss.seam.faces.facesContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.faces.FacesContext
            INFO - Component: org.jboss.seam.faces.facesPage, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.faces.FacesPage
            INFO - Component: org.jboss.seam.faces.httpError, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.faces.HttpError
            INFO - Component: org.jboss.seam.faces.redirect, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.faces.Redirect
            INFO - Component: org.jboss.seam.faces.renderer, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.FaceletsRenderer
            INFO - Component: org.jboss.seam.faces.switcher, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.faces.Switcher
            INFO - Component: org.jboss.seam.faces.uiComponent, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.faces.UiComponent
            INFO - Component: org.jboss.seam.faces.validation, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.faces.Validation
            INFO - Component: org.jboss.seam.framework.currentDate, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.framework.CurrentDate
            INFO - Component: org.jboss.seam.framework.currentDatetime, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.framework.CurrentDatetime
            INFO - Component: org.jboss.seam.framework.currentTime, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.framework.CurrentTime
            INFO - Component: org.jboss.seam.graphicImage.image, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.ui.graphicImage.Image
            INFO - Component: org.jboss.seam.international.localeSelector, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.international.LocaleSelector
            INFO - Component: org.jboss.seam.international.messagesFactory, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.international.Messages
            INFO - Component: org.jboss.seam.international.statusMessages, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.faces.FacesMessages
            INFO - Component: org.jboss.seam.international.timeZone, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.international.TimeZone
            INFO - Component: org.jboss.seam.international.timeZoneSelector, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.international.TimeZoneSelector
            INFO - Component: org.jboss.seam.mail.mailSession, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.mail.MailSession
            INFO - Component: org.jboss.seam.navigation.pages, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.navigation.Pages
            INFO - Component: org.jboss.seam.navigation.safeActions, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.navigation.SafeActions
            INFO - Component: org.jboss.seam.persistence.persistenceContexts, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.persistence.PersistenceContexts
            INFO - Component: org.jboss.seam.persistence.persistenceProvider, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.persistence.HibernatePersistenceProvider
            INFO - Component: org.jboss.seam.resteasy.applicationConfig, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.resteasy.ApplicationConfig
            INFO - Component: org.jboss.seam.resteasy.bootstrap, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.resteasy.ResteasyBootstrap
            INFO - Component: org.jboss.seam.resteasy.dispatcher, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.resteasy.ResteasyDispatcher
            INFO - Component: org.jboss.seam.resteasy.resourceAdapter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.resteasy.ResteasyResourceAdapter
            INFO - Component: org.jboss.seam.security.configurationFactory, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.security.Configuration
            INFO - Component: org.jboss.seam.security.credentials, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.security.Credentials
            INFO - Component: org.jboss.seam.security.entityPermissionChecker, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.EntityPermissionChecker
            INFO - Component: org.jboss.seam.security.facesSecurityEvents, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.FacesSecurityEvents
            INFO - Component: org.jboss.seam.security.identifierPolicy, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.permission.IdentifierPolicy
            INFO - Component: org.jboss.seam.security.identity, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.security.Identity
            INFO - Component: org.jboss.seam.security.identityManager, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.security.management.IdentityManager
            INFO - Component: org.jboss.seam.security.management.roleAction, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.security.management.action.RoleAction
            INFO - Component: org.jboss.seam.security.management.roleSearch, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.security.management.action.RoleSearch
            INFO - Component: org.jboss.seam.security.management.userAction, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.security.management.action.UserAction
            INFO - Component: org.jboss.seam.security.management.userSearch, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.security.management.action.UserSearch
            INFO - Component: org.jboss.seam.security.passwordHash, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.security.management.PasswordHash
            INFO - Component: org.jboss.seam.security.permission.permissionSearch, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.security.permission.action.PermissionSearch
            INFO - Component: org.jboss.seam.security.permissionManager, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.permission.PermissionManager
            INFO - Component: org.jboss.seam.security.permissionMapper, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.permission.PermissionMapper
            INFO - Component: org.jboss.seam.security.persistentPermissionResolver, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.security.permission.PersistentPermissionResolver
            INFO - Component: org.jboss.seam.security.rememberMe, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.security.RememberMe
            INFO - Component: org.jboss.seam.theme.themeFactory, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.theme.Theme
            INFO - Component: org.jboss.seam.theme.themeSelector, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.theme.ThemeSelector
            INFO - Component: org.jboss.seam.transaction.synchronizations, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.transaction.SeSynchronizations
            INFO - Component: org.jboss.seam.transaction.transaction, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.transaction.Transaction
            INFO - Component: org.jboss.seam.transaction.transaction2, scope: EVENT, type: JAVA_BEAN, class: com.sunshock.portal.test.container.MockTransaction
            INFO - Component: org.jboss.seam.ui.EntityConverter, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.ui.EntityConverter
            INFO - Component: org.jboss.seam.ui.entityIdentifierStore, scope: PAGE, type: JAVA_BEAN, class: org.jboss.seam.ui.EntityIdentifierStore
            INFO - Component: org.jboss.seam.ui.entityLoader, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.ui.JpaEntityLoader
            INFO - Component: org.jboss.seam.ui.facelet.faceletCompiler, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.FaceletCompiler
            INFO - Component: org.jboss.seam.ui.facelet.faceletsJBossLogging, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.FaceletsJBossLogging
            INFO - Component: org.jboss.seam.ui.facelet.facesContextFactory, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.RendererFacesContextFactory
            INFO - Component: org.jboss.seam.ui.facelet.mockHttpSession, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.HttpSessionManager
            INFO - Component: org.jboss.seam.ui.facelet.mockServletContext, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.facelet.ServletContextManager
            INFO - Component: org.jboss.seam.ui.graphicImage.graphicImageResource, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.graphicImage.GraphicImageResource
            INFO - Component: org.jboss.seam.ui.graphicImage.graphicImageStore, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.ui.graphicImage.GraphicImageStore
            INFO - Component: org.jboss.seam.ui.resource.webResource, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.ui.resource.WebResource
            INFO - Component: org.jboss.seam.web.ajax4jsfFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.Ajax4jsfFilter
            INFO - Component: org.jboss.seam.web.ajax4jsfFilterInstantiator, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.ui.filter.Ajax4jsfFilterInstantiator
            INFO - Component: org.jboss.seam.web.exceptionFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.ExceptionFilter
            INFO - Component: org.jboss.seam.web.identityFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.IdentityFilter
            INFO - Component: org.jboss.seam.web.isUserInRole, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.faces.IsUserInRole
            INFO - Component: org.jboss.seam.web.loggingFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.LoggingFilter
            INFO - Component: org.jboss.seam.web.multipartFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.MultipartFilter
            INFO - Component: org.jboss.seam.web.parameters, scope: STATELESS, type: JAVA_BEAN, class: org.jboss.seam.faces.Parameters
            INFO - Component: org.jboss.seam.web.redirectFilter, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.web.RedirectFilter
            INFO - Component: org.jboss.seam.web.servletContexts, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.web.ServletContexts
            INFO - Component: org.jboss.seam.web.session, scope: SESSION, type: JAVA_BEAN, class: org.jboss.seam.web.Session
            INFO - Component: org.jboss.seam.web.userPrincipal, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.faces.UserPrinciple
            [.. my stuff ..]
            INFO - starting up: org.jboss.seam.security.persistentPermissionResolver
            WARN - no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required.
            INFO - starting up: org.jboss.seam.security.permissionMapper
            INFO - starting up: org.jboss.seam.navigation.pages
            INFO - no pages.xml file found: /WEB-INF/pages.xml
            INFO - starting up: org.jboss.seam.ui.facelet.faceletsJBossLogging
            INFO - starting up: org.jboss.seam.security.entityPermissionChecker
            INFO - starting up: org.jboss.seam.resteasy.bootstrap
            INFO - deploying Resteasy providers and resources
            INFO - starting up: org.jboss.seam.resteasy.dispatcher
            INFO - registering built-in RESTEasy providers
            INFO - starting up: org.jboss.seam.security.facesSecurityEvents
            FAILED CONFIGURATION: @BeforeSuite beforeSuite
            java.lang.UnsupportedOperationException: no transaction
                 at org.jboss.seam.transaction.NoTransaction.begin(NoTransaction.java:36)
                 at org.jboss.seam.util.Work.workInTransaction(Work.java:42)
                 at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                 at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                 at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                 at com.sunshock.vilea.author.action.init.DatabasePreparation_$$_javassist_6.init(DatabasePreparation_$$_javassist_6.java)
                 at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                 at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
                 at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
                 at org.jboss.seam.core.Events.raiseEvent(Events.java:85)
                 at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:114)
                 at org.jboss.seam.init.Initialization.init(Initialization.java:735)
                 at com.sunshock.portal.test.container.ContainerEnvironment.startSeam(ContainerEnvironment.java:78)
                 at com.sunshock.portal.test.container.ContainerEnvironment.beforeSuite(ContainerEnvironment.java:36)
                 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
            ... Removed 23 stack frames


            • 3. Re: Using OpenEJB for integration testing
              Olivier Thierry Apprentice

              The post you found on AndroMDA forum was mine ;)


              Well it looks like I changed nothing to the ContainerEnvironment class you use as base class for your tests. It still works for me with Seam 2.1.1.GA (but not with 2.1.2.CR1 as you could see in an other post).


              Anyway I don't have the exception you encounter with transactions. But this may be due to the fact I use EJB transactions because all my Seam components are EJB3 session beans (AndroMDA default cartrdige builds EJB3 Seam components, not POJO ones). Is it your case ? Do you use POJO Seam components or EJB3 Seam components ?


              Note I tried to unit test POJO Seam components with OpenEJB a few weeks ago. So I had to use Seam managed persistence contexts, but I couldn't make it work with Open EJB and I finally gave up ... I might have had the same no transaction exception you have, but I am not sure, I don't remember very well ...

              • 4. Re: Using OpenEJB for integration testing
                Stephan B Newbie

                I thought that name was familiar :-)


                Good advice on the transaction issue, thanks! I'll try that, I'm in fact using POJO components.
                Would be great if it works out.


                I'm only surprised by the lack of interest of other users in this topic because honestly I simply can't get JBoss Embedded working with my setup (maven etc.).


                Cheers,
                Stephan

                • 5. Re: Using OpenEJB for integration testing
                  Olivier Thierry Apprentice

                  Stephan B wrote on Apr 19, 2009 13:20:


                  I'm only surprised by the lack of interest of other users in this topic because honestly I simply can't get JBoss Embedded working with my setup (maven etc.).


                  I could make it work with JBoss embedded, but I encountered problems because my EJB3 session beans are generated by AndroMDA in two parts : a base class that is generated from UML model and an implementation class that is generated once. For what I remember, JBoss embedded had problems finding annotations in such classes. So I decided to use OpenEJB instead and it worked much better ;) Moreover JBoss embedded is not fully EJB3 compliant, so I think it would be a good thing if Seam gave the choice to use the EJB3 embedded container you want to run unit tests instead of imposing JBOss embedded.


                  I would like to use POJO Seam components too, so I will investigate further about how to test them with Open EJB. But I have not a lot of time for this for the moment :(

                  • 6. Re: Using OpenEJB for integration testing
                    lucio piccoli Newbie

                    what is the state of openEJB and seam2.2.0GA?


                    is there is active usage or is jboss embedded the only container that works with seam?


                    -lp

                    • 7. Re: Using OpenEJB for integration testing
                      Stephan B Newbie

                      Actually I made it work.


                      Here are the necessary files:


                      public class ContainerWhiteBoxTest
                              extends BootstrapEnvironment {
                      
                          /**
                           * ********* Methods ***********
                           */
                      
                          protected static <T> T getContextComponent (final Class<T> pClass) {
                      
                              return (T) Component.getInstance (pClass);
                          }
                      
                          protected static <T> T getContextComponent (final String pName) {
                      
                              return (T) Component.getInstance (pName);
                          }
                      
                          protected static <T> T getContextComponent (final String pName,
                                                                      final ScopeType pScope) {
                      
                              return (T) Component.getInstance (pName, pScope);
                          }
                      
                          /**
                           * Call a method binding
                           */
                          protected Object invokeMethod (final String pMethodExpression) {
                      
                              return Expressions.instance ().createMethodExpression (pMethodExpression).invoke ();
                          }
                      
                          /**
                           * Evaluate (get) a value binding
                           */
                          protected Object getValue (final String pValueExpression) {
                      
                              return Expressions.instance ().createValueExpression (pValueExpression).getValue ();
                          }
                      
                          /**
                           * Set a value binding
                           */
                          protected void setValue (final String pValueExpression,
                                                   final Object pValue) {
                      
                              Expressions.instance ().createValueExpression (pValueExpression).setValue (pValue);
                          }
                      
                          /**
                           * ********* Database Component Test Class ***********
                           */
                      
                          public abstract class DBComponentTest
                                  extends ComponentTest {
                      
                              /**
                               * ********* Fields ***********
                               */
                      
                              private EntityTransaction transaction;
                      
                              private EntityManager em;
                      
                              /**
                               * ********* Setup ***********
                               */
                      
                              @Override
                              public void run () throws Exception {
                      
                                  super.run ();
                                  cleanEM ();
                              }
                      
                              @Override
                              protected final void testComponents () throws Exception {
                                  initEM ();
                                  testDBComponents ();
                              }
                      
                              protected abstract void testDBComponents () throws Exception;
                      
                              protected void initEM () {
                      
                                  em = (EntityManager) Component.getInstance ("em");
                                  transaction = em.getTransaction ();
                                  transaction.begin ();
                                  transaction.setRollbackOnly ();
                              }
                      
                              protected void cleanEM () {
                      
                                  if (transaction != null && transaction.isActive ()) {
                                      transaction.rollback ();
                                  }
                              }
                      
                              /**
                               * ********* Get/Set ***********
                               */
                      
                              public EntityManager getEm () {
                                  return em;
                              }
                      
                              public void setEm (final EntityManager pEm) {
                                  em = pEm;
                              }
                      
                              public EntityTransaction getTransaction () {
                                  return transaction;
                              }
                      
                              public void setTransaction (final EntityTransaction pTransaction) {
                                  transaction = pTransaction;
                              }
                          }
                      }




                      public class BootstrapEnvironment
                              extends AbstractSeamTest {
                      
                          private static boolean started = false;
                      
                          private ServletContext servletContext;
                      
                          private static InitialContext initialContext = null;
                      
                          private static InitialContext securedInitialContext = null;
                      
                          /**
                           * ********* Setup ***********
                           */
                          @BeforeSuite
                          // needs a WEB-INF/web.xml in resources!!!
                          public void beforeSuite () throws Exception {
                              startSeam ();
                          }
                      
                          @BeforeClass
                          public void beforeClass () throws Exception {
                              setupClass ();
                          }
                      
                          @BeforeMethod
                          @Override
                          public void begin () {
                              super.begin ();
                              //TestLifecycle.beginTest (servletContext, new ServletSessionMap (getSession ()));
                          }
                      
                          @AfterMethod
                          @Override
                          public void end () {
                              //TestLifecycle.endTest ();
                              super.end ();
                          }
                      
                          @AfterClass
                          public void afterClass () throws Exception {
                              cleanupClass ();
                          }
                      
                          @AfterSuite
                          public void afterSuite () throws Exception {
                              stopSeam ();
                          }
                      
                          /**
                           * ********* Methods ***********
                           */
                      
                          @Override
                          protected void startJbossEmbeddedIfNecessary ()
                                  throws Exception {
                      
                              if (!started && openEjbAvailable ()) {
                                  startOpenEJB ();
                              }
                              started = true;
                          }
                      
                          protected void startOpenEJB () throws Exception {
                      
                              new OpenEjbBootstrap ().startAndDeployResources ();
                          }
                      
                          private boolean openEjbAvailable () {
                      
                              try {
                                  Class.forName ("org.apache.openejb.OpenEJB");
                                  return true;
                              }
                              catch (ClassNotFoundException e) {
                                  return false;
                              }
                          }
                      
                          @Override
                          protected InitialContext getInitialContext ()
                                  throws NamingException {
                      
                              return getStaticInitialContext ();
                          }
                      
                          public static InitialContext getStaticInitialContext ()
                                  throws NamingException {
                      
                              if (initialContext == null) {
                                  loadInitialContext ();
                              }
                              return initialContext;
                          }
                      
                          /**
                           * Return a new InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory,
                           * setting the the default context.
                           *
                           * @return javax.naming.InitialContext
                           * @throws Exception
                           */
                          public InitialContext newInitialContext ()
                                  throws Exception {
                      
                              Hashtable<String, String> props = getInitialContextProperties ();
                              initialContext = new InitialContext (props);
                              return initialContext;
                          }
                      
                          /**
                           * Return a new InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory,
                           * setting the default context. Use the specified username and password to set the security context.
                           *
                           * @param pPrincipal
                           * @param credential
                           * @return javax.naming.InitialContext
                           * @throws Exception
                           */
                          public InitialContext newInitialContext (final String pPrincipal,
                                                                   final String pCredential)
                                  throws Exception {
                      
                              Hashtable<String, String> props =
                                      getInitialContextProperties (pPrincipal, pCredential);
                              securedInitialContext = new InitialContext (props);
                              return securedInitialContext;
                          }
                      
                          /**
                           * Return the default InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory
                           * if one is already instantiated, otherwise create a new InitialContext and set as the default.
                           *
                           * @return javax.naming.InitialContext
                           * @throws javax.naming.NamingException
                           */
                          public static InitialContext loadInitialContext ()
                                  throws NamingException {
                      
                              if (initialContext == null) {
                                  Hashtable<String, String> props = getInitialContextProperties ();
                                  initialContext = new InitialContext (props);
                              }
                              return initialContext;
                          }
                      
                          /**
                           * Return the default InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory
                           * if one is already instantiated, otherwise create a new InitialContext and set as the default.
                           * Use the specified username and password to set the security context.
                           *
                           * @param pPrincipal
                           * @param pCredential
                           * @return
                           * @throws javax.naming.NamingException
                           */
                          public InitialContext loadInitialContext (final String pPrincipal,
                                                                    final String pCredential)
                                  throws NamingException {
                      
                              if (securedInitialContext == null) {
                                  Hashtable<String, String> props =
                                          getInitialContextProperties (pPrincipal, pCredential);
                                  securedInitialContext = new InitialContext (props);
                              }
                              return securedInitialContext;
                          }
                      
                          private static Hashtable<String, String> getInitialContextProperties () {
                      
                              Hashtable<String, String> props = new Hashtable<String, String> (1);
                              props.put (Context.INITIAL_CONTEXT_FACTORY,
                                         "org.apache.openejb.client.LocalInitialContextFactory");
                      
                              return props;
                          }
                      
                          private Hashtable<String, String> getInitialContextProperties (final String pPrincipal,
                                                                                         final String pCredential) {
                      
                              Hashtable<String, String> props = getInitialContextProperties ();
                              props.put (Context.SECURITY_PRINCIPAL, pPrincipal);
                              props.put (Context.SECURITY_CREDENTIALS, pCredential);
                              return props;
                          }
                      }




                      public class OpenEjbBootstrap {
                      
                          public void startAndDeployResources ()
                                  throws Exception {
                      
                              startAndDeployResources (null);
                          }
                      
                          public void startAndDeployResources (final Properties pProperties)
                                  throws Exception {
                      
                              try {
                                  String base = "target/test-classes";
                                  System.setProperty ("openejb.home", base);
                                  System.setProperty ("openejb.base", base);
                      
                                  Properties props = new Properties ();
                                  props.put ("openejb.jndiname.format", "{deploymentId}/{interfaceType.annotationName}");
                                  props.put ("openejb.configuration", base + "/openejb.xml");
                      
                                  if (pProperties != null) {
                                      props.putAll (pProperties);
                                  }
                      
                                  // DEBUG - print classpath
                                  /*
                                  ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader ();
                                  URL[] urls = ((URLClassLoader) sysClassLoader).getURLs ();
                                  LoggingStaticService.info ("############################");
                                  LoggingStaticService.info ("CLASSPATH:");
                                  for (URL url : urls) {
                                      String prefix;
                                      String s = url.getFile ();
                                      if (s.endsWith (".jar")) {
                                          prefix = "JAR: ";
                                      } else {
                                          prefix = "DIR: ";
                                      }
                                      LoggingStaticService.info (prefix + s);
                                  }
                                  LoggingStaticService.info ("############################");
                                  */
                                  // DEBUG
                      
                                  OpenEJB.init (props);
                              }
                              catch (Exception ex) {
                                  LoggingStaticService.error (ex);
                                  throw new RuntimeException (ex);
                              }
                          }
                      
                          private boolean resourceExists (final String pName) {
                      
                              return Thread.currentThread ().getContextClassLoader ().getResource (pName) != null;
                          }
                      
                      }




                      @Name("org.jboss.seam.transaction.transaction_container")
                      @Scope(ScopeType.EVENT)
                      @Install(precedence = Install.MOCK)
                      @BypassInterceptors
                      public class MockTransaction
                              extends Transaction {
                      
                          public static String EJB_CONTEXT_NAME = "java:comp.ejb3/EJBContext";
                      
                          public static final String STANDARD_EJB_CONTEXT_NAME = "java:comp/EJBContext";
                      
                          @Override
                          protected org.jboss.seam.transaction.UserTransaction createCMTTransaction ()
                                  throws NamingException {
                      
                              return new CMTTransaction (getEJBContext ());
                          }
                      
                          public static EJBContext getEJBContext ()
                                  throws NamingException {
                      
                              try {
                                  return (EJBContext) BootstrapEnvironment.getStaticInitialContext ()
                                          .lookup (EJB_CONTEXT_NAME);
                              }
                              catch (NameNotFoundException nnfe) {
                                  return (EJBContext) BootstrapEnvironment.getStaticInitialContext ()
                                          .lookup (STANDARD_EJB_CONTEXT_NAME);
                              }
                          }
                      
                          @Override
                          protected UserTransaction getUserTransaction ()
                                  throws NamingException {
                      
                              InitialContext context = BootstrapEnvironment.getStaticInitialContext ();
                      
                              try {
                                  return (UserTransaction) context.lookup ("java:comp/UserTransaction");
                              }
                              catch (NameNotFoundException nnfe) {
                                  try {
                                      //Embedded JBoss has no java:comp/UserTransaction
                                      UserTransaction ut = (UserTransaction) context.lookup ("UserTransaction");
                                      ut.getStatus (); //for glassfish, which can return an unusable UT
                                      return ut;
                                  }
                                  catch (Exception e) {
                                      throw nnfe;
                                  }
                              }
                          }
                      }





                      @BypassInterceptors
                      public class ReallyNoTransaction
                              extends NoTransaction {
                      
                          @Override
                          public void begin () throws NotSupportedException, SystemException {
                      
                          }
                      
                          @Override
                          public void commit () throws RollbackException, HeuristicMixedException,
                                                       HeuristicRollbackException, SecurityException,
                                                       IllegalStateException, SystemException {
                      
                          }
                      
                          @Override
                          public int getStatus () throws SystemException {
                              return Status.STATUS_NO_TRANSACTION;
                          }
                      
                          @Override
                          public void rollback () throws IllegalStateException, SecurityException, SystemException {
                      
                          }
                      
                          @Override
                          public void setRollbackOnly () throws IllegalStateException, SystemException {
                      
                          }
                      
                          @Override
                          public void setTransactionTimeout (final int pTimeout) throws SystemException {
                      
                          }
                      
                          @Override
                          public void registerSynchronization (final Synchronization sync) {
                      
                          }
                      
                      }



                      A test template:


                      @Test(groups = "whitebox")
                      public class ExampleTest
                              extends ContainerWhiteBoxTest {
                      
                          // save --------------------------------------------------------------------------------------
                          public void should () throws Exception {
                      
                              new DBComponentTest() {
                      
                                  @Override
                                  protected void testDBComponents () throws Exception {
                                      // ...
                                  }
                              }.run ();
                          }
                      }



                      also I created a folder 'resources-ejb' next to my 'resources' in my maven structure. it contains:


                      ejb-jar.xml


                      <ejb-jar/>



                      openejb.xml


                      <?xml version="1.0"?>
                      <openejb/>



                      WEB-INF/web.xml


                      <?xml version="1.0" encoding="UTF-8"?>
                      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                               xmlns="http://java.sun.com/xml/ns/javaee"
                               xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                               version="2.5">
                      
                          <listener>
                              <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
                          </listener>
                      
                          <filter>
                              <filter-name>Seam Filter</filter-name>
                              <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
                          </filter>
                      
                          <filter-mapping>
                              <filter-name>Seam Filter</filter-name>
                              <url-pattern>/*</url-pattern>
                          </filter-mapping>
                      
                      </web-app>



                      WEB-INF/components.xml


                      <?xml version="1.0" encoding="UTF-8"?>
                      <components xmlns="http://jboss.com/products/seam/components"
                                  xmlns:core="http://jboss.com/products/seam/core"
                                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                                  xmlns:security="http://jboss.com/products/seam/security"
                                  xmlns:framework="http://jboss.com/products/seam/framework">
                      
                          <!-- #### -->
                          <!-- CORE -->
                          <!-- #### -->
                      
                          <core:init
                                  jndi-pattern="\#{ejbName}/local"
                                  debug="false" transaction-management-enabled="false"/>
                      
                          <component
                                  class="com.TODO.ReallyNoTransaction"
                                  name="org.jboss.seam.transaction.transaction" scope="event" precedence="30"/>
                      
                      
                          <!-- ############# -->
                          <!-- ENTITYMANAGER -->
                          <!-- ############# -->
                      
                          <!-- JPA -->
                          <transaction:no-transaction/>
                      
                          <persistence:entity-manager-factory
                                  name="containerPU"/>
                      
                          <persistence:managed-persistence-context
                                  name="em" auto-create="true" entity-manager-factory="#{containerPU}"/>
                      
                          <!-- ######## -->
                          <!-- SECURITY -->
                          <!-- ######## -->
                      
                          <security:jpa-identity-store
                                  user-class="com.TODO.entity.UserEntity"
                                  role-class="com.TODO.entity.UserRoleEntity"/>
                      
                          <security:jpa-permission-store
                                  user-permission-class="com.TODO.entity.UserPermissionEntity"/>
                      
                          <security:identity
                                  authenticate-method="#{TODO}"
                                  remember-me="false"/>
                      
                      </components>



                      and in my persistence.xml (unter resources/META-INF) I added to the existing PU:


                      <persistence-unit name="containerPU" transaction-type="RESOURCE_LOCAL">
                      
                              <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      
                              <!--
                              <jta-data-source>java:openejb/Resource/Default JDBC Database</jta-data-source>
                              <non-jta-data-source>java:openejb/Resource/Default Unmanaged JDBC Database</non-jta-data-source>
                              -->
                      
                              <properties>
                                  <property name="hibernate.hbm2ddl.auto"
                                            value="create-drop"/>
                                  <property name="hibernate.connection.driver_class"
                                            value="org.h2.Driver"/>
                                  <property name="hibernate.connection.username"
                                            value="sa"/>
                                  <property name="hibernate.connection.password"
                                            value=""/>
                                  <property name="hibernate.connection.url"
                                            value="jdbc:h2:mem:mydb"/>
                                  <property name="hibernate.dialect"
                                            value="org.hibernate.dialect.H2Dialect"/>
                                  <property name="hibernate.connection.release_mode"
                                            value="after_transaction"/>
                                  <property name="hibernate.transaction.manager_lookup_class"
                                            value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
                              </properties>
                      
                          </persistence-unit>



                      As a maven user of course I had to add 'resources-ejb' to the classpath:


                      <testResources>
                        <!-- needed for whitebox container tests: -->
                        <testResource>
                          <filtering>false</filtering>
                          <directory>${basedir}/src/test/resources-ejb</directory>
                        </testResource>
                      </testResources>



                      By the way - the openejb dependency looks like this:



                             <!-- OpenEJB Application Server -->
                              <dependency>
                                  <groupId>org.apache.openejb</groupId>
                                  <artifactId>openejb-core</artifactId>
                                  <version>3.1</version>
                                  <exclusions>
                                      <exclusion>
                                          <groupId>org.apache.openjpa</groupId>
                                          <artifactId>openjpa</artifactId>
                                      </exclusion>
                                      <exclusion>
                                          <groupId>hsqldb</groupId>
                                          <artifactId>hsqldb</artifactId>
                                      </exclusion>
                                      <exclusion>
                                          <groupId>junit</groupId>
                                          <artifactId>junit</artifactId>
                                      </exclusion>
                                  </exclusions>
                              </dependency>




                      I can't tell which files are really crucial and which are not - but I can tell you that this combination works for me :-)
                      Of course all credit goes to Olivier Thierry - I merely changed a few lines of code and added config files.


                      Hope it works for you!

                      • 8. Re: Using OpenEJB for integration testing
                        lucio piccoli Newbie


                        I can't tell which files are really crucial and which are not - but I can tell you that this combination works for me :-) Of course all credit goes to Olivier Thierry - I merely changed a few lines of code and added config files.

                        great detail!


                        i got heaps of dependencies issues that i am working thru to integrated openejb into my seam project.


                        what did u remove from the original seam-gen classpath? i assumed u removed all the jboss-embedded jars?
                        Did u also remove the 'bootstrap' folder?


                        -lp

                        • 9. Re: Using OpenEJB for integration testing
                          Stephan B Newbie

                          well, I didn't use seam-gen to build the basis, I defined everything from scratch via maven


                          the jboss-embedded jars have to go of course, the bootstrap-folder too


                          I created a dependency tree from maven where you can see what dependencies I have (my project is scattered across various sub modules):


                           com.author:portal-web:war:0.0.4
                           +- javax.servlet:servlet-api:jar:2.5:provided (scope not updated to compile)
                           +- commons-digester:commons-digester:jar:1.8:compile
                           |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
                           +- commons-logging:commons-logging:jar:1.1:compile
                           |  +- logkit:logkit:jar:1.0.1:compile
                           |  \- avalon-framework:avalon-framework:jar:4.1.3:compile
                           +- org.jboss.seam:jboss-seam-ui:jar:2.2.0.GA:runtime
                           |  \- org.jboss.seam:jboss-seam-jul:jar:2.2.0.GA:runtime
                           +- org.jboss.seam:jboss-seam-mail:jar:2.2.0.GA:runtime
                           +- org.jboss:jboss-faces:jar:4.2.3.GA:runtime
                           +- jboss:jboss-serialization:jar:4.2.2.GA:runtime
                           +- org.jboss.logging:jboss-logging-spi:jar:2.0.5.GA:runtime
                           +- trove:trove:jar:1.0.2:runtime
                           +- net.sourceforge.nekohtml:nekohtml:jar:1.9.9:runtime
                           |  \- xerces:xercesImpl:jar:2.8.1:runtime
                           +- org.mortbay.jetty:jetty-embedded:jar:6.1.19:provided
                           |  +- org.mortbay.jetty:jetty:jar:6.1.19:provided
                           |  |  +- org.mortbay.jetty:jetty-util:jar:6.1.19:provided
                           |  |  \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:provided
                           |  \- javax.servlet.jsp:jsp-api:jar:2.1:provided
                           +- org.webcastellum:webcastellum:jar:1.8.2:system
                           +- com.author:portal-lib:jar:0.0.4:compile
                           |  +- org.jboss.seam:jboss-seam-resteasy:jar:2.2.0.GA:runtime
                           |  |  +- org.jboss.resteasy:resteasy-jaxrs:jar:1.1-RC2:runtime
                           |  |  |  \- org.jboss.resteasy:jaxrs-api:jar:1.1-RC2:runtime
                           |  |  +- org.jboss.resteasy:resteasy-jaxb-provider:jar:1.1-RC2:runtime
                           |  |  |  +- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.2:runtime
                           |  |  |  +- com.sun.xml.stream:sjsxp:jar:1.0.1:runtime
                           |  |  |  |  \- javax.xml.stream:stax-api:jar:1.0:runtime
                           |  |  |  \- org.codehaus.jettison:jettison:jar:1.0.1:runtime
                           |  |  \- org.jboss.resteasy:resteasy-atom-provider:jar:1.1-RC2:runtime
                           |  +- com.sunshock.portal:portal-users:jar:0.0.4:compile
                           |  |  \- com.sunshock.portal:portal-common:jar:0.0.4:compile
                           |  |     \- com.sunshock.portal:portal-generic:jar:0.0.4:compile
                           |  |        +- javax.faces:jsf-impl:jar:1.2_13:runtime
                           |  |        +- javax.faces:jsf-api:jar:1.2_13:compile
                           |  |        +- org.jboss.seam:jboss-seam:jar:2.2.0.GA:compile
                           |  |        |  +- xstream:xstream:jar:1.1.3:compile
                           |  |        |  +- xpp3:xpp3_min:jar:1.1.3.4.O:compile
                           |  |        |  \- org.jboss.el:jboss-el:jar:1.0_02.CR4:compile
                           |  |        +- javassist:javassist:jar:3.8.0.GA:compile
                           |  |        +- org.tuckey:urlrewritefilter:jar:3.1.0:compile
                           |  |        +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
                           |  |        |  +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
                           |  |        |  +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
                           |  |        |  +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
                           |  |        |  |  \- antlr:antlr:jar:2.7.6:compile
                           |  |        |  +- org.slf4j:slf4j-api:jar:1.4.2:compile
                           |  |        |  +- dom4j:dom4j:jar:1.6.1:compile
                           |  |        |  |  \- xml-apis:xml-apis:jar:1.3.04:compile
                           |  |        |  \- javax.transaction:jta:jar:1.1:compile
                           |  |        +- org.hibernate:hibernate-validator:jar:3.1.0.GA:compile
                           |  |        +- org.hibernate:hibernate-c3p0:jar:3.3.2.GA:compile
                           |  |        |  \- c3p0:c3p0:jar:0.9.1:compile
                           |  |        +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
                           |  |        +- net.sf.ehcache:ehcache:jar:1.5.0:compile
                           |  |        |  +- backport-util-concurrent:backport-util-concurrent:jar:2.1:compile
                           |  |        |  \- net.sf.jsr107cache:jsr107cache:jar:1.0:compile
                           |  |        +- org.hibernate:hibernate-ehcache:jar:3.3.1.GA:compile
                           |  |        +- org.hibernate:hibernate-tools:jar:3.2.4.GA:compile
                           |  |        |  +- org.beanshell:bsh:jar:2.0b4:compile
                           |  |        |  +- freemarker:freemarker:jar:2.3.8:compile
                           |  |        |  \- org.hibernate:jtidy:jar:r8-20060801:compile
                           |  |        +- org.jboss.envers:jboss-envers:jar:1.2.1.GA-hibernate-3.3:compile
                           |  |        +- org.apache.ant:ant:jar:1.7.0:compile
                           |  |        |  \- org.apache.ant:ant-launcher:jar:1.7.0:compile
                           |  |        +- org.slf4j:slf4j-log4j12:jar:1.5.2:runtime
                           |  |        |  \- log4j:log4j:jar:1.2.12:runtime
                           |  |        +- commons-lang:commons-lang:jar:2.4:compile
                           |  |        +- net.jawr:jawr:jar:2.7:runtime
                           |  |        \- org.opensymphony.quartz:quartz:jar:1.6.1:compile
                           |  +- com.author:integration:jar:0.0.4:compile
                           |  |  +- org.apache.httpcomponents:httpclient:jar:4.0:compile
                           |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
                           |  |  |  \- commons-codec:commons-codec:jar:1.3:compile
                           |  |  +- net.java.dev.jets3t:jets3t:jar:0.7.1:compile
                           |  |  |  \- commons-httpclient:commons-httpclient:jar:3.1:compile
                           |  |  +- com.sun.jersey:jersey-client:jar:1.1.1-ea:compile
                           |  |  |  \- com.sun.jersey:jersey-core:jar:1.1.1-ea:compile
                           |  |  |     \- javax.ws.rs:jsr311-api:jar:1.1:compile
                           |  |  +- com.sun.jersey:jersey-server:jar:1.1.1-ea:compile
                           |  |  |  \- asm:asm:jar:3.1:compile
                           |  |  \- com.sunshock.common:common-utilities:jar:0.0.4:compile
                           |  |     +- org.jasypt:jasypt:jar:1.5:compile
                           |  |     \- com.sunshock.common:common-generic:jar:0.0.4:compile
                           |  |        +- commons-io:commons-io:jar:1.4:compile
                           |  |        \- javax.persistence:persistence-api:jar:1.0:compile
                           |  +- org.richfaces.framework:richfaces-impl:jar:3.3.2.CR1:compile
                           |  +- org.richfaces.ui:richfaces-ui:jar:3.3.2.CR1:compile
                           |  +- org.richfaces.framework:richfaces-api:jar:3.3.2.CR1:compile
                           |  |  \- commons-collections:commons-collections:jar:3.2:compile
                           |  \- commons-fileupload:commons-fileupload:jar:1.2.1:compile
                           +- de.odysseus.juel:juel:jar:2.1.0:test
                           +- com.sunshock.portal:portal-test-container:jar:0.0.4:test
                           |  +- com.sunshock.portal:portal-test:jar:0.0.4:test
                           |  |  +- com.sunshock.common:common-test:jar:0.0.4:test
                           |  |  |  +- org.testng:testng:jar:jdk15:5.9:test
                           |  |  |  +- jdepend:jdepend:jar:2.9.1:test
                           |  |  |  +- org.mockito:mockito-all:jar:1.8.0:test
                           |  |  |  \- fest:fest-assert:jar:1.1a1:test
                           |  |  |     \- fest:fest-util:jar:1.0:test
                           |  |  \- com.h2database:h2:jar:1.1.117:test
                           |  +- org.glassfish.embedded:glassfish-embedded-all:jar:3.0-Prelude-Embedded-b14:test
                           |  \- org.apache.openejb:openejb-core:jar:3.1:test
                           |     +- org.apache.openejb:javaee-api:jar:5.0-1:test
                           |     +- org.apache.openejb:ejb31-api-experimental:jar:3.1:test
                           |     +- org.apache.openejb:openejb-loader:jar:3.1:test
                           |     +- org.apache.openejb:openejb-javaagent:jar:3.1:test
                           |     +- org.apache.openejb:openejb-jee:jar:3.1:test
                           |     |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:test
                           |     |  |  \- stax:stax-api:jar:1.0.1:test
                           |     |  \- com.sun.xml.bind:jaxb-impl:jar:2.0.5:test
                           |     +- commons-cli:commons-cli:jar:1.1:test
                           |     +- org.apache.activemq:activemq-ra:jar:4.1.1:test
                           |     +- org.apache.activemq:activemq-core:jar:4.1.1:test
                           |     |  \- org.apache.activemq:activeio-core:jar:3.0.0-incubator:test
                           |     +- net.sourceforge.serp:serp:jar:1.13.1:test
                           |     +- org.apache.geronimo.components:geronimo-connector:jar:2.1:test
                           |     +- org.apache.geronimo.components:geronimo-transaction:jar:2.1:test
                           |     +- org.objectweb.howl:howl:jar:1.0.1-1:test
                           |     +- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.2:test
                           |     +- org.apache.xbean:xbean-reflect:jar:3.4.1:test
                           |     |  \- commons-logging:commons-logging-api:jar:1.1:test
                           |     +- org.apache.openejb:asm-finder:jar:3.1:test
                           |     +- org.apache.xbean:xbean-naming:jar:3.4.1:test
                           |     +- org.apache.openejb:commons-dbcp-all:jar:1.3-r699049:test
                           |     +- org.codehaus.swizzle:swizzle-stream:jar:1.0.1:test
                           |     \- wsdl4j:wsdl4j:jar:1.6.1:test
                           +- com.sunshock.portal:portal-test-ui:jar:0.0.4:test
                           |  +- org.openqa.selenium.webdriver:webdriver-htmlunit:jar:0.6.1039:test
                           |  |  +- org.openqa.selenium.webdriver:webdriver-common:jar:0.6.1039:test
                           |  |  \- net.sourceforge.htmlunit:htmlunit:jar:2.5:test
                           |  |     +- xalan:xalan:jar:2.7.1:test
                           |  |     |  \- xalan:serializer:jar:2.7.1:test
                           |  |     +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.5:test
                           |  |     \- net.sourceforge.cssparser:cssparser:jar:0.9.5:test
                           |  |        \- org.w3c.css:sac:jar:1.3:test
                           |  +- org.openqa.selenium.webdriver:webdriver-firefox:jar:0.6.1039:test
                           |  |  \- org.json:json:jar:20080701:test
                           |  \- org.openqa.selenium.webdriver:webdriver-support:jar:0.6.1039:test
                           |     \- org.hamcrest:hamcrest-all:jar:1.1:test
                           +- org.jvnet.mock-javamail:mock-javamail:jar:1.7:compile
                           |  +- javax.mail:mail:jar:1.4:compile
                           |  |  \- javax.activation:activation:jar:1.1:compile
                           |  \- junit:junit:jar:3.8:compile
                           +- hsqldb:hsqldb:jar:1.8.0.7:compile
                           \- org.jboss.seam:jboss-seam-debug:jar:2.2.0.GA:compile
                              \- com.sun.facelets:jsf-facelets:jar:1.1.15.B1:compile



                          Many of it is probably not relevant for you - but the 'org.apache.openejb:openejb-core:jar:3.1:test'-part might be.

                          • 10. Re: Using OpenEJB for integration testing
                            Tiago Augusto Coelho Newbie

                            Hi guys, i am facing the same problem with my testNG. i am following the instruction you gave, and it works almost fine :).


                            My only problema is the fact that, when i run my install with test my persistence.xml must have diferente jndi name, one for the tomcat and another to the openEJB. So i have to disable the test when i run install for development phase, and enable test for a deply with test, Did you have the same issue?

                            • 11. Re: Using OpenEJB for integration testing
                              Stephan B Newbie

                              I'm sorry - as you can see the posts are over 1 year old. I didn't manage to get it right, the project is long gone and I'm now on the Spring stack.


                              But good luck! :)