You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by km...@apache.org on 2011/07/09 22:51:06 UTC
svn commit: r1144741 - in /openejb/trunk/openejb3/examples: ./
cdi-interceptors/ cdi-interceptors/src/ cdi-interceptors/src/main/
cdi-interceptors/src/main/java/ cdi-interceptors/src/main/java/org/
cdi-interceptors/src/main/java/org/superbiz/ cdi-inter...
Author: kmalhi
Date: Sat Jul 9 20:51:05 2011
New Revision: 1144741
URL: http://svn.apache.org/viewvc?rev=1144741&view=rev
Log:
OPENEJB-1607
Great example by Vishwa.
Thank you Vishwa!
Added:
openejb/trunk/openejb3/examples/cdi-interceptors/ (with props)
openejb/trunk/openejb3/examples/cdi-interceptors/pom.xml
openejb/trunk/openejb3/examples/cdi-interceptors/src/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/
openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java
openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java
Modified:
openejb/trunk/openejb3/examples/pom.xml
Propchange: openejb/trunk/openejb3/examples/cdi-interceptors/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Jul 9 20:51:05 2011
@@ -0,0 +1,4 @@
+.classpath
+.settings
+.project
+target
Added: openejb/trunk/openejb3/examples/cdi-interceptors/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/pom.xml?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/pom.xml (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/pom.xml Sat Jul 9 20:51:05 2011
@@ -0,0 +1,88 @@
+<?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-interceptors</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: CDI Interceptors</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-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,30 @@
+/**
+ * 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;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@ApplicationException
+public class AccessDeniedException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+ public AccessDeniedException(String s) {
+ super(s);
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.bookshow.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+import javax.interceptor.Interceptors;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor;
+
+/**
+ * CDI supports binding an interceptor using @Interceptors
+ * Not recommended though. Has its disadvantages
+ * Cannot be disabled easily
+ * Order dependent on how it is listed in class
+ * Instead, create interceptor bindings using @InterceptorBinding and bind them
+ * See {@link Log}, {@link BookForAShowOneInterceptorApplied}, {@link BookForAShowLoggingInterceptor}
+ */
+@Interceptors(BookForAShowLoggingInterceptor.class)
+@Stateful
+public class BookForAShowOldStyleInterceptorBinding implements Serializable {
+ private static final long serialVersionUID = 6350400892234496909L;
+ public List<String> getMoviesList() {
+ List<String> moviesAvailable = new ArrayList<String>();
+ moviesAvailable.add("KungFu Panda 2");
+ moviesAvailable.add("Kings speech");
+ return moviesAvailable;
+ }
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,41 @@
+/**
+ * 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.bookshow.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+
+@Log
+@Stateful
+public class BookForAShowOneInterceptorApplied implements Serializable {
+ private static final long serialVersionUID = 6350400892234496909L;
+ public List<String> getMoviesList() {
+ List<String> moviesAvailable = new ArrayList<String>();
+ moviesAvailable.add("12 Angry Men");
+ moviesAvailable.add("Kings speech");
+ return moviesAvailable;
+ }
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,43 @@
+/**
+ * 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.bookshow.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
+
+@Log
+@Stateful
+public class BookForAShowTwoInterceptorsApplied implements Serializable {
+ private static final long serialVersionUID = 6350400892234496909L;
+ public List<String> getMoviesList() {
+ List<String> moviesAvailable = new ArrayList<String>();
+ moviesAvailable.add("12 Angry Men");
+ moviesAvailable.add("Kings speech");
+ return moviesAvailable;
+ }
+ @TimeRestricted
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,41 @@
+/**
+ * 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.bookshow.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog;
+
+@Stateful
+public class BookShowInterceptorBindingInheritanceExplored implements Serializable {
+ private static final long serialVersionUID = 6350400892234496909L;
+ public List<String> getMoviesList() {
+ List<String> moviesAvailable = new ArrayList<String>();
+ moviesAvailable.add("12 Angry Men");
+ moviesAvailable.add("Kings speech");
+ return moviesAvailable;
+ }
+ @TimeRestrictAndLog
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,30 @@
+/**
+ * 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.bookshow.interceptorbinding;
+
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.*;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface Log {
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java Sat Jul 9 20:51:05 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.bookshow.interceptorbinding;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ *This InterceptorBinding inherits from @Log and @TimeRestricted Interceptor-Bindings.
+ */
+@Inherited
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+@Log
+@TimeRestricted
+public @interface TimeRestrictAndLog {
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,30 @@
+/**
+ * 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.bookshow.interceptorbinding;
+
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.*;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface TimeRestricted {
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+/**
+ * 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.bookshow.interceptors;
+
+import java.io.Serializable;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Logger;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+@Interceptor
+@Log
+public class BookForAShowLoggingInterceptor implements Serializable {
+ private static final long serialVersionUID = 8139854519874743530L;
+ private Logger logger = Logger.getLogger("BookForAShowApplicationLogger");
+ @AroundInvoke
+ public Object logMethodEntry(InvocationContext ctx) throws Exception {
+ logger.info("Before entering method:" + ctx.getMethod().getName());
+ InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
+ InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
+ return ctx.proceed();
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,47 @@
+/**
+ * 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.bookshow.interceptors;
+
+import java.io.Serializable;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import org.superbiz.cdi.AccessDeniedException;
+import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+@Interceptor
+@TimeRestricted
+public class TimeBasedRestrictingInterceptor implements Serializable {
+ private static final long serialVersionUID = 8139854519874743530L;
+ @AroundInvoke
+ public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception {
+ InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
+ InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
+ if (!isWorkingHours()) {
+ throw new AccessDeniedException("You are not allowed to access the method at this time");
+ }
+ return ctx.proceed();
+ }
+ private boolean isWorkingHours() {
+ /*
+ * int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 9 && hourOfDay <= 21) {
+ * return true; } else { return false; }
+ */
+ return true; // Let's assume
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java Sat Jul 9 20:51:05 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.bookshow.tracker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A helper class for the test.
+ * Keeps track of methods intercepted during one testXXX run
+ * Keeps track of interceptors applied during one textXXX run
+ */
+public class InterceptionOrderTracker {
+ /*
+ * Contains method names that were intercepted by the interceptors
+ */
+ private static List<String> methodsInterceptedList = new ArrayList<String>();
+ /*
+ * Contains the name of the interceptor class that intercepted a method
+ */
+ private static List<String> interceptedByList = new ArrayList<String>();
+ public static List<String> getInterceptedByList() {
+ return interceptedByList;
+ }
+ public static void setInterceptedByList(List<String> interceptedByList) {
+ InterceptionOrderTracker.interceptedByList = interceptedByList;
+ }
+ public static List<String> getMethodsInterceptedList() {
+ return methodsInterceptedList;
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml Sat Jul 9 20:51:05 2011
@@ -0,0 +1,33 @@
+<!--
+
+ 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>
+ <!-- By default, a bean archive has no enabled interceptors bound via interceptor
+ bindings. An interceptor must be explicitly enabled by listing its class
+ under the element of the beans.xml file of the bean archive. The order of
+ the interceptor declarations determines the interceptor ordering. Interceptors
+ which occur earlier in the list are called first. If the same class is listed
+ twice under the interceptors element, the container automatically detects
+ the problem and treats it as a deployment problem. -->
+
+ <interceptors>
+ <class>org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor
+ </class>
+ <class>org.superbiz.cdi.bookshow.interceptors.TimeBasedRestrictingInterceptor
+ </class>
+ </interceptors>
+</beans>
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,55 @@
+/**
+ * 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.bookshow.interceptors;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+
+import junit.framework.TestCase;
+
+import org.superbiz.cdi.bookshow.beans.BookForAShowOldStyleInterceptorBinding;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+public class BookForAShowOldStyleInterceptorBindingTest extends TestCase {
+ @EJB
+ private BookForAShowOldStyleInterceptorBinding bookForAShowBean;
+ EJBContainer ejbContainer;
+ /**
+ * Bootstrap the Embedded EJB Container
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ ejbContainer = EJBContainer.createEJBContainer();
+ ejbContainer.getContext().bind("inject", this);
+ }
+ /**
+ * Test basic interception
+ */
+ public void testMethodShouldBeIntercepted() {
+ // action
+ bookForAShowBean.getMoviesList();
+ // verify
+ assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
+ }
+ protected void tearDown() {
+ // clear the lists after each test
+ InterceptionOrderTracker.getInterceptedByList().clear();
+ InterceptionOrderTracker.getMethodsInterceptedList().clear();
+ ejbContainer.close();
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java Sat Jul 9 20:51:05 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.bookshow.interceptors;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import junit.framework.TestCase;
+
+import org.superbiz.cdi.bookshow.beans.BookForAShowOneInterceptorApplied;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+public class BookForAShowOneInterceptorAppliedTest extends TestCase {
+ @EJB
+ private BookForAShowOneInterceptorApplied bookForAShowBean;
+ EJBContainer ejbContainer;
+ /**
+ * Bootstrap the Embedded EJB Container
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ ejbContainer = EJBContainer.createEJBContainer();
+ ejbContainer.getContext().bind("inject", this);
+ }
+ /**
+ * Test basic interception
+ */
+ public void testMethodShouldBeIntercepted() {
+ // action
+ bookForAShowBean.getMoviesList();
+ // verify
+ assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
+ }
+ protected void tearDown() {
+ // clear the list after each test
+ InterceptionOrderTracker.getInterceptedByList().clear();
+ InterceptionOrderTracker.getMethodsInterceptedList().clear();
+ ejbContainer.close();
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java Sat Jul 9 20:51:05 2011
@@ -0,0 +1,65 @@
+/**
+ * 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.bookshow.interceptors;
+
+import java.util.List;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookForAShowTwoInterceptorsApplied;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+public class BookForAShowTwoInterceptorsAppiledTest extends TestCase {
+ @EJB
+ private BookForAShowTwoInterceptorsApplied bookForAShowBean;
+ EJBContainer ejbContainer;
+ /**
+ * Bootstrap the Embedded EJB Container
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ ejbContainer = EJBContainer.createEJBContainer();
+ ejbContainer.getContext().bind("inject", this);
+ }
+ /**
+ * Interceptors should be applied in order as defined in beans.xml
+ */
+ public void testInterceptorsShouldBeAppliedInOrder() {
+ // action
+ bookForAShowBean.getDiscountedPrice(100);
+ // verify
+ List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+ int indexOfLogger = interceptedByList.indexOf("BookForAShowLoggingInterceptor");
+ int indexOfTimeBasedRestrictor = interceptedByList.indexOf("TimeBasedRestrictingInterceptor");
+ assertTrue(indexOfLogger < indexOfTimeBasedRestrictor);
+ }
+ public void testTwoInterceptorsWereInvoked() {
+ // action
+ bookForAShowBean.getDiscountedPrice(100);
+ // verify
+ List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+ assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
+ }
+ protected void tearDown() {
+ // clear the lists after each test
+ InterceptionOrderTracker.getInterceptedByList().clear();
+ InterceptionOrderTracker.getMethodsInterceptedList().clear();
+ ejbContainer.close();
+ }
+}
Added: openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java?rev=1144741&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java (added)
+++ openejb/trunk/openejb3/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java Sat Jul 9 20:51:05 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.bookshow.interceptors;
+
+import java.util.List;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookShowInterceptorBindingInheritanceExplored;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+public class BookShowInterceptorBindingInheritanceTest extends TestCase {
+ @EJB
+ private BookShowInterceptorBindingInheritanceExplored bookForAShowBean;
+ EJBContainer ejbContainer;
+ /**
+ * Bootstrap the Embedded EJB Container
+ *
+ * @throws Exception
+ */
+ protected void setUp() throws Exception {
+ ejbContainer = EJBContainer.createEJBContainer();
+ ejbContainer.getContext().bind("inject", this);
+ }
+ public void testInterceptorBindingCanInheritFromAnotherBinding() {
+ // action
+ bookForAShowBean.getDiscountedPrice(100);
+ // verify both interceptors were invoked
+ List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+ System.out.println("Intercepted by:" + interceptedByList);
+ assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
+ }
+ protected void tearDown() {
+ // clear the list after each test
+ InterceptionOrderTracker.getInterceptedByList().clear();
+ InterceptionOrderTracker.getMethodsInterceptedList().clear();
+ ejbContainer.close();
+ }
+}
Modified: openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=1144741&r1=1144740&r2=1144741&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Sat Jul 9 20:51:05 2011
@@ -83,6 +83,7 @@
<module>datasource-ciphered-password</module>
<module>bean-validation-design-by-contract</module>
<module>cdi-example</module>
+ <module>cdi-interceptors</module>
</modules>
<profiles>
<profile>