140 likes | 289 Vues
Build, deploy, and test EJB components in just a few seconds. Nader Aeinehchi, Chief Architect – September 2005. Challenge. Build, deploy and test cycle very time-consuming In average between few minutes to half an hour Often requires cleaning the cache or restart of the server.
E N D
Build, deploy, and test EJB components in just a few seconds Nader Aeinehchi, Chief Architect – September 2005
Challenge • Build, deploy and test cycle very time-consuming • In average between few minutes to half an hour • Often requires cleaning the cache or restart of the server
Mock frameworks • Speed up the development process • But • Many frameworks to choose from • Mock frameworks do not provide a complete solution • Mock frameworks need to be integrated with each other • Requires the developer to learn the framework • Requires often special adjustments to the tests
EJB container EJB container Application Application Test Test Traditional testing of EJB components 1. 2. remote
Instead of running your code inside a container,Run the container inside your code
2. EJB container EJB container Test EJB container Application Application Application Test Test remote 3. Testing with embedded container 1. 1.
OpenEJB as embedded EJB container • Designed to be embedded • Takes few seconds to boot and run • Zero administration • Default EJB container for Apache Geronimo and supported by IBM
Test EJB container Application 3. Running OpenEJB in embedded mode • Provide JVM arguments: -Djava.naming.factory.initial=org.openejb.client.LocalInitialContextFactory -Djava.naming.provider.url=ormi://localhost:4201 -Dopenejb.home=c:\java\openejb\openejb-0.9.2 -Dopenejb.configuration=c:\java\openejb\openejb-0.9.2\conf\openejb.conf -Dopenejb.loader=embed -Dopenejb.localcopy=true
2. EJB container Application Test remote Run unit tests with Oracle OC4J • Deploy the application to OC4J • Provide JVM arguments: -Djava.naming.factory.initial=com.evermind.server.ApplicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost:23791/myapplication -Djava.naming.security.principal=admin -Djava.naming.security.credentials=password
Automate input for the tests • Hard-coded Java • time-consuming • pollutes the test • Database • requires a machinery • XML • Appropriate • Many XML – Java mapping frameworks • Xstream • Fast • Simple • Complex Object Hierarchy • Snapshot and persist to file: • XStream xstream = new XStream(); • String xml = xstream.toXML(foo)); • FooWriter.write("foo.xml", xml); • Convert from XML to Java • String xml = FooReader.read("foo.xml"); • Foo foo = xstream.fromXML(xml);
References • JavaWorld: • "Build, deploy, and test EJB components in just a few seconds, OpenEJB simplifies Enterprise JavaBeans development", by Nader Aeinehchi • http://www.javaworld.com/javaworld/jw-06-2005/jw-0613-ejb.html • OpenEJB: • http://www.openejb.org • JUnit: • http://www.junit.org • XStream: • http://xstream.codehaus.org/ • Eclipse: • http://www.eclipse.org • Oracle OC4J: • http://www.oracle.com/technology/tech/java/oc4j/index.html • "Container Driven Testing: Advanced EJB Testing with OpenEJB," N. Alex Rupp (TheServerSide.com, June 2004): • http://www.theserverside.com/articles/article.tss?l=ContainerDrivenTestingSeries • Getting Started with OpenEJB: • http://blog.ideoplex.com/software/2004/01/29.html#a768 • A Simple Entity Bean with OpenEJB: • http://blog.ideoplex.com/software/2004/03/31.html#a828 • Chapter 2, Java Naming and Directory Interface, from the Oracle9iAS Containers for J2EE Services Guide: • http://www.di.unipi.it/~ghelli/bdl/A97329_03/web.902/a95879/jndi.htm • For more articles on testing, browse the Testing section of JavaWorld's Topical Index: • http://www.javaworld.com/channel_content/jw-testing-index.shtml • For more articles on EJB, browse the Enterprise JavaBeans (EJB) section of JavaWorld's Topical Index: • http://www.javaworld.com/channel_content/jw-ejbs-index.shtml?
Demo • POJO development • EJB development