openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1209888 - in /openwebbeans/trunk/webbeans-impl/src/test: java/org/apache/webbeans/newtests/interceptors/business/common/ java/org/apache/webbeans/newtests/interceptors/business/tests/ resources/org/apache/webbeans/newtests/interceptors/bus...
Date Sat, 03 Dec 2011 11:26:56 GMT
Author: struberg
Date: Sat Dec  3 11:26:55 2011
New Revision: 1209888

URL: http://svn.apache.org/viewvc?rev=1209888&view=rev
Log:
OWB-515 add tests for interception of derived methods

This works fine now

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalBaseBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalChildBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.java
      - copied, changed from r1209800, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/WithStereoTypeInterceptorTest.java
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.xml
      - copied unchanged from r1209800, openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/business/tests/WithStereoTypeInterceptorTest.xml

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalBaseBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalBaseBean.java?rev=1209888&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalBaseBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalBaseBean.java
Sat Dec  3 11:26:55 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.apache.webbeans.newtests.interceptors.business.common;
+
+import org.apache.webbeans.test.component.intercept.webbeans.bindings.Secure;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * This class will get inherited.
+ */
+@RequestScoped
+public class TransactionalBaseBean
+{
+
+    /**
+     * calling this method from outside should still trigger the Secure interceptor
+     */
+    @Secure
+    public String doBase()
+    {
+        return "42";
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalChildBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalChildBean.java?rev=1209888&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalChildBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/common/TransactionalChildBean.java
Sat Dec  3 11:26:55 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.apache.webbeans.newtests.interceptors.business.common;
+
+import org.apache.webbeans.test.component.intercept.webbeans.bindings.Secure;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * This class extends a bean with intercepted methods.
+ */
+@RequestScoped
+public class TransactionalChildBean extends TransactionalBaseBean
+{
+
+    /**
+     * calling this method from outside should also trigger the Secure interceptor
+     */
+    @Secure
+    public String doHalf()
+    {
+        return "21";
+    }
+}

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.java
(from r1209800, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/WithStereoTypeInterceptorTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/WithStereoTypeInterceptorTest.java&r1=1209800&r2=1209888&rev=1209888&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/WithStereoTypeInterceptorTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InheritedBeanInterceptorTest.java
Sat Dec  3 11:26:55 2011
@@ -18,54 +18,52 @@
  */
 package org.apache.webbeans.newtests.interceptors.business.tests;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-
 import junit.framework.Assert;
-
 import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.interceptors.business.common.WithStereoTypeInterceptorBean;
+import org.apache.webbeans.newtests.interceptors.business.common.TransactionalBaseBean;
+import org.apache.webbeans.newtests.interceptors.business.common.TransactionalChildBean;
 import org.apache.webbeans.newtests.interceptors.common.TransactionInterceptor;
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 @SuppressWarnings("unchecked")
-public class WithStereoTypeInterceptorTest extends AbstractUnitTest
+public class InheritedBeanInterceptorTest extends AbstractUnitTest
 {
-    private static final String PACKAGE_NAME = WithStereoTypeInterceptorTest.class.getPackage().getName();
+    private static final String PACKAGE_NAME = InheritedBeanInterceptorTest.class.getPackage().getName();
     
     @Test
     public void testStereoTypeBasedInterceptor()
     {
         Collection<String> beanXmls = new ArrayList<String>();
-        beanXmls.add(getXmlPath(PACKAGE_NAME, "WithStereoTypeInterceptorTest"));
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "InheritedBeanInterceptorTest"));
         
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
         beanClasses.add(TransactionInterceptor.class);
-        beanClasses.add(WithStereoTypeInterceptorBean.class);
-        
-        startContainer(beanClasses, beanXmls);       
-        
-        Set<Bean<?>> beans = getBeanManager().getBeans("org.apache.webbeans.newtests.interceptors.business.common.WithStereoTypeInterceptorBean");
-        Assert.assertNotNull(beans);        
-        Bean<WithStereoTypeInterceptorBean> bean = (Bean<WithStereoTypeInterceptorBean>)beans.iterator().next();
-        
-        CreationalContext<WithStereoTypeInterceptorBean> ctx = getBeanManager().createCreationalContext(bean);
-        
-        Object reference = getBeanManager().getReference(bean, WithStereoTypeInterceptorBean.class,
ctx);
-        Assert.assertNotNull(reference);
-        
-        Assert.assertTrue(reference instanceof WithStereoTypeInterceptorBean);
-        
-        WithStereoTypeInterceptorBean beanInstance = (WithStereoTypeInterceptorBean)reference;
-        
-        beanInstance.sayHello();
-        
+        beanClasses.add(TransactionalBaseBean.class);
+        beanClasses.add(TransactionalChildBean.class);
+
+        startContainer(beanClasses, beanXmls);
+
+        TransactionInterceptor.ECHO = false;
+        TransactionInterceptor.count = 0;
+
+        TransactionalChildBean child = getInstance(TransactionalChildBean.class);
+        Assert.assertNotNull(child);
+        Assert.assertEquals(0, TransactionInterceptor.count);
+
+        Assert.assertEquals("21", child.doHalf());
         Assert.assertTrue(TransactionInterceptor.ECHO);
-        
+        Assert.assertEquals(1, TransactionInterceptor.count);
+
+        TransactionInterceptor.ECHO = false;
+        TransactionInterceptor.count = 0;
+
+        Assert.assertEquals("42", child.doBase());
+        Assert.assertTrue(TransactionInterceptor.ECHO);
+        Assert.assertEquals(1, TransactionInterceptor.count);
+
         shutDownContainer();
         
     }



Mime
View raw message