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. площадку для обмена цифровых активов и произвести трансакцию

    1. Определите цель операции
    Перед выбором обменной платформы важно понять, что именно вы планируете перевести — BTC, Ethereum или другие токены.

    2. Проверьте репутацию сервиса
    Используйте обзоры в сети для оценки качества работы.
    Проверьте наличие лицензий и прозрачных условий.

    3. Сравните ценовые предложения
    Разные сервисы могут предлагать средний курс.
    Используйте специальные сервисы для поиска максимально выгодного варианта.

    4. Оцените комиссии
    Некоторые обменники могут предлагать среднюю комиссию. Сравните структуру комиссии заранее, чтобы избежать скрытых расходов http://mywoman.info/korotko-shho-take-kriptoobminnik-i-navishho-vin-potribnij.html

    5. Обратите внимание на оперативность
    Хороший сервис выполняет переводы быстро, особенно если речь идёт о быстро меняющихся курсах.

    6. Проверьте способы ввода средств и вывода
    Выберите метод, удобный вам: платёжная система, а также удобный вывод.

    7. Как произвести трансакцию
    1. Выберите онлайн-сервис с подходящими курсами.
    2. Укажите валютный маршрут — например, Bitcoin в Tether.
    3. Введите сумму и реквизиты получения.
    4. Оплатите ордер.
    5. Дождитесь подтверждения транзакции.

    Совет
    Выбирайте авторитетные криптообменники и всегда проверяйте адреса кошельков перед подтверждением.

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.