Author: jlmonteiro
Date: Fri Aug 19 13:18:53 2011
New Revision: 1159626
URL: http://svn.apache.org/viewvc?rev=1159626&view=rev
Log:
OPENEJB-1613 Example: @Produces and @Disposes for "smart" construction and
destruction of beans
Thanks Rangarajan Sreenivasan!
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/
openejb/trunk/openejb3/examples/cdi-produces-disposes/README.txt
openejb/trunk/openejb3/examples/cdi-produces-disposes/pom.xml
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
openejb/trunk/openejb3/examples/cdi-produces-disposes/target/
Modified:
openejb/trunk/openejb3/examples/pom.xml
Added: openejb/trunk/openejb3/examples/cdi-produces-disposes/README.txt
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/README.txt?rev=1159626&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-produces-disposes/README.txt (added)
+++ openejb/trunk/openejb3/examples/cdi-produces-disposes/README.txt Fri Aug 19
13:18:53 2011
@@ -0,0 +1,18 @@
+This example shows how to use the concept of CDI in a simple POJO context
+
+This functionality is often referred as dependency injection (see
+http://www.martinfowler.com/articles/injection.html), and has been recently
introduced in
+Java EE 5.
+
+This example shows how the @Produces and @Disposes annotations work. A
LogFactory creates an instance of the LogHandler
+depending on a "type" attribute. For the purposes of this example, the type is
hard-coded to a specific value.
+A Logger implementation shall contain a list of LogHandlers. We shall have
three implementations of the LogHandler interface.
+
+ * A DatabaseHandler
+ * A FileHandler
+ * A ConsoleHandler
+
+The DatabaseHandler would seemingly write the logs to a database. The
FileHandler would write the same logs to a file.
+The ConsoleHandler would just print the logs to a console (Standard out). This
example is just an illustration of how
+the concepts within CDI work and is not intended to provide a logging
framework design/implementation.
+
Added: openejb/trunk/openejb3/examples/cdi-produces-disposes/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/pom.xml?rev=1159626&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-produces-disposes/pom.xml (added)
+++ openejb/trunk/openejb3/examples/cdi-produces-disposes/pom.xml Fri Aug 19
13:18:53 2011
@@ -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: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 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-produces-disposes</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: CDI-Disposes</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-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-SNAPSHOT</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/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.produces.disposes;
+
+public class ConsoleHandler implements LogHandler {
+
+ private String name;
+
+ public ConsoleHandler (String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void writeLog(String s) {
+ System.out.printf("##### Handler: %s, Writing to the console!\n",
getName());
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,38 @@
+/**
+ * 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.produces.disposes;
+
+public class DatabaseHandler implements LogHandler {
+
+ private String name;
+
+ public DatabaseHandler (String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void writeLog(String s) {
+ System.out.printf("##### Handler: %s, Writing to the database!\n",
getName());
+ // Use connection to write log to database
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,38 @@
+/**
+ * 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.produces.disposes;
+
+public class FileHandler implements LogHandler {
+
+ private String name;
+
+ public FileHandler (String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void writeLog(String s) {
+ System.out.printf("##### Handler: %s, Writing to the file!\n",
getName());
+ // Write to log file
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,54 @@
+/**
+ * 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.produces.disposes;
+
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+
+public class LogFactory {
+
+ private int type = 2;
+
+ @Produces
+ public LogHandler getLogHandler() {
+ switch (type) {
+ case 1:
+ return new FileHandler("@Produces created FileHandler!");
+ case 2:
+ return new DatabaseHandler("@Produces created
DatabaseHandler!");
+ case 3:
+ default:
+ return new ConsoleHandler("@Produces created ConsoleHandler!");
+ }
+
+ }
+
+ public void closeLogHandler (@Disposes LogHandler handler) {
+ switch (type) {
+ case 1:
+ System.out.println("Closing File handler!");
+ break;
+ case 2:
+ System.out.println("Closing DB handler!");
+ break;
+ case 3:
+ default:
+ System.out.println("Closing Console handler!");
+ }
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,25 @@
+/**
+ * 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.produces.disposes;
+
+public interface LogHandler {
+
+ public String getName();
+
+ public void writeLog(String s);
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,25 @@
+/**
+ * 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.produces.disposes;
+
+public interface Logger {
+
+ public void log (String s);
+
+ public LogHandler getHandler();
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.produces.disposes;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named("logger")
+public class LoggerImpl implements Logger {
+
+ @Inject
+ private LogHandler handler;
+
+ @Override
+ public void log(String s) {
+ getHandler().writeLog(s);
+ }
+
+ public LogHandler getHandler() {
+ return handler;
+ }
+
+}
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/beans.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/beans.xml?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/beans.xml
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/main/resources/META-INF/beans.xml
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,24 @@
+<?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.
+-->
+<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">
+
+</beans>
\ No newline at end of file
Added:
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java?rev=1159626&view=auto
==============================================================================
---
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
(added)
+++
openejb/trunk/openejb3/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
Fri Aug 19 13:18:53 2011
@@ -0,0 +1,69 @@
+/**
+ * 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.produces.disposes;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.Context;
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class LoggerTest {
+
+ @Inject
+ Logger logger;
+
+ private Context ctxt;
+
+ @Before
+ public void setUp() {
+ try {
+ ctxt = EJBContainer.createEJBContainer().getContext();
+ ctxt.bind("inject", this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void cleanUp() {
+ try {
+ ctxt.unbind("inject");
+ ctxt.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testLogHandler() {
+ assertNotNull(logger);
+ assertFalse("Handler should not be a ConsoleHandler",
logger.getHandler() instanceof ConsoleHandler);
+ assertFalse("Handler should not be a FileHandler", logger.getHandler()
instanceof FileHandler);
+ assertTrue("Handler should be a DatabaseHandler", logger.getHandler()
instanceof DatabaseHandler);
+ logger.log("##### Testing write\n");
+ logger = null;
+ }
+
+
+}
Modified: openejb/trunk/openejb3/examples/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=1159626&r1=1159625&r2=1159626&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Fri Aug 19 13:18:53 2011
@@ -83,9 +83,10 @@
<module>datasource-ciphered-password</module>
<module>bean-validation-design-by-contract</module>
<module>cdi-basic</module>
- <module>cdi-interceptors</module>
+ <module>cdi-interceptors</module>
<module>rest-on-ejb</module>
<module>dynamic-dao-implementation</module>
+ <module>cdi-produces-disposes</module>
</modules>
<profiles>
<profile>