Posts
Showing posts from April, 2011
EJB 3 JUnit testing with OpenEJB 3.1.4
- Get link
- X
- Other Apps
This is quick example of how to create JUnit test to test the EJB 3.0 session bean. The approach is new innovation using @LocalClient. This will create EJB client for Java SE. The interface of the calculator class is, package com.ojitha.calculator; import javax.ejb.Local; @Local public interface CalculatorLocal { public int add(int a, int b); } This is the implement of the Calculator package com.ojitha.calculator; import javax.ejb.Stateless; /** * Session Bean implementation class Calculator */ @Stateless public class Calculator implements CalculatorLocal { /** * Default constructor. */ public Calculator() { } @Override public int add(int a, int b) { return a + b; } } Let's look at the openEJB based JUnit test class package com.ojitha.calculator; import static org.junit.Assert.*; import java.util.Properties; import javax.ejb.EJB; import javax.naming.InitialContext; import org.apache.openejb.api.LocalClient; import org.junit.After; import o...