You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/10/29 17:56:01 UTC
svn commit: r831026 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test:
component/intercept/webbeans/CallBusinessInConstructorBean.java
unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
Author: gerdogdu
Date: Thu Oct 29 16:56:00 2009
New Revision: 831026
URL: http://svn.apache.org/viewvc?rev=831026&view=rev
Log:
Testing calling business method from constructor.
Added:
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java (with props)
incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java (with props)
Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java?rev=831026&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java Thu Oct 29 16:56:00 2009
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.apache.webbeans.test.component.intercept.webbeans;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+
+import org.apache.webbeans.test.component.intercept.webbeans.bindings.Secure;
+
+@Named
+@RequestScoped
+public class CallBusinessInConstructorBean
+{
+ public CallBusinessInConstructorBean()
+ {
+ shuffle();
+ }
+
+ @Secure
+ public void shuffle()
+ {
+
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/CallBusinessInConstructorBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java?rev=831026&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java Thu Oct 29 16:56:00 2009
@@ -0,0 +1,87 @@
+/*
+ * 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.test.unittests.intercept.webbeans;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.Bean;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.context.RequestContext;
+import org.apache.webbeans.test.component.intercept.webbeans.CallBusinessInConstructorBean;
+import org.apache.webbeans.test.component.intercept.webbeans.SecureInterceptor;
+import org.apache.webbeans.test.servlet.TestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CallingBusinessInConstructorTest extends TestContext
+{
+ public CallingBusinessInConstructorTest()
+ {
+ super(CallingBusinessInConstructorTest.class.getName());
+ }
+
+ @Before
+ public void init()
+ {
+ super.init();
+
+ SecureInterceptor.CALL = false;
+ initializeInterceptorType(SecureInterceptor.class);
+ }
+
+ @After
+ public void after()
+ {
+ SecureInterceptor.CALL = false;
+ }
+
+ @Test
+ public void testCallBusinessInConstructor()
+ {
+ ContextFactory.initRequestContext(null);
+
+ clear();
+
+ defineSimpleWebBeanInterceptor(SecureInterceptor.class);
+ Bean<CallBusinessInConstructorBean> bean = defineSimpleWebBean(CallBusinessInConstructorBean.class);
+ CallBusinessInConstructorBean instance = (CallBusinessInConstructorBean) getInstanceByName("callBusinessInConstructorBean");
+
+ Assert.assertNotNull(instance);
+
+ Assert.assertTrue(SecureInterceptor.CALL);
+
+ ContextFactory.destroyRequestContext(null);
+
+ SecureInterceptor.CALL = false;
+
+ ContextFactory.initRequestContext(null);
+
+ RequestContext ctx = (RequestContext) ContextFactory.getStandardContext(RequestScoped.class);
+
+ Assert.assertNull(ctx.get(bean));
+
+ instance = (CallBusinessInConstructorBean) getInstanceByName("callBusinessInConstructorBean");
+
+ Assert.assertNotNull(instance);
+
+ Assert.assertTrue(!SecureInterceptor.CALL);
+
+ ContextFactory.destroyRequestContext(null);
+
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Re: svn commit: r831026 - in /incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test: component/intercept/webbeans/CallBusinessInConstructorBean.java unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
Posted by Gurkan Erdogdu <gu...@yahoo.com>.
+1
May we add ThreadLocal variable to JavassistProxyFactory while creating instance and check this in InterceptorHandler?
WDYT?
--Gurkan
________________________________
From: Eric Covener <co...@gmail.com>
To: openwebbeans-dev@incubator.apache.org
Sent: Fri, October 30, 2009 12:58:24 AM
Subject: Re: svn commit: r831026 - in /incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test: component/intercept/webbeans/CallBusinessInConstructorBean.java unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
On Thu, Oct 29, 2009 at 12:56 PM, <ge...@apache.org> wrote:
> Author: gerdogdu
> Date: Thu Oct 29 16:56:00 2009
> New Revision: 831026
>
> URL: http://svn.apache.org/viewvc?rev=831026&view=rev
> Log:
> Testing calling business method from constructor.
> + defineSimpleWebBeanInterceptor(SecureInterceptor.class);
> + Bean<CallBusinessInConstructorBean> bean = defineSimpleWebBean(CallBusinessInConstructorBean.class);
> + CallBusinessInConstructorBean instance = (CallBusinessInConstructorBean) getInstanceByName("callBusinessInConstructorBean");
> +
> + Assert.assertNotNull(instance);
> +
> + Assert.assertTrue(SecureInterceptor.CALL);
While 7.2 of 299 does not cover this explicitly, Joe Bergmark made a
good argument offline that the proxy calling the underlying bean
constructor may not be correctly interpreted here as a business method
invocation, since it's the container making the call and not via a
contextual reference.
--
Eric Covener
covener@gmail.com
Re: svn commit: r831026 - in /incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test:
component/intercept/webbeans/CallBusinessInConstructorBean.java
unittests/intercept/webbeans/CallingBusinessInConstructorTest.java
Posted by Eric Covener <co...@gmail.com>.
On Thu, Oct 29, 2009 at 12:56 PM, <ge...@apache.org> wrote:
> Author: gerdogdu
> Date: Thu Oct 29 16:56:00 2009
> New Revision: 831026
>
> URL: http://svn.apache.org/viewvc?rev=831026&view=rev
> Log:
> Testing calling business method from constructor.
> + defineSimpleWebBeanInterceptor(SecureInterceptor.class);
> + Bean<CallBusinessInConstructorBean> bean = defineSimpleWebBean(CallBusinessInConstructorBean.class);
> + CallBusinessInConstructorBean instance = (CallBusinessInConstructorBean) getInstanceByName("callBusinessInConstructorBean");
> +
> + Assert.assertNotNull(instance);
> +
> + Assert.assertTrue(SecureInterceptor.CALL);
While 7.2 of 299 does not cover this explicitly, Joe Bergmark made a
good argument offline that the proxy calling the underlying bean
constructor may not be correctly interpreted here as a business method
invocation, since it's the container making the call and not via a
contextual reference.
--
Eric Covener
covener@gmail.com