You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2011/10/29 06:54:42 UTC

svn commit: r1190757 [9/15] - in /openejb/trunk/openejb/examples: access-timeout-meta/src/main/java/org/superbiz/accesstimeout/ alternate-descriptors/ application-composer/ applicationexception/ applicationexception/src/test/java/org/superbiz/appexcept...

Added: openejb/trunk/openejb/examples/spring-integration/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/spring-integration/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/spring-integration/README.md (added)
+++ openejb/trunk/openejb/examples/spring-integration/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,553 @@
+[INFO] Scanning for projects...
+[INFO]                                                                         
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Spring Integration 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO] 
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ spring-integration ---
+[INFO] Deleting /Users/dblevins/examples/spring-integration/target
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ spring-integration ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 3 resources
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ spring-integration ---
+[INFO] Compiling 8 source files to /Users/dblevins/examples/spring-integration/target/classes
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ spring-integration ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/spring-integration/src/test/resources
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ spring-integration ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/spring-integration/target/test-classes
+[INFO] 
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ spring-integration ---
+[INFO] Surefire report directory: /Users/dblevins/examples/spring-integration/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.spring.MoviesTest
+log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
+log4j:WARN Please initialize the log4j system properly.
+log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/spring-integration
+INFO - openejb.base = /Users/dblevins/examples/spring-integration
+INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory, type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
+INFO - Configuring Service(id=MovieDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Configuring Service(id=MovieDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/spring-integration/target/classes
+INFO - Beginning load: /Users/dblevins/examples/spring-integration/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/spring-integration/classpath.ear
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+INFO - Auto-creating a container for bean CineplexImpl: Container(type=STATELESS, id=Default Stateless Container)
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.spring.CineplexImpl/theaters' in bean CineplexImpl to Resource(id=theaters)
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container)
+INFO - Configuring PersistenceUnit(name=movie-unit, provider=org.hibernate.ejb.HibernatePersistence)
+INFO - Enterprise application "/Users/dblevins/examples/spring-integration/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/spring-integration/classpath.ear
+INFO - PersistenceUnit(name=movie-unit, provider=org.hibernate.ejb.HibernatePersistence) - provider time 672ms
+INFO - Jndi(name=CineplexImplLocal) --> Ejb(deployment-id=CineplexImpl)
+INFO - Jndi(name=global/classpath.ear/spring-integration/CineplexImpl!org.superbiz.spring.Cineplex) --> Ejb(deployment-id=CineplexImpl)
+INFO - Jndi(name=global/classpath.ear/spring-integration/CineplexImpl) --> Ejb(deployment-id=CineplexImpl)
+INFO - Jndi(name=MoviesLocal) --> Ejb(deployment-id=Movies)
+INFO - Jndi(name=global/classpath.ear/spring-integration/Movies!org.superbiz.spring.Movies) --> Ejb(deployment-id=Movies)
+INFO - Jndi(name=global/classpath.ear/spring-integration/Movies) --> Ejb(deployment-id=Movies)
+INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Created Ejb(deployment-id=CineplexImpl, ejb-name=CineplexImpl, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Started Ejb(deployment-id=CineplexImpl, ejb-name=CineplexImpl, container=Default Stateless Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/spring-integration/classpath.ear)
+INFO - Exported EJB Movies with interface org.superbiz.spring.Movies to Spring bean MoviesLocal
+INFO - Exported EJB Movies with interface org.superbiz.spring.Movies to Spring bean global/classpath.ear/spring-integration/Movies!org.superbiz.spring.Movies
+INFO - Exported EJB CineplexImpl with interface org.superbiz.spring.Cineplex to Spring bean CineplexImplLocal
+INFO - Exported EJB CineplexImpl with interface org.superbiz.spring.Cineplex to Spring bean global/classpath.ear/spring-integration/CineplexImpl!org.superbiz.spring.Cineplex
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.429 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO] 
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ spring-integration ---
+[INFO] Building jar: /Users/dblevins/examples/spring-integration/target/spring-integration-1.0.jar
+[INFO] 
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ spring-integration ---
+[INFO] Installing /Users/dblevins/examples/spring-integration/target/spring-integration-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/spring-integration/1.0/spring-integration-1.0.jar
+[INFO] Installing /Users/dblevins/examples/spring-integration/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/spring-integration/1.0/spring-integration-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 5.577s
+[INFO] Finished at: Fri Oct 28 17:09:39 PDT 2011
+[INFO] Final Memory: 15M/81M
+[INFO] ------------------------------------------------------------------------
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import javax.annotation.PostConstruct;
+    import javax.ejb.EJB;
+    import java.util.List;
+    
+    //START SNIPPET: code
+    
+    /**
+     * This is a simple Spring bean that we use as an easy way
+     * to seed the example with a list of persistent Movie objects
+     * <p/>
+     * The individual Movie objects are constructed by Spring, then
+     * passed into the Movies EJB where they are transactionally
+     * persisted with the EntityManager.
+     */
+    public class AvailableMovies {
+    
+        @EJB(name = "MoviesLocal")
+        private Movies moviesEjb;
+    
+        private List<Movie> movies;
+    
+        @PostConstruct
+        public void construct() throws Exception {
+            for (Movie movie : movies) {
+                moviesEjb.addMovie(movie);
+            }
+        }
+    
+        public List<Movie> getMovies() {
+            return movies;
+        }
+    
+        public void setMovies(List<Movie> movies) {
+            this.movies = movies;
+        }
+    
+        public void setMoviesEjb(Movies moviesEjb) {
+            this.moviesEjb = moviesEjb;
+        }
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import java.util.List;
+    
+    public interface Cineplex {
+    
+        public List<Theater> getTheaters();
+    
+    }
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import javax.annotation.Resource;
+    import javax.ejb.Stateless;
+    import java.util.List;
+    
+    //START SNIPPET: code
+    
+    @Stateless
+    public class CineplexImpl implements Cineplex {
+    
+        /**
+         * The Theaters Spring bean will be injected
+         */
+        @Resource
+        private Theaters theaters;
+    
+        public List<Theater> getTheaters() {
+            return theaters.getTheaters();
+        }
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import javax.persistence.Entity;
+    import javax.persistence.GeneratedValue;
+    import javax.persistence.GenerationType;
+    import javax.persistence.Id;
+    
+    @Entity
+    public class Movie {
+    
+        @Id
+        @GeneratedValue(strategy = GenerationType.AUTO)
+        private long id;
+    
+        private String director;
+        private String title;
+        private int year;
+    
+        public Movie() {
+        }
+    
+        public Movie(String director, String title, int year) {
+            this.director = director;
+            this.title = title;
+            this.year = year;
+        }
+    
+        public String getDirector() {
+            return director;
+        }
+    
+        public void setDirector(String director) {
+            this.director = director;
+        }
+    
+        public String getTitle() {
+            return title;
+        }
+    
+        public void setTitle(String title) {
+            this.title = title;
+        }
+    
+        public int getYear() {
+            return year;
+        }
+    
+        public void setYear(int year) {
+            this.year = year;
+        }
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import java.util.List;
+    
+    public interface Movies {
+        void addMovie(Movie movie) throws Exception;
+    
+        void deleteMovie(Movie movie) throws Exception;
+    
+        List<Movie> getMovies() throws Exception;
+    
+        Movie getMovieByTitle(String title) throws Exception;
+    }
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import javax.ejb.Stateful;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
+    import javax.persistence.PersistenceContextType;
+    import javax.persistence.Query;
+    import java.util.List;
+    
+    //START SNIPPET: code
+    
+    /**
+     * A normal Stateful EJB that uses a JPA EntityManager.
+     * <p/>
+     * We use this bean to transactionally wrap access to the
+     * EntityManager persist, remove, and query methods.
+     */
+    @Stateful(name = "Movies")
+    public class MoviesImpl implements Movies {
+    
+        @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
+        private EntityManager entityManager;
+    
+        public void addMovie(Movie movie) throws Exception {
+            entityManager.persist(movie);
+        }
+    
+        public void deleteMovie(Movie movie) throws Exception {
+            entityManager.remove(movie);
+        }
+    
+        public List<Movie> getMovies() throws Exception {
+            Query query = entityManager.createQuery("SELECT m from Movie as m");
+            return query.getResultList();
+        }
+    
+        public Movie getMovieByTitle(String title) throws Exception {
+            Query query = entityManager.createQuery("SELECT m from Movie as m where m.title = ?1");
+            query.setParameter(1, title);
+            return (Movie) query.getSingleResult();
+        }
+    
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import javax.inject.Inject;
+    import javax.inject.Named;
+    import org.springframework.beans.factory.annotation.Autowired;
+    
+    import java.util.ArrayList;
+    import java.util.List;
+    
+    //START SNIPPET: code
+    
+    /**
+     * Spring bean that references the Movies EJB and the Movie JPA bean.
+     * <p/>
+     * This bean shows that Spring beans can have references to EJBs.
+     */
+    public class Theater {
+    
+        /**
+         * The Movies @Stateless EJB
+         */
+        private final Movies movies;
+    
+        private final List<Movie> nowPlaying = new ArrayList<Movie>();
+    
+        /**
+         * The Movies EJB is passed in on the constructor which
+         * guarantees we can use it in the setNowPlaying method.
+         *
+         * @param movies
+         */
+        @Inject @Named(value = "MoviesLocal")
+        public Theater(Movies movies) {
+            this.movies = movies;
+        }
+    
+        /**
+         * For every title in the list we will use the Movies EJB
+         * to lookup the actual Movie JPA object.
+         *
+         * @param nowPlaying
+         * @throws Exception
+         */
+        public void setNowPlaying(List<String> nowPlaying) throws Exception {
+            for (String title : nowPlaying) {
+                this.nowPlaying.add(movies.getMovieByTitle(title));
+            }
+        }
+    
+        public List<Movie> getMovies() throws Exception {
+            return nowPlaying;
+        }
+    }
+    //END SNIPPET: code
+    
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import java.util.List;
+    
+    /**
+     * Injection of collections of Spring beans into an EJB
+     * is not yet supported, so this Spring bean exists to
+     * wrap the collection as an injectable object.
+     */
+    public class Theaters {
+    
+        private List<Theater> theaters;
+    
+        public List<Theater> getTheaters() {
+            return theaters;
+        }
+    
+        public void setTheaters(List<Theater> theaters) {
+            this.theaters = theaters;
+        }
+    
+    }
+    /**
+     * 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.
+     */
+    package org.superbiz.spring;
+    
+    import junit.framework.TestCase;
+    import org.springframework.context.support.ClassPathXmlApplicationContext;
+    
+    import java.util.List;
+    
+    //START SNIPPET: code
+    public class MoviesTest extends TestCase {
+    
+        public void test() throws Exception {
+    
+            //Uncomment for debug logging
+            //org.apache.log4j.BasicConfigurator.configure();
+    
+            System.setProperty("openejb.deployments.classpath.include", ".*/spring-integration.*");
+    
+            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("movies.xml");
+    
+            // Can I lookup the Cineplex EJB via the Spring ApplicationContext
+            Cineplex cineplex = (Cineplex) context.getBean("CineplexImplLocal");
+            assertNotNull(cineplex);
+    
+            // Does the Cineplex EJB have a reference to the Theaters Spring bean?
+            List<Theater> theaters = cineplex.getTheaters();
+            assertNotNull(theaters);
+    
+            assertEquals(2, theaters.size());
+    
+            Theater theaterOne = theaters.get(0);
+            Theater theaterTwo = theaters.get(1);
+    
+    
+            // Were the Theater Spring beans able to use the
+            // Movies EJB to get references to the Movie JPA objects?
+            List<Movie> theaterOneMovies = theaterOne.getMovies();
+            assertNotNull(theaterOneMovies);
+    
+            List<Movie> theaterTwoMovies = theaterTwo.getMovies();
+            assertNotNull(theaterTwoMovies);
+    
+            // The first Theater should have used the Movies EJB
+            // to get a reference to three Movie JPA objects
+            assertEquals(3, theaterOneMovies.size());
+    
+            assertEquals("Fargo", theaterOneMovies.get(0).getTitle());
+            assertEquals("Reservoir Dogs", theaterOneMovies.get(1).getTitle());
+            assertEquals("The Big Lebowski", theaterOneMovies.get(2).getTitle());
+    
+            // The second Theater should have used the Movies EJB
+            // to get a reference to four Movie JPA objects
+    
+            assertEquals(4, theaterTwoMovies.size());
+    
+            assertEquals("You, Me and Dupree", theaterTwoMovies.get(0).getTitle());
+            assertEquals("Wedding Crashers", theaterTwoMovies.get(1).getTitle());
+            assertEquals("Zoolander", theaterTwoMovies.get(2).getTitle());
+            assertEquals("Shanghai Noon", theaterTwoMovies.get(3).getTitle());
+        }
+    }
+    //END SNIPPET: code

Added: openejb/trunk/openejb/examples/telephone-stateful/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/telephone-stateful/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/telephone-stateful/README.md (added)
+++ openejb/trunk/openejb/examples/telephone-stateful/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,275 @@
+[INFO] Scanning for projects...
+[INFO]                                                                         
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Telephone Stateful Pojo 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO] 
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ telephone-stateful ---
+[INFO] Deleting /Users/dblevins/examples/telephone-stateful/target
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ telephone-stateful ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ telephone-stateful ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/telephone-stateful/target/classes
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ telephone-stateful ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/telephone-stateful/src/test/resources
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ telephone-stateful ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/telephone-stateful/target/test-classes
+[INFO] 
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ telephone-stateful ---
+[INFO] Surefire report directory: /Users/dblevins/examples/telephone-stateful/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.telephone.TelephoneTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/telephone-stateful
+INFO - openejb.base = /Users/dblevins/examples/telephone-stateful
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/telephone-stateful/target/classes
+INFO - Beginning load: /Users/dblevins/examples/telephone-stateful/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/telephone-stateful/classpath.ear
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+INFO - Auto-creating a container for bean TelephoneBean: Container(type=STATEFUL, id=Default Stateful Container)
+INFO - Enterprise application "/Users/dblevins/examples/telephone-stateful/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/telephone-stateful/classpath.ear
+INFO - Jndi(name=TelephoneBeanRemote) --> Ejb(deployment-id=TelephoneBean)
+INFO - Jndi(name=global/classpath.ear/telephone-stateful/TelephoneBean!org.superbiz.telephone.Telephone) --> Ejb(deployment-id=TelephoneBean)
+INFO - Jndi(name=global/classpath.ear/telephone-stateful/TelephoneBean) --> Ejb(deployment-id=TelephoneBean)
+INFO - Created Ejb(deployment-id=TelephoneBean, ejb-name=TelephoneBean, container=Default Stateful Container)
+INFO - Started Ejb(deployment-id=TelephoneBean, ejb-name=TelephoneBean, container=Default Stateful Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/telephone-stateful/classpath.ear)
+INFO - Initializing network services
+INFO - Creating ServerService(id=admin)
+INFO - Creating ServerService(id=ejbd)
+INFO - Creating ServerService(id=ejbds)
+INFO - Initializing network services
+  ** Starting Services **
+  NAME                 IP              PORT  
+  admin thread         127.0.0.1       4200  
+  ejbd                 127.0.0.1       4201  
+  ejbd                 127.0.0.1       4203  
+-------
+Ready!
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.412 sec
+
+Results :
+
+Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO] 
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ telephone-stateful ---
+[INFO] Building jar: /Users/dblevins/examples/telephone-stateful/target/telephone-stateful-1.0.jar
+[INFO] 
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ telephone-stateful ---
+[INFO] Installing /Users/dblevins/examples/telephone-stateful/target/telephone-stateful-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/telephone-stateful/1.0/telephone-stateful-1.0.jar
+[INFO] Installing /Users/dblevins/examples/telephone-stateful/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/telephone-stateful/1.0/telephone-stateful-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 4.641s
+[INFO] Finished at: Fri Oct 28 17:02:08 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+    /**
+     * 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.
+     */
+    //START SNIPPET: code
+    package org.superbiz.telephone;
+    
+    public interface Telephone {
+    
+        void speak(String words);
+    
+        String listen();
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    //START SNIPPET: code
+    package org.superbiz.telephone;
+    
+    import javax.ejb.Remote;
+    import javax.ejb.Stateful;
+    import java.util.ArrayList;
+    import java.util.List;
+    
+    @Remote
+    @Stateful
+    public class TelephoneBean implements Telephone {
+    
+        private static final String[] answers = {
+                "How nice.",
+                "Oh, of course.",
+                "Interesting.",
+                "Really?",
+                "No.",
+                "Definitely.",
+                "I wondered about that.",
+                "Good idea.",
+                "You don't say!",
+        };
+    
+        private List<String> conversation = new ArrayList<String>();
+    
+        public void speak(String words) {
+            conversation.add(words);
+        }
+    
+        public String listen() {
+            if (conversation.size() == 0) {
+                return "Nothing has been said";
+            }
+    
+            String lastThingSaid = conversation.get(conversation.size() - 1);
+            return answers[Math.abs(lastThingSaid.hashCode()) % answers.length];
+        }
+    }
+    //END SNIPPET: code/**
+     * 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.
+     */
+    package org.superbiz.telephone;
+    
+    import junit.framework.TestCase;
+    
+    import javax.naming.Context;
+    import javax.naming.InitialContext;
+    import java.util.Properties;
+    
+    /**
+     * @version $Rev: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) $
+     */
+    public class TelephoneTest extends TestCase {
+    
+        //START SNIPPET: setup
+    
+        protected void setUp() throws Exception {
+            Properties properties = new Properties();
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+            properties.setProperty("openejb.embedded.remotable", "true");
+            // Uncomment these properties to change the defaults
+            //properties.setProperty("ejbd.port", "4202");
+            //properties.setProperty("ejbd.bind", "localhost");
+            //properties.setProperty("ejbd.threads", "200");
+            //properties.setProperty("ejbd.disabled", "false");
+            //properties.setProperty("ejbd.only_from", "127.0.0.1,192.168.1.1");
+    
+            new InitialContext(properties);
+        }
+        //END SNIPPET: setup
+    
+        /**
+         * Lookup the Telephone bean via its remote interface but using the LocalInitialContextFactory
+         *
+         * @throws Exception
+         */
+        //START SNIPPET: localcontext
+        public void testTalkOverLocalNetwork() throws Exception {
+    
+            Properties properties = new Properties();
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+            InitialContext localContext = new InitialContext(properties);
+    
+            Telephone telephone = (Telephone) localContext.lookup("TelephoneBeanRemote");
+    
+            telephone.speak("Did you know I am talking directly through the embedded container?");
+    
+            assertEquals("Interesting.", telephone.listen());
+    
+    
+            telephone.speak("Yep, I'm using the bean's remote interface but since the ejb container is embedded " +
+                    "in the same vm I'm just using the LocalInitialContextFactory.");
+    
+            assertEquals("Really?", telephone.listen());
+    
+    
+            telephone.speak("Right, you really only have to use the RemoteInitialContextFactory if you're in a different vm.");
+    
+            assertEquals("Oh, of course.", telephone.listen());
+        }
+        //END SNIPPET: localcontext
+    
+        /**
+         * Lookup the Telephone bean via its remote interface using the RemoteInitialContextFactory
+         *
+         * @throws Exception
+         */
+        //START SNIPPET: remotecontext
+        public void testTalkOverRemoteNetwork() throws Exception {
+            Properties properties = new Properties();
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
+            properties.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201");
+            InitialContext remoteContext = new InitialContext(properties);
+    
+            Telephone telephone = (Telephone) remoteContext.lookup("TelephoneBeanRemote");
+    
+            telephone.speak("Is this a local call?");
+    
+            assertEquals("No.", telephone.listen());
+    
+    
+            telephone.speak("This would be a lot cooler if I was connecting from another VM then, huh?");
+    
+            assertEquals("I wondered about that.", telephone.listen());
+    
+    
+            telephone.speak("I suppose I should hangup and call back over the LocalInitialContextFactory.");
+    
+            assertEquals("Good idea.", telephone.listen());
+    
+    
+            telephone.speak("I'll remember this though in case I ever have to call you accross a network.");
+    
+            assertEquals("Definitely.", telephone.listen());
+        }
+        //END SNIPPET: remotecontext
+    
+    }

Added: openejb/trunk/openejb/examples/testcase-injection/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/testcase-injection/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/testcase-injection/README.md (added)
+++ openejb/trunk/openejb/examples/testcase-injection/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,270 @@
+[INFO] Scanning for projects...
+[INFO]                                                                         
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: TestCase Injection 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO] 
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ testcase-injection ---
+[INFO] Deleting /Users/dblevins/examples/testcase-injection/target
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ testcase-injection ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ testcase-injection ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/testcase-injection/target/classes
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ testcase-injection ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] skip non existing resourceDirectory /Users/dblevins/examples/testcase-injection/src/test/resources
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ testcase-injection ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/testcase-injection/target/test-classes
+[INFO] 
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ testcase-injection ---
+[INFO] Surefire report directory: /Users/dblevins/examples/testcase-injection/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.testinjection.MoviesTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/testcase-injection
+INFO - openejb.base = /Users/dblevins/examples/testcase-injection
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/testcase-injection/target/classes
+INFO - Beginning load: /Users/dblevins/examples/testcase-injection/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/testcase-injection
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container)
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.testinjection.MoviesTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Configuring PersistenceUnit(name=movie-unit)
+INFO - Auto-creating a Resource with id 'movieDatabaseNonJta' of type 'DataSource for 'movie-unit'.
+INFO - Configuring Service(id=movieDatabaseNonJta, type=Resource, provider-id=movieDatabase)
+INFO - Adjusting PersistenceUnit movie-unit <non-jta-data-source> to Resource ID 'movieDatabaseNonJta' from 'movieDatabaseUnmanaged'
+INFO - Enterprise application "/Users/dblevins/examples/testcase-injection" loaded.
+INFO - Assembling app: /Users/dblevins/examples/testcase-injection
+INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 405ms
+INFO - Jndi(name="java:global/testcase-injection/Movies!org.superbiz.testinjection.Movies")
+INFO - Jndi(name="java:global/testcase-injection/Movies")
+INFO - Jndi(name="java:global/EjbModule713732239/org.superbiz.testinjection.MoviesTest!org.superbiz.testinjection.MoviesTest")
+INFO - Jndi(name="java:global/EjbModule713732239/org.superbiz.testinjection.MoviesTest")
+INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Created Ejb(deployment-id=org.superbiz.testinjection.MoviesTest, ejb-name=org.superbiz.testinjection.MoviesTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Started Ejb(deployment-id=org.superbiz.testinjection.MoviesTest, ejb-name=org.superbiz.testinjection.MoviesTest, container=Default Managed Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/testcase-injection)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.239 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO] 
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ testcase-injection ---
+[INFO] Building jar: /Users/dblevins/examples/testcase-injection/target/testcase-injection-1.0.jar
+[INFO] 
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ testcase-injection ---
+[INFO] Installing /Users/dblevins/examples/testcase-injection/target/testcase-injection-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/testcase-injection/1.0/testcase-injection-1.0.jar
+[INFO] Installing /Users/dblevins/examples/testcase-injection/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/testcase-injection/1.0/testcase-injection-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 5.326s
+[INFO] Finished at: Fri Oct 28 17:08:21 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+    /**
+     * 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.
+     */
+    package org.superbiz.testinjection;
+    
+    import javax.persistence.Entity;
+    
+    @Entity
+    public class Movie {
+    
+        private String director;
+        private String title;
+        private int year;
+    
+        public Movie() {
+        }
+    
+        public Movie(String director, String title, int year) {
+            this.director = director;
+            this.title = title;
+            this.year = year;
+        }
+    
+        public String getDirector() {
+            return director;
+        }
+    
+        public void setDirector(String director) {
+            this.director = director;
+        }
+    
+        public String getTitle() {
+            return title;
+        }
+    
+        public void setTitle(String title) {
+            this.title = title;
+        }
+    
+        public int getYear() {
+            return year;
+        }
+    
+        public void setYear(int year) {
+            this.year = year;
+        }
+    
+    
+    }
+    /**
+     * 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.
+     */
+    package org.superbiz.testinjection;
+    
+    import javax.ejb.Stateful;
+    import javax.ejb.TransactionAttribute;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
+    import javax.persistence.PersistenceContextType;
+    import javax.persistence.Query;
+    import java.util.List;
+    
+    import static javax.ejb.TransactionAttributeType.MANDATORY;
+    
+    //START SNIPPET: code
+    @Stateful
+    @TransactionAttribute(MANDATORY)
+    public class Movies {
+    
+        @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION)
+        private EntityManager entityManager;
+    
+        public void addMovie(Movie movie) throws Exception {
+            entityManager.persist(movie);
+        }
+    
+        public void deleteMovie(Movie movie) throws Exception {
+            entityManager.remove(movie);
+        }
+    
+        public List<Movie> getMovies() throws Exception {
+            Query query = entityManager.createQuery("SELECT m from Movie as m");
+            return query.getResultList();
+        }
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.testinjection;
+    
+    import junit.framework.TestCase;
+    
+    import javax.annotation.Resource;
+    import javax.ejb.EJB;
+    import javax.ejb.embeddable.EJBContainer;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
+    import javax.transaction.UserTransaction;
+    import java.util.List;
+    import java.util.Properties;
+    
+    //START SNIPPET: code
+    public class MoviesTest extends TestCase {
+    
+        @EJB
+        private Movies movies;
+    
+        @Resource
+        private UserTransaction userTransaction;
+    
+        @PersistenceContext
+        private EntityManager entityManager;
+    
+        public void setUp() throws Exception {
+            Properties p = new Properties();
+            p.put("movieDatabase", "new://Resource?type=DataSource");
+            p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+            p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+    
+            EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        }
+    
+        public void test() throws Exception {
+    
+            userTransaction.begin();
+    
+            try {
+                entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
+                entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
+                entityManager.persist(new Movie("Joel Coen", "The Big Lebowski", 1998));
+    
+                List<Movie> list = movies.getMovies();
+                assertEquals("List.size()", 3, list.size());
+    
+                for (Movie movie : list) {
+                    movies.deleteMovie(movie);
+                }
+    
+                assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+    
+            } finally {
+                userTransaction.commit();
+            }
+    
+    
+        }
+    }
+    //END SNIPPET: code

Added: openejb/trunk/openejb/examples/testing-security-2/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/testing-security-2/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/testing-security-2/README.md (added)
+++ openejb/trunk/openejb/examples/testing-security-2/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,336 @@
+[INFO] Scanning for projects...
+[INFO]                                                                         
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Testing Security 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO] 
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ testing-security-2 ---
+[INFO] Deleting /Users/dblevins/examples/testing-security-2/target
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ testing-security-2 ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 1 resource
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ testing-security-2 ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/testing-security-2/target/classes
+[INFO] 
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ testing-security-2 ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 2 resources
+[INFO] 
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ testing-security-2 ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/testing-security-2/target/test-classes
+[INFO] 
+[INFO] --- maven-surefire-plugin:2.6:test (default-test) @ testing-security-2 ---
+[INFO] Surefire report directory: /Users/dblevins/examples/testing-security-2/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.injection.secure.MovieTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/testing-security-2
+INFO - openejb.base = /Users/dblevins/examples/testing-security-2
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/testing-security-2/target/classes
+INFO - Beginning load: /Users/dblevins/examples/testing-security-2/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/testing-security-2
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container)
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.injection.secure.MovieTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Configuring PersistenceUnit(name=movie-unit)
+INFO - Auto-creating a Resource with id 'movieDatabaseNonJta' of type 'DataSource for 'movie-unit'.
+INFO - Configuring Service(id=movieDatabaseNonJta, type=Resource, provider-id=movieDatabase)
+INFO - Adjusting PersistenceUnit movie-unit <non-jta-data-source> to Resource ID 'movieDatabaseNonJta' from 'movieDatabaseUnmanaged'
+INFO - Enterprise application "/Users/dblevins/examples/testing-security-2" loaded.
+INFO - Assembling app: /Users/dblevins/examples/testing-security-2
+INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 411ms
+INFO - Jndi(name="java:global/testing-security-2/Movies!org.superbiz.injection.secure.Movies")
+INFO - Jndi(name="java:global/testing-security-2/Movies")
+INFO - Jndi(name="java:global/EjbModule236054577/org.superbiz.injection.secure.MovieTest!org.superbiz.injection.secure.MovieTest")
+INFO - Jndi(name="java:global/EjbModule236054577/org.superbiz.injection.secure.MovieTest")
+INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Created Ejb(deployment-id=org.superbiz.injection.secure.MovieTest, ejb-name=org.superbiz.injection.secure.MovieTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container)
+INFO - Started Ejb(deployment-id=org.superbiz.injection.secure.MovieTest, ejb-name=org.superbiz.injection.secure.MovieTest, container=Default Managed Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/testing-security-2)
+INFO - Logging in
+INFO - Logging out
+INFO - EJBContainer already initialized.  Call ejbContainer.close() to allow reinitialization
+INFO - Logging in
+INFO - Logging out
+INFO - EJBContainer already initialized.  Call ejbContainer.close() to allow reinitialization
+Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.39 sec
+
+Results :
+
+Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO] 
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ testing-security-2 ---
+[INFO] Building jar: /Users/dblevins/examples/testing-security-2/target/testing-security-2-1.0.jar
+[INFO] 
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ testing-security-2 ---
+[INFO] Installing /Users/dblevins/examples/testing-security-2/target/testing-security-2-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/testing-security-2/1.0/testing-security-2-1.0.jar
+[INFO] Installing /Users/dblevins/examples/testing-security-2/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/testing-security-2/1.0/testing-security-2-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 5.300s
+[INFO] Finished at: Fri Oct 28 16:59:09 PDT 2011
+[INFO] Final Memory: 14M/81M
+[INFO] ------------------------------------------------------------------------
+    /**
+     * 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.
+     */
+    package org.superbiz.injection.secure;
+    
+    import javax.persistence.Entity;
+    
+    @Entity
+    public class Movie {
+    
+        private String director;
+        private String title;
+        private int year;
+    
+        public Movie() {
+        }
+    
+        public Movie(String director, String title, int year) {
+            this.director = director;
+            this.title = title;
+            this.year = year;
+        }
+    
+        public String getDirector() {
+            return director;
+        }
+    
+        public void setDirector(String director) {
+            this.director = director;
+        }
+    
+        public String getTitle() {
+            return title;
+        }
+    
+        public void setTitle(String title) {
+            this.title = title;
+        }
+    
+        public int getYear() {
+            return year;
+        }
+    
+        public void setYear(int year) {
+            this.year = year;
+        }
+    
+    
+    }
+    /**
+     * 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.
+     */
+    package org.superbiz.injection.secure;
+    
+    //START SNIPPET: code
+    
+    import javax.annotation.security.PermitAll;
+    import javax.annotation.security.RolesAllowed;
+    import javax.ejb.Stateful;
+    import javax.ejb.TransactionAttribute;
+    import javax.ejb.TransactionAttributeType;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
+    import javax.persistence.PersistenceContextType;
+    import javax.persistence.Query;
+    import java.util.List;
+    
+    @Stateful
+    public class Movies  {
+    
+        @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
+        private EntityManager entityManager;
+    
+        @RolesAllowed({"Employee", "Manager"})
+        public void addMovie(Movie movie) throws Exception {
+            entityManager.persist(movie);
+        }
+    
+        @RolesAllowed({"Manager"})
+        public void deleteMovie(Movie movie) throws Exception {
+            entityManager.remove(movie);
+        }
+    
+        @PermitAll
+        @TransactionAttribute(TransactionAttributeType.SUPPORTS)
+        public List<Movie> getMovies() throws Exception {
+            Query query = entityManager.createQuery("SELECT m from Movie as m");
+            return query.getResultList();
+        }
+    }
+    //END SNIPPET: code
+    /**
+     * 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.
+     */
+    package org.superbiz.injection.secure;
+    
+    import junit.framework.TestCase;
+    
+    import javax.ejb.EJB;
+    import javax.ejb.EJBAccessException;
+    import javax.ejb.embeddable.EJBContainer;
+    import javax.naming.Context;
+    import javax.naming.InitialContext;
+    import java.util.List;
+    import java.util.Properties;
+    
+    //START SNIPPET: code
+    public class MovieTest extends TestCase {
+    
+        @EJB
+        private Movies movies;
+    
+        protected void setUp() throws Exception {
+    
+            // Uncomment this line to set the login/logout functionality on Debug
+            //System.setProperty("log4j.category.OpenEJB.security", "debug");
+    
+            Properties p = new Properties();
+            p.put("movieDatabase", "new://Resource?type=DataSource");
+            p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+            p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+    
+            EJBContainer.createEJBContainer(p).getContext().bind("inject", this);
+        }
+    
+        public void testAsManager() throws Exception {
+            Properties p = new Properties();
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+            p.put(Context.SECURITY_PRINCIPAL, "jane");
+            p.put(Context.SECURITY_CREDENTIALS, "waterfall");
+    
+            InitialContext context = new InitialContext(p);
+    
+            try {
+                movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
+                movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
+                movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
+    
+                List<Movie> list = movies.getMovies();
+                assertEquals("List.size()", 3, list.size());
+    
+                for (Movie movie : list) {
+                    movies.deleteMovie(movie);
+                }
+    
+                assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
+            } finally {
+                context.close();
+            }
+        }
+    
+        public void testAsEmployee() throws Exception {
+            Properties p = new Properties();
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+            p.put(Context.SECURITY_PRINCIPAL, "joe");
+            p.put(Context.SECURITY_CREDENTIALS, "cool");
+    
+            InitialContext context = new InitialContext(p);
+    
+            try {
+                movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
+                movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
+                movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
+    
+                List<Movie> list = movies.getMovies();
+                assertEquals("List.size()", 3, list.size());
+    
+                for (Movie movie : list) {
+                    try {
+                        movies.deleteMovie(movie);
+                        fail("Employees should not be allowed to delete");
+                    } catch (EJBAccessException e) {
+                        // Good, Employees cannot delete things
+                    }
+                }
+    
+                // The list should still be three movies long
+                assertEquals("Movies.getMovies()", 3, movies.getMovies().size());
+            } finally {
+                context.close();
+            }
+        }
+    
+        public void testUnauthenticated() throws Exception {
+            try {
+                movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
+                fail("Unauthenticated users should not be able to add movies");
+            } catch (EJBAccessException e) {
+                // Good, guests cannot add things
+            }
+    
+            try {
+                movies.deleteMovie(null);
+                fail("Unauthenticated users should not be allowed to delete");
+            } catch (EJBAccessException e) {
+                // Good, Unauthenticated users cannot delete things
+            }
+    
+            try {
+                // Read access should be allowed
+    
+                List<Movie> list = movies.getMovies();
+    
+            } catch (EJBAccessException e) {
+                fail("Read access should be allowed");
+            }
+    
+        }
+    }
+    //END SNIPPET: code