Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java (original) +++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java Thu Mar 29 15:45:36 2007 @@ -330,56 +330,6 @@ } @Test - public void inject_service_annotation_with_symbol() - { - Registry r = buildRegistry(IndirectionModule.class); - - Indirection outer = r.getService("Outer", Indirection.class); - - assertEquals(outer.getName(), "OUTER[INNER]"); - } - - @Test - public void inject_annotation_with_symbol() - { - Registry r = buildRegistry(IndirectionModule.class); - - Indirection outer = r.getService("Outer2", Indirection.class); - - assertEquals(outer.getName(), "OUTER2[INNER]"); - } - - @Test - public void registry_get_service_with_symbol() - { - Registry r = buildRegistry(IndirectionModule.class); - - Indirection inner = r.getService("${indirection.inner}", Indirection.class); - - assertEquals(inner.getName(), "INNER"); - } - - @Test - public void registry_get_object_with_symbol() - { - Registry r = buildRegistry(IndirectionModule.class); - - Indirection inner = r.getObject("${indirection.object-inner}", Indirection.class); - - assertEquals(inner.getName(), "INNER"); - } - - @Test - public void inject_annotation_literal_value() - { - Registry r = buildRegistry(InjectLiteralModule.class); - - IntHolder holder = r.getService(IntHolder.class); - - assertEquals(holder.getValue(), 42); - } - - @Test public void access_to_services_ignores_case() { Registry r = buildRegistry(FredModule.class);
Added: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ValueObjectProviderTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ValueObjectProviderTest.java?view=auto&rev=523862 ============================================================================== --- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ValueObjectProviderTest.java (added) +++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/services/ValueObjectProviderTest.java Thu Mar 29 15:45:36 2007 @@ -0,0 +1,82 @@ +// Copyright 2007 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.apache.tapestry.ioc.internal.services; + +import java.lang.annotation.Annotation; + +import org.apache.tapestry.ioc.AnnotationProvider; +import org.apache.tapestry.ioc.ServiceLocator; +import org.apache.tapestry.ioc.annotations.Value; +import org.apache.tapestry.ioc.services.SymbolSource; +import org.apache.tapestry.ioc.services.TypeCoercer; +import org.apache.tapestry.ioc.test.IOCTestCase; +import org.testng.annotations.Test; + +public class ValueObjectProviderTest extends IOCTestCase +{ + @Test + public void no_value_annotation() + { + SymbolSource symbolSource = newSymbolSource(); + TypeCoercer coercer = newTypeCoercer(); + AnnotationProvider annotationProvider = newAnnotationProvider(); + ServiceLocator locator = newServiceLocator(); + + train_getAnnotation(annotationProvider, Value.class, null); + + replay(); + + ValueObjectProvider provider = new ValueObjectProvider(symbolSource, coercer); + + assertNull(provider.provide(Runnable.class, annotationProvider, locator)); + + verify(); + } + + @Test + public void value_annotation_present() + { + SymbolSource symbolSource = newSymbolSource(); + TypeCoercer coercer = newTypeCoercer(); + AnnotationProvider annotationProvider = newAnnotationProvider(); + ServiceLocator locator = newServiceLocator(); + String annotationValue = "${foo}"; + String expanded = "Foo"; + Runnable coerced = newRunnable(); + Value annotation = newMock(Value.class); + + train_getAnnotation(annotationProvider, Value.class, annotation); + + expect(annotation.value()).andReturn(annotationValue); + + train_expandSymbols(symbolSource, annotationValue, expanded); + train_coerce(coercer, expanded, Runnable.class, coerced); + + replay(); + + ValueObjectProvider provider = new ValueObjectProvider(symbolSource, coercer); + + assertSame(provider.provide(Runnable.class, annotationProvider, locator), coerced); + + verify(); + } + + protected final <T extends Annotation> void train_getAnnotation( + AnnotationProvider annotationProvider, Class<T> annotationClass, T annotation) + { + expect(annotationProvider.getAnnotation(annotationClass)).andReturn(annotation) + .atLeastOnce(); + } +} Modified: tapestry/tapestry5/tapestry-project/trunk/pom.xml URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-project/trunk/pom.xml?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-project/trunk/pom.xml (original) +++ tapestry/tapestry5/tapestry-project/trunk/pom.xml Thu Mar 29 15:45:36 2007 @@ -215,8 +215,8 @@ </reporting> <repositories> <repository> - <id>apache.snapshots</id> - <url>http://people.apache.org/repo/m2-snapshot-repository/</url> + <id>tapestry-snapshots</id> + <url>http://people.apache.org/~hlship/tapestry-snapshot-repository/</url> </repository> <repository> <id>codehaus.snapshots</id> @@ -231,8 +231,8 @@ </repositories> <pluginRepositories> <pluginRepository> - <id>apache.snapshots</id> - <url> http://people.apache.org/repo/m2-snapshot-repository </url> + <id>tapestry-snapshots</id> + <url>http://people.apache.org/~hlship/tapestry-snapshot-repository</url> </pluginRepository> <!-- I believe a version of the surefire plugin lives here. --> <pluginRepository> @@ -266,15 +266,15 @@ <distributionManagement> <site> <id>tapestry</id> - <url> scpexe://people.apache.org/www/tapestry.apache.org/tapestry5/ </url> + <url>scpexe://people.apache.org/www/tapestry.apache.org/tapestry5/ </url> </site> <repository> <id>tapestry</id> - <url> scpexe://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository </url> + <url>scpexe://people.apache.org/~hlship/public_html/tapestry-ibiblio-rsynch-repository</url> </repository> <snapshotRepository> <id>tapestry</id> - <url> scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository </url> + <url>scpexe://people.apache.org/~hlship/public_html/tapestry-snapshot-repository</url> </snapshotRepository> </distributionManagement> Modified: tapestry/tapestry5/tapestry-project/trunk/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-project/trunk/src/site/apt/index.apt?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-project/trunk/src/site/apt/index.apt (original) +++ tapestry/tapestry5/tapestry-project/trunk/src/site/apt/index.apt Thu Mar 29 15:45:36 2007 @@ -94,8 +94,13 @@ New and Noteworthy + Another pass at simplifying and improving {{{tapestry-ioc/}tapestry-ioc}}, using ideas + from {{{http://code.google.com/p/google-guice/}Guice}}. The idea is to combine + @Inject with other annotations to supply overrding details (but @Inject on its own + is usually sufficient). + The {{{tapestry-ioc/}tapestry-ioc}} module has been simplified, removing the concept - of module ids and namespaces, as well as private services. + of module ids and namespaces, as well as private services. Work has been started on {{{http://hibernate.org}Hibernate}} integration in the new {{{tapestry-hibernate/}tapestry-hibernate}} module. Added: tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringBean.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringBean.java?view=auto&rev=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringBean.java (added) +++ tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringBean.java Thu Mar 29 15:45:36 2007 @@ -0,0 +1,36 @@ +// Copyright 2007 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.apache.tapestry.spring; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Indicates that the injection is for a Spring bean. + */ [EMAIL PROTECTED]( +{ FIELD, PARAMETER }) [EMAIL PROTECTED] [EMAIL PROTECTED](RUNTIME) +public @interface SpringBean +{ + /** The name or id of the Spring bean to inject. */ + String value(); +} Modified: tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringModule.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringModule.java?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringModule.java (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringModule.java Thu Mar 29 15:45:36 2007 @@ -17,6 +17,8 @@ import org.apache.commons.logging.Log; import org.apache.tapestry.ioc.MappedConfiguration; import org.apache.tapestry.ioc.ObjectProvider; +import org.apache.tapestry.ioc.OrderedConfiguration; +import org.apache.tapestry.ioc.annotations.EagerLoad; import org.apache.tapestry.ioc.annotations.Inject; import org.apache.tapestry.ioc.annotations.InjectService; import org.apache.tapestry.services.Context; @@ -41,7 +43,7 @@ * href="http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#context-create">standard * way</a> (which involves adding a listener to the web.xml deployment descriptor). */ - public static WebApplicationContext build(@Inject("alias:context") + public static WebApplicationContext build(@InjectService("Context") Context context) { WebApplicationContext springContext = null; @@ -62,15 +64,14 @@ } /** - * Contributes a "spring:" provider, that obtains beans from the - * [EMAIL PROTECTED] #buildSpringObjectProvider(Log, Context) SpringObjectProvider service}. + * Contributes a provider named "Spring". */ public static void contributeMasterObjectProvider(@InjectService("SpringObjectProvider") ObjectProvider springObjectProvider, - MappedConfiguration<String, ObjectProvider> configuration) + OrderedConfiguration<ObjectProvider> configuration) { - configuration.add("spring", springObjectProvider); + configuration.add("Spring", springObjectProvider); } } Modified: tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/main/java/org/apache/tapestry/spring/SpringObjectProvider.java Thu Mar 29 15:45:36 2007 @@ -19,6 +19,7 @@ import java.util.Map; import org.apache.commons.logging.Log; +import org.apache.tapestry.ioc.AnnotationProvider; import org.apache.tapestry.ioc.ObjectProvider; import org.apache.tapestry.ioc.ServiceLocator; import org.springframework.web.context.WebApplicationContext; @@ -31,45 +32,69 @@ */ class SpringObjectProvider implements ObjectProvider { - private final WebApplicationContext _context; + private final Log _log; - private final Map<String, String> _beanNames = newCaseInsensitiveMap(); + private final WebApplicationContext _context; - public SpringObjectProvider(Log log, WebApplicationContext context) - { - _context = context; + private boolean _beansNamesLoaded = false; - // Build up a case-insensitive mapping of bean names. + private final Map<String, String> _beanNames = newCaseInsensitiveMap(); - for (String name : _context.getBeanDefinitionNames()) + public SpringObjectProvider(Log log, WebApplicationContext context) { - _beanNames.put(name, name); + _log = log; + + _context = context; } - log.info(SpringMessages.contextStartup(_beanNames.keySet())); - } + private synchronized void loadBeanNames() + { + if (_beansNamesLoaded) return; - /** - * The expression is the name of a spring bean inside the context. - */ - public <T> T provide(String expression, Class<T> objectType, ServiceLocator locator) - { - // Attempt to convert from the base insensitive name to the name as defined by Spring - // (which is, to my knowledge) case sensitive. - String effectiveName = _beanNames.containsKey(expression) ? _beanNames.get(expression) - : expression; + for (String name : _context.getBeanDefinitionNames()) + { + _beanNames.put(name, name); + } - try - { - Object raw = _context.getBean(effectiveName, objectType); + _log.info(SpringMessages.contextStartup(_beanNames.keySet())); - return objectType.cast(raw); + _beansNamesLoaded = true; } - catch (Exception ex) + + /** + * The expression is the name of a spring bean inside the context. + */ + public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, + ServiceLocator locator) { - throw new RuntimeException(SpringMessages.beanAccessFailure(effectiveName, objectType, ex), - ex); + SpringBean annotation = annotationProvider.getAnnotation(SpringBean.class); + + if (annotation == null) return null; + + String beanName = annotation.value(); + + // Need to defer loading bean names to avoid some bootstrapping problems. + + loadBeanNames(); + + // Attempt to convert from the base insensitive name to the name as defined by Spring + // (which is, to my knowledge) case sensitive. + String effectiveName = _beanNames.containsKey(beanName) ? _beanNames.get(beanName) + : beanName; + + try + { + Object raw = _context.getBean(effectiveName, objectType); + + return objectType.cast(raw); + } + catch (Exception ex) + { + throw new RuntimeException(SpringMessages.beanAccessFailure( + effectiveName, + objectType, + ex), ex); + } } - } } Modified: tapestry/tapestry5/tapestry-spring/trunk/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/site/apt/index.apt?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/site/apt/index.apt (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/site/apt/index.apt Thu Mar 29 15:45:36 2007 @@ -55,13 +55,16 @@ * Injecting beans Inside your component classes, you may use the - {{{http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/Inject.html}Inject}} annotation. The annotation - value should be "spring:" + the name of the bean. Example: + {{{http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/annotations/Inject.html}Inject}} annotation in combination with + the {{{apidocs/org/apache/tapestry/spring/SpringBean.html}SpringBean}} annotation (to define the name of the bean). +----+ - @Inject("spring:userDAO") + @Inject + @SpringBean("userDAO") private UserDAO _userDAO; +----+ + + This also works with parameters to service builder methods. Case Insensitivity Copied: tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SampleBean.java (from r515167, tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringBean.java) URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SampleBean.java?view=diff&rev=523862&p1=tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringBean.java&r1=515167&p2=tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SampleBean.java&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringBean.java (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SampleBean.java Thu Mar 29 15:45:36 2007 @@ -14,7 +14,7 @@ package org.apache.tapestry.spring; -public interface SpringBean +public interface SampleBean { } Modified: tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/apache/tapestry/spring/SpringObjectProviderTest.java Thu Mar 29 15:45:36 2007 @@ -15,6 +15,7 @@ package org.apache.tapestry.spring; import org.apache.commons.logging.Log; +import org.apache.tapestry.ioc.AnnotationProvider; import org.apache.tapestry.ioc.ObjectProvider; import org.apache.tapestry.ioc.ServiceLocator; import org.apache.tapestry.test.TapestryTestCase; @@ -23,121 +24,149 @@ public class SpringObjectProviderTest extends TapestryTestCase { - private static final String STARTUP_MESSAGE = "Using Spring WebApplicationContext containing beans: "; + private static final String STARTUP_MESSAGE = "Using Spring WebApplicationContext containing beans: "; - private static final String BEAN_NAME = "mySpringBean"; + private static final String BEAN_NAME = "mySpringBean"; - @Test - public void failure_getting_bean_from_context() - { - Log log = newLog(); - WebApplicationContext webContext = newWebApplicationContext(); - ServiceLocator locator = newServiceLocator(); - Throwable t = new RuntimeException("Simulated failure."); - - train_getBeanDefinitionNames(webContext, BEAN_NAME); - - log.info(STARTUP_MESSAGE + BEAN_NAME); + @Test + public void failure_getting_bean_from_context() + { + Log log = newLog(); + WebApplicationContext webContext = newWebApplicationContext(); + ServiceLocator locator = newServiceLocator(); + Throwable t = new RuntimeException("Simulated failure."); + AnnotationProvider annotationProvider = newAnnotationProvider(); + SpringBean annotation = newSpringBean(BEAN_NAME); + + train_getBeanDefinitionNames(webContext, BEAN_NAME); + + log.info(STARTUP_MESSAGE + BEAN_NAME); + + train_getAnnotation(annotationProvider, SpringBean.class, annotation); + + expect(webContext.getBean(BEAN_NAME, SampleBean.class)).andThrow(t); + + replay(); + + ObjectProvider provider = new SpringObjectProvider(log, webContext); + + try + { + provider.provide(SampleBean.class, annotationProvider, locator); + unreachable(); + } + catch (RuntimeException ex) + { + assertEquals( + ex.getMessage(), + "A failure occured obtaining Spring bean \'mySpringBean\' (of type org.apache.tapestry.spring.SampleBean): Simulated failure."); + assertSame(ex.getCause(), t); + } - expect(webContext.getBean(BEAN_NAME, SpringBean.class)).andThrow(t); + verify(); + } - replay(); + private SpringBean newSpringBean(String name) + { + SpringBean bean = newMock(SpringBean.class); - ObjectProvider provider = new SpringObjectProvider(log, webContext); + expect(bean.value()).andReturn(name).atLeastOnce(); - try - { - provider.provide(BEAN_NAME, SpringBean.class, locator); - unreachable(); + return bean; } - catch (RuntimeException ex) + + @Test + public void get_bean_from_context() { - assertEquals( - ex.getMessage(), - "A failure occured obtaining Spring bean \'mySpringBean\' (of type org.apache.tapestry.spring.SpringBean): Simulated failure."); - assertSame(ex.getCause(), t); - } + Log log = newLog(); + WebApplicationContext webContext = newWebApplicationContext(); + ServiceLocator locator = newServiceLocator(); + AnnotationProvider annotationProvider = newAnnotationProvider(); + SpringBean annotation = newSpringBean(BEAN_NAME); + + SampleBean bean = newMock(SampleBean.class); + + train_getBeanDefinitionNames(webContext, "fred", "barney", BEAN_NAME); - verify(); - } + log.info(STARTUP_MESSAGE + "barney, fred, " + BEAN_NAME); - @Test - public void get_bean_from_context() - { - Log log = newLog(); - WebApplicationContext webContext = newWebApplicationContext(); - ServiceLocator locator = newServiceLocator(); - SpringBean bean = newMock(SpringBean.class); + train_getAnnotation(annotationProvider, SpringBean.class, annotation); - train_getBeanDefinitionNames(webContext, "fred", "barney", BEAN_NAME); + expect(webContext.getBean(BEAN_NAME, SampleBean.class)).andReturn(bean); - log.info(STARTUP_MESSAGE + "barney, fred, " + BEAN_NAME); + replay(); - expect(webContext.getBean(BEAN_NAME, SpringBean.class)).andReturn(bean); + ObjectProvider provider = new SpringObjectProvider(log, webContext); - replay(); + assertSame(provider.provide(SampleBean.class, annotationProvider, locator), bean); - ObjectProvider provider = new SpringObjectProvider(log, webContext); + verify(); + } - assertSame(provider.provide(BEAN_NAME, SpringBean.class, locator), bean); + @Test + public void bean_name_is_case_insensitive_if_in_bean_definitions() + { + Log log = newLog(); + WebApplicationContext webContext = newWebApplicationContext(); + ServiceLocator locator = newServiceLocator(); + SampleBean bean = newMock(SampleBean.class); + AnnotationProvider annotationProvider = newAnnotationProvider(); + SpringBean annotation = newSpringBean(BEAN_NAME.toUpperCase()); - verify(); - } + train_getBeanDefinitionNames(webContext, "fred", "barney", BEAN_NAME); - @Test - public void bean_name_is_case_insensitive_if_in_bean_definitions() - { - Log log = newLog(); - WebApplicationContext webContext = newWebApplicationContext(); - ServiceLocator locator = newServiceLocator(); - SpringBean bean = newMock(SpringBean.class); + log.info(STARTUP_MESSAGE + "barney, fred, " + BEAN_NAME); - train_getBeanDefinitionNames(webContext, "fred", "barney", BEAN_NAME); + train_getAnnotation(annotationProvider, SpringBean.class, annotation); - log.info(STARTUP_MESSAGE + "barney, fred, " + BEAN_NAME); + expect(webContext.getBean(BEAN_NAME, SampleBean.class)).andReturn(bean); - expect(webContext.getBean(BEAN_NAME, SpringBean.class)).andReturn(bean); + replay(); - replay(); + ObjectProvider provider = new SpringObjectProvider(log, webContext); - ObjectProvider provider = new SpringObjectProvider(log, webContext); + assertSame(provider.provide(SampleBean.class, annotationProvider, locator), bean); - assertSame(provider.provide(BEAN_NAME.toUpperCase(), SpringBean.class, locator), bean); + verify(); + } + + @Test + public void bean_name_outside_of_bean_definitions_supported_with_provided_case() + { + Log log = newLog(); + WebApplicationContext webContext = newWebApplicationContext(); + ServiceLocator locator = newServiceLocator(); + AnnotationProvider annotationProvider = newAnnotationProvider(); + SpringBean annotation = newSpringBean(BEAN_NAME); - verify(); - } + SampleBean bean = newMock(SampleBean.class); - @Test - public void bean_name_outside_of_bean_definitions_supported_with_provided_case() - { - Log log = newLog(); - WebApplicationContext webContext = newWebApplicationContext(); - ServiceLocator locator = newServiceLocator(); - SpringBean bean = newMock(SpringBean.class); + train_getBeanDefinitionNames(webContext, "fred", "barney"); - train_getBeanDefinitionNames(webContext, "fred", "barney"); + log.info(STARTUP_MESSAGE + "barney, fred"); - log.info(STARTUP_MESSAGE + "barney, fred"); + train_getAnnotation(annotationProvider, SpringBean.class, annotation); - expect(webContext.getBean(BEAN_NAME, SpringBean.class)).andReturn(bean); + expect(webContext.getBean(BEAN_NAME, SampleBean.class)).andReturn(bean); - replay(); + replay(); - ObjectProvider provider = new SpringObjectProvider(log, webContext); + ObjectProvider provider = new SpringObjectProvider(log, webContext); - assertSame(provider.provide(BEAN_NAME, SpringBean.class, locator), bean); + assertSame(provider.provide(SampleBean.class, annotationProvider, locator), bean); - verify(); - } + verify(); + } - protected final void train_getBeanDefinitionNames(WebApplicationContext context, String... names) - { - expect(context.getBeanDefinitionNames()).andReturn(names); - } + protected final void train_getBeanDefinitionNames(WebApplicationContext context, + String... names) + { + expect(context.getBeanDefinitionNames()).andReturn(names); + } - protected final WebApplicationContext newWebApplicationContext() - { - return newMock(WebApplicationContext.class); - } + protected final WebApplicationContext newWebApplicationContext() + { + return newMock(WebApplicationContext.class); + } } Modified: tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/example/testapp/pages/Start.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/example/testapp/pages/Start.java?view=diff&rev=523862&r1=523861&r2=523862 ============================================================================== --- tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/example/testapp/pages/Start.java (original) +++ tapestry/tapestry5/tapestry-spring/trunk/src/test/java/org/example/testapp/pages/Start.java Thu Mar 29 15:45:36 2007 @@ -16,30 +16,32 @@ import org.apache.tapestry.annotations.Inject; import org.apache.tapestry.annotations.Retain; +import org.apache.tapestry.spring.SpringBean; import org.example.testapp.services.Upcase; public class Start { - @Retain - private String _input; + @Retain + private String _input; - // Demonstrating case insensitivity - @Inject("Spring:Upcase") - private Upcase _upcaseBean; + // Demonstrating case insensitivity + @Inject + @SpringBean("Upcase") + private Upcase _upcaseBean; - void onSuccess() - { - _input = _upcaseBean.toUpperCase(_input); - } + void onSuccess() + { + _input = _upcaseBean.toUpperCase(_input); + } - public String getInput() - { - return _input; - } + public String getInput() + { + return _input; + } - public void setInput(String input) - { - _input = input; - } + public void setInput(String input) + { + _input = input; + } }
