Author: hlship
Date: Thu Jan  8 11:43:42 2009
New Revision: 732804

URL: http://svn.apache.org/viewvc?rev=732804&view=rev
Log:
TAP5-355: TapestrySpring does not support injection of Spring FactoryBeans

Added:
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SpringStatusProviderFactory.java
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactory.java
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactoryFactory.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
    tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml
    
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml

Modified: 
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
 Thu Jan  8 11:43:42 2009
@@ -136,7 +136,11 @@
     {
         for (final String beanName : 
BeanFactoryUtils.beanNamesIncludingAncestors(context))
         {
-            services.put(beanName, new SpringBeanServiceDef(beanName, 
context));
+            String trueName = beanName.startsWith("&")
+                              ? beanName.substring(1)
+                              : beanName;
+
+            services.put(trueName, new SpringBeanServiceDef(trueName, 
context));
         }
     }
 

Modified: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/internal/spring/SpringModuleDefTest.java
 Thu Jan  8 11:43:42 2009
@@ -34,6 +34,7 @@
         ServletContext servletContext = mockServletContext();
         ConfigurableWebApplicationContext ac = 
newMock(ConfigurableWebApplicationContext.class);
         Runnable fred = mockRunnable();
+        Runnable barney = mockRunnable();
 
         ServiceBuilderResources resources = mockServiceBuilderResources();
 
@@ -41,7 +42,9 @@
 
         train_getAttribute(servletContext, 
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
 
-        expect(ac.getBeanNamesForType(Object.class)).andReturn(new String[] 
{"fred", "barney"});
+        // Simulate barney as a factory bean.
+
+        expect(ac.getBeanNamesForType(Object.class)).andReturn(new String[] 
{"fred", "&barney"});
         expect(ac.getParentBeanFactory()).andReturn(null);
 
         replay();
@@ -81,6 +84,15 @@
         assertEquals(sd.createServiceCreator(null).toString(), 
"ObjectCreator<Spring Bean 'fred'>");
 
         verify();
+
+        expect(ac.getType("barney")).andReturn(Runnable.class);
+        expect(ac.getBean("barney")).andReturn(barney);
+
+        replay();
+
+        sd = moduleDef.getServiceDef("barney");
+
+        assertSame(sd.createServiceCreator(null).createObject(), barney);
     }
 
     @Test

Modified: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/apache/tapestry5/spring/TapestrySpringIntegrationTest.java
 Thu Jan  8 11:43:42 2009
@@ -60,4 +60,12 @@
         assertTextPresent(
                 "Spring context contains 2 beans assignable to type 
org.example.testapp.services.Flintstone: barney, fred.");
     }
+
+    @Test
+    public void factory_provided_beans_accessible() throws Exception
+    {
+        open(BASE_URL);
+
+        assertEquals(getText("viaFactory"), "Instantiated via a factory 
bean.");
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/pages/Start.java
 Thu Jan  8 11:43:42 2009
@@ -20,6 +20,7 @@
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.example.testapp.services.SpringStatusProvider;
 import org.example.testapp.services.Upcase;
+import org.example.testapp.services.ViaFactory;
 import org.springframework.context.ApplicationContext;
 
 import java.util.Arrays;
@@ -40,6 +41,10 @@
     @Property
     private SpringStatusProvider statusProvider;
 
+    @Inject
+    @Property
+    private ViaFactory viaFactory;
+
     void onSuccess()
     {
         input = upcaseBean.toUpperCase(input);

Added: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SpringStatusProviderFactory.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SpringStatusProviderFactory.java?rev=732804&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SpringStatusProviderFactory.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/SpringStatusProviderFactory.java
 Thu Jan  8 11:43:42 2009
@@ -0,0 +1,35 @@
+// Copyright 2009 The Apache Software Foundation
+//
+// Licensed 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.example.testapp.services;
+
+import org.springframework.beans.factory.FactoryBean;
+
+public class SpringStatusProviderFactory implements FactoryBean
+{
+    public Object getObject() throws Exception
+    {
+        return null;
+    }
+
+    public Class getObjectType()
+    {
+        return null;
+    }
+
+    public boolean isSingleton()
+    {
+        return false;
+    }
+}

Added: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactory.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactory.java?rev=732804&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactory.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactory.java
 Thu Jan  8 11:43:42 2009
@@ -0,0 +1,20 @@
+// Copyright 2009 The Apache Software Foundation
+//
+// Licensed 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.example.testapp.services;
+
+public interface ViaFactory
+{
+    public String getMessage();
+}

Added: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactoryFactory.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactoryFactory.java?rev=732804&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactoryFactory.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/java/org/example/testapp/services/ViaFactoryFactory.java
 Thu Jan  8 11:43:42 2009
@@ -0,0 +1,41 @@
+// Copyright 2009 The Apache Software Foundation
+//
+// Licensed 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.example.testapp.services;
+
+import org.springframework.beans.factory.FactoryBean;
+
+public class ViaFactoryFactory implements FactoryBean
+{
+    public Object getObject() throws Exception
+    {
+        return new ViaFactory()
+        {
+            public String getMessage()
+            {
+                return "Instantiated via a factory bean.";
+            }
+        };
+    }
+
+    public Class getObjectType()
+    {
+        return ViaFactory.class;
+    }
+
+    public boolean isSingleton()
+    {
+        return true;
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/Start.tml Thu Jan  
8 11:43:42 2009
@@ -19,6 +19,8 @@
             <dd id="beans">${springBeans}</dd>
             <dt>Filter message:</dt>
             <dd id="message">${statusProvider.status}</dd>
+            <dt>Via factory:</dt>
+            <dd id="viaFactory">${viaFactory.message}</dd>
         </dl>
 
     </body>

Modified: 
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml?rev=732804&r1=732803&r2=732804&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-spring/src/test/webapp/WEB-INF/applicationContext.xml
 Thu Jan  8 11:43:42 2009
@@ -29,5 +29,7 @@
 
     <bean id="fred" class="org.example.testapp.services.FlintstoneImpl"/>
     <bean id="barney" class="org.example.testapp.services.FlintstoneImpl"/>
+
+    <bean id="viaFactory" 
class="org.example.testapp.services.ViaFactoryFactory"/>
 </beans>
 


Reply via email to