Author: dblevins
Date: Mon Nov 12 20:50:38 2007
New Revision: 594433
URL: http://svn.apache.org/viewvc?rev=594433&view=rev
Log:
Example in M2 and Ant of using OpenEJB for embedded testing, including wls
descriptors
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/
openejb/trunk/openejb3/examples/helloworld-weblogic/build.xml
openejb/trunk/openejb3/examples/helloworld-weblogic/pom.xml
openejb/trunk/openejb3/examples/helloworld-weblogic/src/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloBean.java
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocal.java
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocalHome.java
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/ejb-jar.xml
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/weblogic-ejb-jar.xml
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/HelloTest.java
Modified:
openejb/trunk/openejb3/examples/pom.xml
Added: openejb/trunk/openejb3/examples/helloworld-weblogic/build.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/build.xml?rev=594433&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/helloworld-weblogic/build.xml (added)
+++ openejb/trunk/openejb3/examples/helloworld-weblogic/build.xml Mon Nov 12
20:50:38 2007
@@ -0,0 +1,92 @@
+<project name="MyProject" default="dist" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+ <!-- ===============================================================
+
+ HOW TO RUN
+
+ Download
http://www.apache.org/dist/maven/binaries/maven-ant-tasks-2.0.7.jar
+ Then execute ant as follows:
+
+ ant -lib maven-ant-tasks-2.0.7.jar
+
+ NOTE
+
+ You do NOT need maven-ant-tasks-2.0.7.jar to use OpenEJB for embedded EJB
+ testing with Ant. It is simply used in this example to make the build.xml
+ a bit simpler. As long as OpenEJB and it's required libraries are in the
+ <junit> classpath, the tests will run with OpenEJB embedded.
+
+ ================================================================= -->
+
+ <artifact:remoteRepository id="apache.snapshot.repository"
url="http://people.apache.org/repo/m2-snapshot-repository/" />
+ <artifact:remoteRepository id="m2.repository"
url="http://repo1.maven.org/maven2/" />
+
+ <!-- Build Classpath -->
+ <artifact:dependencies pathId="classpath.main">
+ <dependency groupId="org.apache.geronimo.specs"
artifactId="geronimo-ejb_3.0_spec" version="1.0"/>
+ </artifact:dependencies>
+
+ <!-- Test Build Classpath -->
+ <artifact:dependencies pathId="classpath.test.build">
+ <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+ </artifact:dependencies>
+
+ <!-- Test Run Classpath -->
+ <artifact:dependencies pathId="classpath.test.run">
+ <remoteRepository refid="apache.snapshot.repository" />
+ <remoteRepository refid="m2.repository" />
+
+ <dependency groupId="org.apache.openejb" artifactId="openejb-core"
version="3.0.0-SNAPSHOT"/>
+ <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+ </artifact:dependencies>
+
+ <!-- Properties -->
+
+ <property name="src.main.java" location="src/main/java"/>
+ <property name="src.main.resources" location="src/main/resources"/>
+ <property name="src.test.java" location="src/test/java"/>
+ <property name="build.main" location="target/classes"/>
+ <property name="build.test" location="target/test-classes"/>
+ <property name="dist" location="target"/>
+
+
+ <target name="init">
+ <mkdir dir="${build.main}"/>
+ <mkdir dir="${build.test}"/>
+ </target>
+
+ <target name="compile" depends="init">
+
+ <javac srcdir="${src.main.java}" destdir="${build.main}">
+ <classpath refid="classpath.main" />
+ </javac>
+ <copy todir="${build.main}">
+ <fileset dir="${src.main.resources}"/>
+ </copy>
+
+ <javac srcdir="${src.test.java}" destdir="${build.test}">
+ <classpath location="${build.main}"/>
+ <classpath refid="classpath.main"/>
+ <classpath refid="classpath.test.build"/>
+ </javac>
+ </target>
+
+ <target name="test" depends="compile">
+ <junit fork="yes" printsummary="yes">
+ <classpath location="${build.main}"/>
+ <classpath location="${build.test}"/>
+ <classpath refid="classpath.main"/>
+ <classpath refid="classpath.test.build"/>
+ <classpath refid="classpath.test.run"/>
+
+ <formatter type="plain"/>
+
+ <test name="org.superbiz.hello.HelloTest"/>
+ </junit>
+ </target>
+
+ <target name="dist" depends="test">
+ <jar jarfile="${dist}/myproject-1.0.jar" basedir="${build.main}"/>
+ </target>
+
+</project>
Added: openejb/trunk/openejb3/examples/helloworld-weblogic/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/pom.xml?rev=594433&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/helloworld-weblogic/pom.xml (added)
+++ openejb/trunk/openejb3/examples/helloworld-weblogic/pom.xml Mon Nov 12
20:50:38 2007
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Rev: 580640 $ $Date: 2007-09-29 13:42:19 -0700 (Sat, 29 Sep 2007) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>helloworld-weblogic</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Hello World - Weblogic</name>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>codehaus-m2-snapshot</id>
+ <name>Codehaus Snapshot Repository</name>
+ <url>http://snapshots.repository.codehaus.org</url>
+ </repository>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://people.apache.org/repo/m2-snapshot-repository/</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.0_spec</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!--
+ Nice thing about maven2 is it has test-only dependencies.
+ This guarantees that non of your runtime code is dependent
+ on any OpenEJB classes.
+
+ For those of you who want to know the minimum steps required
+ to add OpenEJB for testing to an existing maven 2 build, you
+ simply add this dependency below and in your test code create
+ your InitialContext like such:
+
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
+
+ initialContext = new InitialContext(properties);
+
+ And include an add a src/main/resources/META-INF/ejb-jar.xml
+ file to your project containing at least "<ejb-jar/>"
+
+ There is a method for finding your app without the need for
+ an ejb-jar.xml via annotation scraping the classpath. See:
+ http://openejb.apache.org/loading-deployments-from-the-classpath.html
+ -->
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloBean.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloBean.java?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloBean.java
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloBean.java
Mon Nov 12 20:50:38 2007
@@ -0,0 +1,23 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2003 David Blevins. All rights reserved.
+ *
+ * =====================================================================
+ */
+package org.superbiz.hello;
+
+import javax.ejb.LocalHome;
+import javax.ejb.Stateless;
+
+/**
+ * @version $Revision$ $Date$
+ */
[EMAIL PROTECTED]
[EMAIL PROTECTED](HelloEjbLocalHome.class)
+public class HelloBean {
+
+ public String sayHello() {
+ return "Hello, World!";
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocal.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocal.java?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocal.java
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocal.java
Mon Nov 12 20:50:38 2007
@@ -0,0 +1,20 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2003 David Blevins. All rights reserved.
+ *
+ * =====================================================================
+ */
+package org.superbiz.hello;
+
+import javax.ejb.EJBLocalHome;
+import javax.ejb.CreateException;
+import javax.ejb.EJBLocalObject;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface HelloEjbLocal extends EJBLocalObject {
+
+ String sayHello();
+
+}
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocalHome.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocalHome.java?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocalHome.java
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/java/org/superbiz/hello/HelloEjbLocalHome.java
Mon Nov 12 20:50:38 2007
@@ -0,0 +1,17 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2003 David Blevins. All rights reserved.
+ *
+ * =====================================================================
+ */
+package org.superbiz.hello;
+
+import javax.ejb.EJBLocalHome;
+import javax.ejb.CreateException;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface HelloEjbLocalHome extends EJBLocalHome {
+ HelloEjbLocal create() throws CreateException;
+}
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/ejb-jar.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/ejb-jar.xml?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/ejb-jar.xml
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/ejb-jar.xml
Mon Nov 12 20:50:38 2007
@@ -0,0 +1 @@
+<ejb-jar/>
\ No newline at end of file
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/weblogic-ejb-jar.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/weblogic-ejb-jar.xml?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/weblogic-ejb-jar.xml
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/main/resources/META-INF/weblogic-ejb-jar.xml
Mon Nov 12 20:50:38 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 7.0.0
EJB//EN" "http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd">
+<weblogic-ejb-jar>
+ <weblogic-enterprise-bean>
+ <ejb-name>HelloBean</ejb-name>
+ <local-jndi-name>MyHello</local-jndi-name>
+ </weblogic-enterprise-bean>
+</weblogic-ejb-jar>
+
Added:
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/HelloTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/HelloTest.java?rev=594433&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/HelloTest.java
(added)
+++
openejb/trunk/openejb3/examples/helloworld-weblogic/src/test/java/org/superbiz/hello/HelloTest.java
Mon Nov 12 20:50:38 2007
@@ -0,0 +1,32 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2003 David Blevins. All rights reserved.
+ *
+ * =====================================================================
+ */
+package org.superbiz.hello;
+
+import junit.framework.TestCase;
+
+import javax.naming.InitialContext;
+import javax.naming.Context;
+import java.util.Properties;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class HelloTest extends TestCase {
+
+ public void test() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
+ InitialContext initialContext = new InitialContext(properties);
+
+ HelloEjbLocalHome localHome = (HelloEjbLocalHome)
initialContext.lookup("MyHello");
+ HelloEjbLocal helloEjb = localHome.create();
+
+ String message = helloEjb.sayHello();
+
+ assertEquals(message, "Hello, World!");
+ }
+}
Modified: openejb/trunk/openejb3/examples/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=594433&r1=594432&r2=594433&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Mon Nov 12 20:50:38 2007
@@ -31,6 +31,7 @@
<name>OpenEJB :: Examples</name>
<modules>
<module>helloworld-stateful-pojo</module>
+ <module>helloworld-weblogic</module>
<module>calculator-stateless-pojo</module>
<module>counter-stateful-pojo</module>
<module>ejb-injection</module>