You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by da...@apache.org on 2012/12/07 22:21:38 UTC
svn commit: r1418482 - in
/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind:
./ test/ test/aop/ test/aop/annoherited/ test/aop/annotated/
test/aop/inherited/ test/aop/invalid/
Author: danielmanzke
Date: Fri Dec 7 21:21:37 2012
New Revision: 1418482
URL: http://svn.apache.org/viewvc?rev=1418482&view=rev
Log:
[ONAMI-23] reenable configuration of autobind
- added missing test files
Added:
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/AllTests.java
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/AnnoheritedInterceptorTests.java
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/AnnotatedInterceptorTests.java
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/InheritedInterceptorTests.java
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/ (with props)
incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/InvalidInterceptorTests.java
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/
------------------------------------------------------------------------------
bugtraq:number = true
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/
------------------------------------------------------------------------------
bugtraq:number = true
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/AllTests.java?rev=1418482&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/AllTests.java (added)
+++ incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/AllTests.java Fri Dec 7 21:21:37 2012
@@ -0,0 +1,36 @@
+package org.apache.onami.autobind.test.aop;
+
+/*
+ * 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.
+ */
+
+import org.apache.onami.autobind.test.aop.annoherited.AnnoheritedInterceptorTests;
+import org.apache.onami.autobind.test.aop.annotated.AnnotatedInterceptorTests;
+import org.apache.onami.autobind.test.aop.inherited.InheritedInterceptorTests;
+import org.apache.onami.autobind.test.aop.invalid.InvalidInterceptorTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith( Suite.class )
+@Suite.SuiteClasses( { AnnoheritedInterceptorTests.class,
+ AnnotatedInterceptorTests.class,
+ InheritedInterceptorTests.class,
+ InvalidInterceptorTests.class } )
+public class AllTests
+{
+}
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/AnnoheritedInterceptorTests.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/AnnoheritedInterceptorTests.java?rev=1418482&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/AnnoheritedInterceptorTests.java (added)
+++ incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annoherited/AnnoheritedInterceptorTests.java Fri Dec 7 21:21:37 2012
@@ -0,0 +1,137 @@
+package org.apache.onami.autobind.test.aop.annoherited;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Method;
+
+import javax.interceptor.Interceptor;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.aop.ClassMatcher;
+import org.apache.onami.autobind.aop.Intercept;
+import org.apache.onami.autobind.aop.MethodMatcher;
+import org.apache.onami.autobind.aop.feature.InterceptorFeature;
+import org.apache.onami.autobind.configuration.StartupModule;
+import org.apache.onami.autobind.scanner.PackageFilter;
+import org.apache.onami.autobind.scanner.asm.ASMClasspathScanner;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+
+public class AnnoheritedInterceptorTests
+{
+
+ private static ThreadLocal<Boolean> called = new ThreadLocal<Boolean>();
+
+ @Test
+ public void createDynamicModule()
+ {
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( AnnoheritedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+ }
+
+ @Test
+ public void createInheritedInterceptor()
+ {
+ called.set( false );
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( AnnoheritedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+
+ TestInterface instance = injector.getInstance( TestInterface.class );
+ instance.sayHello(); // should be intercepted
+ instance.sayGoodBye(); // if intercepted an exception is thrown
+
+ assertTrue( "Interceptor was not invoked", called.get() );
+ }
+
+ @Interceptor
+ public static class InheritedMethodInterceptor
+ implements MethodInterceptor
+ {
+
+ @Override
+ public Object invoke( MethodInvocation invocation )
+ throws Throwable
+ {
+ assertTrue( invocation.getMethod().getName().equals( "sayHello" ) );
+ called.set( true );
+ return invocation.proceed();
+ }
+
+ @ClassMatcher
+ public Matcher<? super Class<?>> getClassMatcher()
+ {
+ return Matchers.any();
+ }
+
+ @MethodMatcher
+ public Matcher<? super Method> getMethodMatcher()
+ {
+ return Matchers.annotatedWith( Intercept.class );
+ }
+
+ }
+
+ public static interface TestInterface
+ {
+
+ String sayHello();
+
+ String sayGoodBye();
+
+ }
+
+ @Bind
+ public static class TestInterfaceImplementation
+ implements TestInterface
+ {
+ public static final String TEST = "test";
+
+ @Override
+ @Intercept
+ public String sayHello()
+ {
+ return TEST;
+ }
+
+ @Override
+ public String sayGoodBye()
+ {
+ return "Good Bye!";
+ }
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/AnnotatedInterceptorTests.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/AnnotatedInterceptorTests.java?rev=1418482&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/AnnotatedInterceptorTests.java (added)
+++ incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/annotated/AnnotatedInterceptorTests.java Fri Dec 7 21:21:37 2012
@@ -0,0 +1,136 @@
+package org.apache.onami.autobind.test.aop.annotated;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Method;
+
+import javax.interceptor.Interceptor;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.aop.ClassMatcher;
+import org.apache.onami.autobind.aop.Intercept;
+import org.apache.onami.autobind.aop.Invoke;
+import org.apache.onami.autobind.aop.MethodMatcher;
+import org.apache.onami.autobind.aop.feature.InterceptorFeature;
+import org.apache.onami.autobind.configuration.StartupModule;
+import org.apache.onami.autobind.scanner.PackageFilter;
+import org.apache.onami.autobind.scanner.asm.ASMClasspathScanner;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+
+public class AnnotatedInterceptorTests
+{
+
+ private static ThreadLocal<Boolean> called = new ThreadLocal<Boolean>();
+
+ @Test
+ public void createDynamicModule()
+ {
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( AnnotatedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+ }
+
+ @Test
+ public void createInheritedInterceptor()
+ {
+ called.set( false );
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( AnnotatedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+
+ TestInterface instance = injector.getInstance( TestInterface.class );
+ instance.sayHello(); // should be intercepted
+ instance.sayGoodBye(); // if intercepted an exception is thrown
+
+ assertTrue( "Interceptor was not invoked", called.get() );
+ }
+
+ @Interceptor
+ public static class InheritedMethodInterceptor
+ {
+
+ @Invoke
+ public Object invoke( MethodInvocation invocation )
+ throws Throwable
+ {
+ assertTrue( invocation.getMethod().getName().equals( "sayHello" ) );
+ called.set( true );
+ return invocation.proceed();
+ }
+
+ @ClassMatcher
+ public Matcher<? super Class<?>> getClassMatcher()
+ {
+ return Matchers.any();
+ }
+
+ @MethodMatcher
+ public Matcher<? super Method> getMethodMatcher()
+ {
+ return Matchers.annotatedWith( Intercept.class );
+ }
+
+ }
+
+ public static interface TestInterface
+ {
+
+ String sayHello();
+
+ String sayGoodBye();
+
+ }
+
+ @Bind
+ public static class TestInterfaceImplementation
+ implements TestInterface
+ {
+ public static final String TEST = "test";
+
+ @Override
+ @Intercept
+ public String sayHello()
+ {
+ return TEST;
+ }
+
+ @Override
+ public String sayGoodBye()
+ {
+ return "Good Bye!";
+ }
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/InheritedInterceptorTests.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/InheritedInterceptorTests.java?rev=1418482&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/InheritedInterceptorTests.java (added)
+++ incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/inherited/InheritedInterceptorTests.java Fri Dec 7 21:21:37 2012
@@ -0,0 +1,137 @@
+package org.apache.onami.autobind.test.aop.inherited;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Method;
+
+import javax.interceptor.Interceptor;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.aop.GuiceMethodInterceptor;
+import org.apache.onami.autobind.aop.Intercept;
+import org.apache.onami.autobind.aop.feature.InterceptorFeature;
+import org.apache.onami.autobind.configuration.StartupModule;
+import org.apache.onami.autobind.scanner.PackageFilter;
+import org.apache.onami.autobind.scanner.asm.ASMClasspathScanner;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+
+public class InheritedInterceptorTests
+{
+
+ private static ThreadLocal<Boolean> called = new ThreadLocal<Boolean>();
+
+ @Test
+ public void createDynamicModule()
+ {
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( InheritedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+ }
+
+ @Test
+ public void createInheritedInterceptor()
+ {
+ called.set( false );
+
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( InheritedInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+
+ TestInterface instance = injector.getInstance( TestInterface.class );
+ instance.sayHello(); // should be intercepted
+ instance.sayGoodBye(); // if intercepted an exception is thrown
+
+ assertTrue( "Interceptor was not invoked", called.get() );
+ }
+
+ @Interceptor
+ public static class InheritedMethodInterceptor
+ extends GuiceMethodInterceptor
+ {
+
+ @Override
+ public Object invoke( MethodInvocation invocation )
+ throws Throwable
+ {
+ assertTrue( invocation.getMethod().getName().equals( "sayHello" ) );
+ called.set( true );
+ return invocation.proceed();
+ }
+
+ @Override
+ public Matcher<? super Class<?>> getClassMatcher()
+ {
+ return Matchers.any();
+ }
+
+ @Override
+ public Matcher<? super Method> getMethodMatcher()
+ {
+ return Matchers.annotatedWith( Intercept.class );
+ }
+
+ }
+
+ public static interface TestInterface
+ {
+
+ String sayHello();
+
+ String sayGoodBye();
+
+ }
+
+ @Bind
+ public static class TestInterfaceImplementation
+ implements TestInterface
+ {
+
+ public static final String TEST = "test";
+
+ @Override
+ @Intercept
+ public String sayHello()
+ {
+ return TEST;
+ }
+
+ @Override
+ public String sayGoodBye()
+ {
+ return "Good Bye!";
+ }
+ }
+
+}
Propchange: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/
------------------------------------------------------------------------------
bugtraq:number = true
Added: incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/InvalidInterceptorTests.java
URL: http://svn.apache.org/viewvc/incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/InvalidInterceptorTests.java?rev=1418482&view=auto
==============================================================================
--- incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/InvalidInterceptorTests.java (added)
+++ incubator/onami/trunk/autobind/aop/src/test/java/org/apache/onami/autobind/test/aop/invalid/InvalidInterceptorTests.java Fri Dec 7 21:21:37 2012
@@ -0,0 +1,119 @@
+package org.apache.onami.autobind.test.aop.invalid;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Method;
+
+import javax.interceptor.Interceptor;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.onami.autobind.annotations.Bind;
+import org.apache.onami.autobind.aop.ClassMatcher;
+import org.apache.onami.autobind.aop.Intercept;
+import org.apache.onami.autobind.aop.Invoke;
+import org.apache.onami.autobind.aop.MethodMatcher;
+import org.apache.onami.autobind.aop.feature.InterceptorFeature;
+import org.apache.onami.autobind.configuration.StartupModule;
+import org.apache.onami.autobind.scanner.PackageFilter;
+import org.apache.onami.autobind.scanner.asm.ASMClasspathScanner;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.matcher.Matcher;
+import com.google.inject.matcher.Matchers;
+
+public class InvalidInterceptorTests
+{
+
+ @Test
+ public void createDynamicModule()
+ {
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( InvalidInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+ }
+
+ @Test
+ public void createInvalidInterceptor()
+ {
+ StartupModule startup =
+ StartupModule.create( ASMClasspathScanner.class, PackageFilter.create( InvalidInterceptorTests.class ) );
+ startup.addFeature( InterceptorFeature.class );
+
+ Injector injector = Guice.createInjector( startup );
+ assertNotNull( injector );
+
+ TestInterface instance = injector.getInstance( TestInterface.class );
+ instance.sayHello();
+ }
+
+ @Interceptor
+ public static class InvalidMethodInterceptor
+ {
+
+ @Invoke
+ public Object invoke( MethodInvocation invocation, Object obj )
+ throws Throwable
+ {
+ fail( "This is an invalid Interceptor, it should never be called." );
+ return invocation.proceed();
+ }
+
+ @ClassMatcher
+ public Matcher<? super Class<?>> getClassMatcher()
+ {
+ return Matchers.any();
+ }
+
+ @MethodMatcher
+ public Matcher<? super Method> getMethodMatcher()
+ {
+ return Matchers.any();// Matchers.annotatedWith(Intercept.class);
+ }
+
+ }
+
+ public static interface TestInterface
+ {
+ String sayHello();
+ }
+
+ @Bind
+ public static class TestInterfaceImplementation
+ implements TestInterface
+ {
+ public static final String TEST = "test";
+
+ @Override
+ @Intercept
+ public String sayHello()
+ {
+ return TEST;
+ }
+ }
+
+}