How to unit test EJB3 without a container

Unit test EJB3 without a container has become much easier since the EJB 3.1 spec with the introduction of the embeddable EJBContainer concept. An embeddable EJBContainer is a container for enterprise beans that does not require a Java EE server to run.

Interesting usage scenarios are:

  • EJB unit testing: you don’t need to install a JavaEE server for EJB development, unit testing and deployment to the container
  • Lightweight: the embeddable container has a much smaller footprint
  • Fast: starts faster than the full server, because it only initializes EJB-related components

Sample code

Below you can find a simple setup method for a JUnit test that configures the Embeddable EJBContainer.

@Before
public void setup() {
	Properties properties = new Properties();
	properties.setProperty(EJBContainer.MODULES, "myModule");
	properties.put(EJBContainer.PROVIDER, "tomee-embedded");
	Context context = EJBContainer.createEJBContainer().getContext();
}

@After
public void tearDown() throws NamingException {
	ejbContainer.close();
}

Here myModule is the module-name defined in ejb-jar.xml file

So how does the EJBContainer start an embedded EJB container? You’ll need to provide an embedded EJB container on the classpath. Normally all Application servers supporting JavaEE6 have to provide such an embedded EJB container.

Apache TomEE container This example uses Apache TomEE as it provides an easy way to specify the correct dependencies via Maven.

<dependency>
	<groupId>org.apache.openejb</groupId>
	<artifactId>tomee-embedded</artifactId>
	<version>1.5.2</version>
</dependency>            
<dependency>
	<groupId>javax</groupId>
	<artifactId>javaee-api</artifactId>
	<version>6.0</version>
	<scope>provided</scope>
</dependency>

The properties.put(EJBContainer.PROVIDER, “tomee-embedded”) makes sure that we will use Apache TomEE when running the test. (even if there is another provider on the classpath)

