6.2. Writing the test class code

This example tests if a business method can be invoked from a bean, and if the bean can return an Integer value without modifications.

The source code(TestExample.java) can be found in the tests/examples folder of the project (named EasyBeans by default):

package org.objectweb.easybeans.tests.examples;

import static org.objectweb.easybeans.tests.common.helper.EJBHelper.getBeanRemoteInstance;
import static org.testng.Assert.assertEquals;

import org.objectweb.easybeans.tests.common.ejbs.base.ItfExample;
import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBExample;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;

/**
 * This is an example of a EasyBeans Test Suite Class.
 * @reference It is used to specify the document that the tests cover. Example:
 *            JSR220-PROPOSED FINAL
 * @requirement It is used to specify the classes and files needed to run the
 *              tests. Exampe: EasyBeans must be running and the bean
 *              org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SFSBExample
 *              must be deployed.
 * @setup It is used to specify the classes and files needed to run the test.
 * @author Eduardo Studzinski Estima de Castro
 * @author Gisele Pinheiro Souza
 */
public class TestExample {

    /**
     * Constant.
     */
    private static final Integer INPUT = new Integer(1);

    /**
     * Bean used in tests.
     */
    private ItfExample<Integer> bean;

    /**
     * Gets a new bean instance used during the tests.
     * @throws Exception if an error occurs during the setup.
     */
    @Configuration(beforeTestMethod = true)
    public void setup() throws Exception {
        // Gets a bean instance.
        bean = getBeanRemoteInstance(SLSBExample.class, ItfExample.class);
    }

    /**
     * Indicates the test description. Example: Tests if the bean can return a
     * value without modifications.
     * @input It is used to specify the classes and files needed to run the
     *        test. Example: Integer value.
     * @output It is used to specify the classes and files needed to run the
     *         test. Example: The same input integer.
     * @throws Exception if an error occurs during the test.
     */
    @Test
    public void test00() throws Exception {
        // Output value, it must be the same as the input.
        Integer output = bean.getValue(INPUT);

        // Test if input and output are equal.
        assertEquals(INPUT, output, "The input and output values should be equal.");
    }
}