Author: rmannibucau
Date: Mon Oct 31 10:00:38 2011
New Revision: 1195386

URL: http://svn.apache.org/viewvc?rev=1195386&view=rev
Log:
adding cdi-events test

Added:
    openejb/trunk/openejb/examples/cdi-events/
    openejb/trunk/openejb/examples/cdi-events/pom.xml
    openejb/trunk/openejb/examples/cdi-events/src/
    openejb/trunk/openejb/examples/cdi-events/src/main/
    openejb/trunk/openejb/examples/cdi-events/src/main/java/
    openejb/trunk/openejb/examples/cdi-events/src/main/java/org/
    openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/
    openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/
    
openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/
    
openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
    openejb/trunk/openejb/examples/cdi-events/src/main/resources/
    openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/
    
openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/beans.xml
    openejb/trunk/openejb/examples/cdi-events/src/test/
    openejb/trunk/openejb/examples/cdi-events/src/test/java/
    openejb/trunk/openejb/examples/cdi-events/src/test/java/org/
    openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/
    openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/
    
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/
    
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
    
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
    openejb/trunk/openejb/examples/cdi-events/src/test/resources/
    openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/
    
openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/beans.xml
    openejb/trunk/openejb/examples/cdi-events/src/test/resources/log4j.xml
Modified:
    openejb/trunk/openejb/examples/pom.xml

Added: openejb/trunk/openejb/examples/cdi-events/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/pom.xml?rev=1195386&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-events/pom.xml (added)
+++ openejb/trunk/openejb/examples/cdi-events/pom.xml Mon Oct 31 10:00:38 2011
@@ -0,0 +1,111 @@
+<?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: 1178411 $ $Date: 2011-10-03 15:35:26 +0200 (lun. 03 oct. 2011) $ -->
+
+<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.superbiz</groupId>
+  <artifactId>cdi-events</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: CDI Events</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-3-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>4.0.0-beta-2-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- to show events we log them in the test -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.6.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.6.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.16</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>

Added: 
openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java?rev=1195386&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
 (added)
+++ 
openejb/trunk/openejb/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
 Mon Oct 31 10:00:38 2011
@@ -0,0 +1,36 @@
+/**
+ * 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.cdi.events;
+
+import javax.ejb.Schedule;
+import javax.ejb.Singleton;
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import java.util.Date;
+
+/**
+ * @author rmannibucau
+ */
+@Singleton
+public class Notifier {
+    @Inject private Event<Date> dateEvent;
+
+    @Schedule(second = "*", minute = "*", hour = "*")
+    public void sendHour() {
+        dateEvent.fire(new Date());
+    }
+}

Added: 
openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/beans.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/beans.xml?rev=1195386&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/beans.xml 
(added)
+++ 
openejb/trunk/openejb/examples/cdi-events/src/main/resources/META-INF/beans.xml 
Mon Oct 31 10:00:38 2011
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee";
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"; />

Added: 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java?rev=1195386&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
 (added)
+++ 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
 Mon Oct 31 10:00:38 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.cdi.events;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.NamingException;
+
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * @author rmannibucau
+ */
+public class EventTest {
+    private static EJBContainer container;
+    private static String initialLogProperty;
+
+    @Inject
+    private Observer observer;
+
+    @BeforeClass
+    public static void start() throws NamingException {
+        initialLogProperty = System.getProperty("openejb.logger.external");
+        System.setProperty("openejb.logger.external", "true");
+        container = EJBContainer.createEJBContainer();
+    }
+
+    @AfterClass
+    public static void shutdown() {
+        if (container != null) {
+            container.close();
+        }
+        if (initialLogProperty != null) {
+            System.setProperty("openejb.logger.external", initialLogProperty);
+        } else {
+            System.getProperties().remove("openejb.logger.external");
+        }
+    }
+
+    @Before
+    public void inject() throws NamingException {
+        container.getContext().bind("inject", this);
+    }
+
+    @After
+    public void reset() throws NamingException {
+        container.getContext().unbind("inject");
+    }
+
+    @Test
+    public void observe() throws InterruptedException {
+        Thread.sleep(4000);
+        assertTrue(observer.getDates().size() > 3); // in 4s normally at least 
3 events were received
+    }
+}

Added: 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java?rev=1195386&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
 (added)
+++ 
openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
 Mon Oct 31 10:00:38 2011
@@ -0,0 +1,45 @@
+/**
+ * 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.cdi.events;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.event.Observes;
+import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author rmannibucau
+ */
+@Singleton
+public class Observer {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(Observer.class);
+
+    private List<Date> dates = new ArrayList<Date>();
+
+    public void saveDate(@Observes Date date) {
+        dates.add(date);
+        LOGGER.info("received date '{}'", date);
+    }
+
+    public List<Date> getDates() {
+        return dates;
+    }
+}

Added: 
openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/beans.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/beans.xml?rev=1195386&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/beans.xml 
(added)
+++ 
openejb/trunk/openejb/examples/cdi-events/src/test/resources/META-INF/beans.xml 
Mon Oct 31 10:00:38 2011
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee";
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"; />

Added: openejb/trunk/openejb/examples/cdi-events/src/test/resources/log4j.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/test/resources/log4j.xml?rev=1195386&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-events/src/test/resources/log4j.xml 
(added)
+++ openejb/trunk/openejb/examples/cdi-events/src/test/resources/log4j.xml Mon 
Oct 31 10:00:38 2011
@@ -0,0 +1,42 @@
+<?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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"; 
debug="false">
+  <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{2}] %m%n"/>
+    </layout>
+  </appender>
+
+  <logger name="org.superbiz.cdi.events.Observer" additivity="false">
+    <level value="info"/>
+    <appender-ref ref="stdout"/>
+  </logger>
+  <logger name="org.apache" additivity="false">
+    <level value="info"/>
+    <appender-ref ref="stdout"/>
+  </logger>
+
+  <root>
+    <priority value="WARN"/>
+    <appender-ref ref="stdout"/>
+  </root>
+</log4j:configuration>

Modified: openejb/trunk/openejb/examples/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1195386&r1=1195385&r2=1195386&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Mon Oct 31 10:00:38 2011
@@ -90,6 +90,7 @@
     <module>cdi-produces-disposes</module>
     <module>dynamic-implementation</module>
     <module>cdi-alternative-and-stereotypes</module>
+    <module>cdi-events</module>
   </modules>
   <profiles>
     <profile>


Reply via email to