0 thoughts on “How to unit test EJB3 without a container”

  1. Playgama offers a overwhelming tenets for gaming enthusiasts, featuring the latest and most artistically democratic online games. Solitary of the standout benefits of Playgama is its commitment to providing an uninterrupted gaming experience. Players can plunge into their favorite games without the hassle of long-winded downloads, officious ads, or annoying pop-ups that often visitation other gaming sites.

    With Playgama, you can obviously cargo up your chosen artifice at once in your интернет browser, allowing after seamless access and immediate enjoyment. This convenience means that you can post-haste swap between games, exploring new titles or revisiting archaic favorites without any barriers. Whether you are into vitality, reflect on, or plan games, Playgama has something in behalf of everyone https://playgama.com/

    To boot, the option is regularly updated, ensuring that you many times from access to the latest titles in the gaming world. The stand prioritizes narcotic addict practice, making it easy to navigate and find games that accommodate your interests.

    In conclusion, Playgama is the expert objective seeking anyone looking to be undergoing in jest and dig gaming without interruptions. With a far-reaching variety of emancipated online games nearby at your fingertips, you can submerge yourself in hours of entertainment—all from the solace of your web browser. So, why wait? Visit Playgama today and start your gaming adventure!

  2. Playgama offers a overwhelming tenets for gaming enthusiasts, featuring the latest and best manumitted online games. At one of the standout benefits of Playgama is its commitment to providing an uninterrupted gaming experience. Players can nosedive into their favorite games without the hassle of loquacious downloads, meddling ads, or annoying pop-ups that regularly evil other gaming sites.

    With Playgama, you can totally cross up your chosen spirited speedily in your web browser, allowing for seamless access and direct enjoyment. This convenience means that you can swiftly trade between games, exploring fresh titles or revisiting old favorites without any barriers. Whether you are into action, reflect on, or strategy games, Playgama has something in behalf of everyone https://zuxiashiguang.com/home.php?mod=space&uid=7356

    In addition, the option is regularly updated, ensuring that you always have access to the latest titles in the gaming world. The platform prioritizes owner incident, making it amicable to navigate and identify games that jacket your interests.

    In conclusion, Playgama is the perfect journey’s end in behalf of anyone looking to have in jest and appreciate gaming without interruptions. With a ample array of democratic online games nearby at your fingertips, you can dunk yourself in hours of sport—all from the relief of your web browser. So, why wait? Visit Playgama today and start your gaming adventure!

  3. Playgama offers a overwhelming platform payment gaming enthusiasts, featuring the latest and most artistically free online games. One of the standout benefits of Playgama is its commitment to providing an uninterrupted gaming experience. Players can plunge into their favorite games without the hassle of lengthy downloads, officious ads, or annoying pop-ups that ordinarily evil other gaming sites.

    With Playgama, you can unpretentiously cargo up your chosen gamble directly in your интернет browser, allowing for the sake seamless access and knee-jerk enjoyment. This convenience means that you can quick swap between games, exploring supplementary titles or revisiting archaic favorites without any barriers. Whether you are into action, contemplate, or tactics games, Playgama has something for everyone https://www.rosepic.vip/home.php?mod=space&uid=19309&do=profile

    To boot, the selection is regularly updated, ensuring that you each time have access to the latest titles in the gaming world. The tenets prioritizes drug incident, making it unhurried to pilot and identify games that suit your interests.

    In conclusion, Playgama is the expert objective seeking anyone looking to get in jest and appreciate gaming without interruptions. With a encyclopedic range of emancipated online games to hand at your fingertips, you can immerse yourself in hours of entertainment—all from the solace of your интернет browser. So, why wait? Inflict Playgama today and start your gaming undertaking!

  4. Playgama offers a extravagant tenets for gaming enthusiasts, featuring the latest and best free online games. Individual of the standout benefits of Playgama is its commitment to providing an uninterrupted gaming experience. Players can nosedive into their favorite games without the hassle of loquacious downloads, meddling ads, or annoying pop-ups that regularly visitation other gaming sites.

    With Playgama, you can simply cross up your chosen gamble speedily in your web browser, allowing after seamless access and knee-jerk enjoyment. This convenience means that you can quickly swap between games, exploring fresh titles or revisiting ex- favorites without any barriers. Whether you are into vitality, contemplate, or design games, Playgama has something as a replacement for everyone http://h-breed.com/uncategorized/hello-world/?unapproved=401386&moderation-hash=ee5916c0ffb5556effbd1b1f4f18680e#comment-401386

    In addition, the choice is regularly updated, ensuring that you each time have access to the latest titles in the gaming world. The party line prioritizes user practice, making it easy to pilot and identify games that jacket your interests.

    In conclusion, Playgama is the perfect destination in behalf of anyone looking to get playfulness and enjoy gaming without interruptions. With a encyclopedic distribute of untenanted online games present at your fingertips, you can dunk yourself in hours of performance—all from the luxury of your интернет browser. So, why wait? Visit Playgama today and start your gaming undertaking!

  5. Playgama offers a bizarre stand in the service of gaming enthusiasts, featuring the latest and most artistically democratic online games. At one of the standout benefits of Playgama is its commitment to providing an uninterrupted gaming experience. Players can plummet into their favorite games without the hassle of over-long downloads, officious ads, or annoying pop-ups that ordinarily visitation other gaming sites.

    With Playgama, you can obviously worry up your chosen artifice speedily in your web browser, allowing for seamless access and direct enjoyment. This convenience means that you can quickly switch between games, exploring fresh titles or revisiting out of date favorites without any barriers. Whether you are into manners, over, or design games, Playgama has something for everyone http://tekst-pesni.ru/index.php?name=account&op=info&uname=ynahek

    To boot, the choosing is regularly updated, ensuring that you always receive access to the latest titles in the gaming world. The party line prioritizes narcotic addict happening, making it light to manoeuvre and identify games that jacket your interests.

    In conclusion, Playgama is the perfect objective seeking anyone looking to obtain fun and enjoy gaming without interruptions. With a ample variety of democratic online games present at your fingertips, you can duck yourself in hours of diversion—all from the comfort of your интернет browser. So, why wait? Visit Playgama today and start your gaming episode!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.