Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:19:59+00:00 2026-05-11T06:19:59+00:00

I would like to have a JUnit (or other) system where the enterprise beans

  • 0

I would like to have a JUnit (or other) system where the enterprise beans can be tested in a mock environment so that all resources/beans and so on are injected locally. The enterprise beans should not have to accomplish this. All kinds of injection should be supported.

  • I would like to have a maven plugin for this so that the tests can be run from a maven build.
  • Transactions are not necessary during the unit tests,this would require a complete container.

Do you know of such a maven plugin or test framework? Experiences with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:19:59+00:00Added an answer on May 11, 2026 at 6:19 am

    Not necessarily the easiest way, but I managed to get this working using JBoss’s embeddable EJB3.0 container, with major assistance from Java Persistence with Hibernate

    For a start, I don’t know of maven plugins/dependencies for this, so I had to install my own locally:

    (1) Download jboss-EJB-3.0_Embeddable_ALPHA_9.zip from downloads

    (2) This zipfile contains two important JARs:

    • jboss-ejb3-all.jar
    • thirdparty-all.jar

    (3) Install these JARs into your local repository (use your own initials instead of nkl):

    mvn install:install-file \     -Dfile=jboss-ejb3-all.jar \     -DgroupId=nkl.jboss.embedded \     -DartifactId=jboss-ejb3-all \     -Dversion=3.0-alpha-9  mvn install:install-file \     -Dfile=thirdparty-all.jar \     -DgroupId=nkl.jboss.embedded \     -DartifactId=thirdparty-all \     -Dversion=3.0-alpha-9 

    (4) If all has gone well, you should now have two directories in your local repository.

    (5) Now add the following dependencies to your pom.xml

        <dependency>       <groupId>nkl.jboss.embedded</groupId>       <artifactId>jboss-ejb3-all</artifactId>       <version>3.0-alpha-9</version>     </dependency>     <dependency>       <groupId>nkl.jboss.embedded</groupId>       <artifactId>thirdparty-all</artifactId>       <version>3.0-alpha-9</version>     </dependency> 

    (6) I also needed to add dependencies for HSQLDB, and SLF4J

    (7) You need to copy some files from the conf directory of the zipfile to the src/main/resources directory of your project:

    • default.persistence.properties
    • ejb3-interceptors-aop.xml
    • embedded-jboss-beans.xml
    • jndi.properties

    (8) I created my own beans.xml and persistence.xml files in src/main/resources/META-INF:

    <?xml version='1.0' encoding='UTF-8'?> <deployment xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'   xsi:schemaLocation='urn:jboss:bean-deployer bean-deployer_1_0.xsd' xmlns='urn:jboss:bean-deployer'>   <bean name='messageDSBootstrap' class='org.jboss.resource.adapter.jdbc.local.LocalTxDataSource'>     <property name='jndiName'>java:/messageDS</property>     <property name='driverClass'>org.hsqldb.jdbcDriver     </property>     <property name='connectionURL'>jdbc:hsqldb:test</property>     <property name='minSize'>0</property>     <property name='maxSize'>10</property>     <property name='blockingTimeout'>1000</property>     <property name='idleTimeout'>30000</property>     <property name='transactionManager'>       <inject bean='TransactionManager' />     </property>     <property name='cachedConnectionManager'>       <inject bean='CachedConnectionManager' />     </property>     <property name='initialContextProperties'>       <inject bean='InitialContextProperties' />     </property>   </bean>   <bean name='messageDS' class='java.lang.Object'>     <constructor factoryMethod='getDatasource'>       <factory bean='messageDSBootstrap' />     </constructor>   </bean> </deployment>  <persistence xmlns='http://java.sun.com/xml/ns/persistence'   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'   xsi:schemaLocation='http://java.sun.com/xml/ns/persistence    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd'   version='1.0'>   <persistence-unit name='jpa'>     <provider>org.hibernate.ejb.HibernatePersistence</provider>     <jta-data-source>java:/messageDS</jta-data-source>     <properties>       <property name='hibernate.dialect' value='org.hibernate.dialect.HSQLDialect' />       <property name='hibernate.show_sql' value='true' />       <property name='hibernate.format_sql' value='true' />       <property name='hibernate.hbm2ddl.auto' value='create' />     </properties>   </persistence-unit> </persistence> 

    (9) I created a unit test like the following, using additional infomation from here.

    package org.nkl;  import java.io.File;  import javax.naming.InitialContext;  import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; import org.jboss.ejb3.embedded.EJB3StandaloneDeployer; import org.junit.Test; import org.nkl.model.MessageHandler;  public class BasicTest {      @Test     public void testEjb() throws Exception {         EJB3StandaloneBootstrap.boot(null);         EJB3StandaloneBootstrap.deployXmlResource('META-INF/beans.xml');         EJB3StandaloneDeployer deployer = EJB3StandaloneBootstrap                 .createDeployer();          deployer.getArchives().add(new File('target/classes').toURI().toURL());          deployer.create();         deployer.start();         InitialContext context = new InitialContext();         MessageHandler messageHandler = (MessageHandler) context                 .lookup('MessageHandlerBean/local');         messageHandler.saveMessages();         messageHandler.showMessages();         EJB3StandaloneBootstrap.shutdown();     } } 

    (10) This uses a simple SLSB like:

    package org.nkl.ejb;  import java.util.List;  import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext;  import org.nkl.model.Message; import org.nkl.model.MessageHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory;  @Stateless public class MessageHandlerBean implements MessageHandler {      @PersistenceContext     private EntityManager em;      Logger logger = LoggerFactory.getLogger(MessageHandlerBean.class);      public void saveMessages() {         logger.info('In saveMessages');         em.persist(new Message('Hello World'));     }      @SuppressWarnings('unchecked')     public void showMessages() {         logger.info('In showMessages');         List messages = em.createQuery(                 'select m from Message m order by m.text asc').getResultList();         for (Object o : messages) {             logger.info(((Message) o).getText());         }     } } 

    (11) And a Message entity class like:

    package org.nkl.model;  import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table;  @Entity @Table(name = 'MESSAGES') public class Message {     @Id     @GeneratedValue     @Column(name = 'MESSAGE_ID')     private Long id;     @Column(name = 'MESSAGE_TEXT')     private String text;     @ManyToOne(cascade = CascadeType.ALL)     @JoinColumn(name = 'NEXT_MESSAGE')     private Message nextMessage;      public Message(String text) {         this.text = text;     }      Message() {}      // setters/getters not shown.  } 

    Lets just say there are a number of stumbling blocks along the way in this approach.

    Notably to do with the order of dependencies.

    Good luck!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 10 JUnit that will be executed automatically. I would like to
I have a JUnit 3.x TestCase which I would like to be able to
I have written JUnit tests for my class, and would like it to tell
I have a problem that I would like have solved via a SQL query.
So in my project i would like have a nice treeview that has images.
I would like to have it so that when I play one Vimeo video
I would like to have a Referral model, where user A can refer an
I would like to have an interface that allows for a generic type public
I have an ant build file that contains JUnit test suite that I would
For tests of some small JBoss enterprise apps I would like to use JUnit,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.