Author: drobiazko
Date: Tue Jan 13 17:06:51 2009
New Revision: 734292

URL: http://svn.apache.org/viewvc?rev=734292&view=rev
Log:
TAP5-69: Add annotation, @Contribute, to allow service contributor methods to 
be arbitrary named

Added:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/Contribute.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationAmbiguousModule.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBinderMethodModule.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBuilderMethodModule.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationWithMarkerModule.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaMethodAnnotationModule.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
    tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/configuration.apt
    
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/Contribute.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/Contribute.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/Contribute.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/Contribute.java
 Tue Jan 13 17:06:51 2009
@@ -0,0 +1,38 @@
+// 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.apache.tapestry5.ioc.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * As an alternative to the naming convention, this annotation may be used to 
mark a method of a module
+ * as a service contributor method. If several implementations of a service 
interface are provided you should 
+ * disambiguate by providing marker annotations or use the naming convention 
(method starts with 'contribute').
+ */
+...@target({ METHOD })
+...@retention(RUNTIME)
+...@documented
+public @interface Contribute
+{
+    /**
+     * A type of a service to contribute into.
+     */
+    Class value();
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java?rev=734292&r1=734291&r2=734292&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
 Tue Jan 13 17:06:51 2009
@@ -116,6 +116,7 @@
 
         grind(methods, modulePreventsServiceDecoration);
         bind(methods, modulePreventsServiceDecoration);
+        contribute(methods, modulePreventsServiceDecoration);
 
         if (methods.isEmpty()) return;
 
@@ -148,6 +149,27 @@
     {
         return serviceDefs.get(serviceId);
     }
+    
+    public List<ServiceDef> getServiceDef(Class interfaceClass, 
Collection<Class> markers)
+    {
+        List<ServiceDef> result = newList();
+        
+        for (String id : getServiceIds())
+        {
+            ServiceDef def = getServiceDef(id);
+            
+            Class serviceInterface = def.getServiceInterface();
+
+            if(serviceInterface.equals(interfaceClass))
+            {
+                
+                if(CollectionFactory.newSet(markers).equals(def.getMarkers())){
+                    result.add(def);
+                }
+            }
+        }
+        return result;
+    }
 
     private void grind(Set<Method> remainingMethods, boolean 
modulePreventsServiceDecoration)
     {
@@ -186,20 +208,36 @@
                 remainingMethods.remove(m);
                 continue;
             }
+            
+            // contribute methods are handled later, after autobuilding is 
finished
+        }
+    }
+    
+    private void contribute(Set<Method> remainingMethods, boolean 
modulePreventsServiceDecoration)
+    {
+        Method[] methods = moduleClass.getMethods();
+        
+        for (Method m : methods)
+        {
+            String name = m.getName();
 
-            if (name.startsWith(CONTRIBUTE_METHOD_NAME_PREFIX))
+            if (m.isAnnotationPresent(Contribute.class) ||
+                    name.startsWith(CONTRIBUTE_METHOD_NAME_PREFIX))
             {
+ 
                 addContributionDef(m);
                 remainingMethods.remove(m);
                 continue;
             }
         }
+        
     }
 
     private void addContributionDef(Method method)
     {
-        String serviceId = stripMethodPrefix(method, 
CONTRIBUTE_METHOD_NAME_PREFIX);
-
+        
+        String serviceId = extractServiceId(method);
+        
         Class returnType = method.getReturnType();
         if (!returnType.equals(void.class)) 
logger.warn(IOCMessages.contributionWrongReturnType(method));
 
@@ -226,6 +264,33 @@
 
         contributionDefs.add(def);
     }
+    
+    private String extractServiceId(Method method)
+    {
+        Contribute annotation = method.getAnnotation(Contribute.class);
+        
+        if(annotation != null)
+        {
+            Class serviceClass = annotation.value();
+            Collection<Class> markers = extractMarkers(method);
+            
+            List<ServiceDef> defs = getServiceDef(serviceClass, markers);
+          
+           if(defs.isEmpty())
+           {
+               return serviceClass.getSimpleName();
+               
+           }
+           else if(defs.size() != 1)
+           {
+               throw new 
RuntimeException(IOCMessages.tooManyServicesForContributeMethod(method, 
serviceClass));
+              
+           }
+           return defs.get(0).getServiceId();
+        }
+        
+        return stripMethodPrefix(method, CONTRIBUTE_METHOD_NAME_PREFIX);
+    }
 
     private void addDecoratorDef(Method method)
     {

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=734292&r1=734291&r2=734292&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
 Tue Jan 13 17:06:51 2009
@@ -322,4 +322,9 @@
     {
         return MESSAGES.format("no-convention-service-implementation-found", 
clazz.getName(), clazz.getName());
     }
+    
+    static String tooManyServicesForContributeMethod(Method method, Class 
clazz)
+    {
+        return 
MESSAGES.format("too-many-services-for-annotated-contribute-method", 
asString(method), clazz.getName());
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties?rev=734292&r1=734291&r2=734292&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties
 Tue Jan 13 17:06:51 2009
@@ -81,3 +81,4 @@
 unexpected-service-proxy-provider=Unexpected service proxy provider when 
clearing the provider. This may indicate that you have multiple IoC Registries.
 no-proxy-provider=Service token for service '%s' can not be converted back 
into a proxy because no proxy provider has been registered. This may indicate 
that an IoC Registry has not been started yet.
 no-convention-service-implementation-found=No service implements the interface 
%s. Please provide the implementation %sImpl or bind the service interface to a 
service implementation.
+too-many-services-for-annotated-contribute-method=Contribute method %s (for 
service '%s') is marked by @Contribute annotation but several implementations 
of the service were found. You should provide a @Marker annotation or use a 
method that starts with 'contribute' to disambiguate the service the 
contribution is provided for. 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/configuration.apt
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/configuration.apt?rev=734292&r1=734291&r2=734292&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/configuration.apt 
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/configuration.apt Tue 
Jan 13 17:06:51 2009
@@ -80,6 +80,45 @@
   other contributing modules (such as the one that contributes the Office file 
services) may be written at 
   a much later date. With no change to the FileServicerDispatcher service or 
its module class,
   the new services "plug into" the overall solution, simply by having their 
JAR's on runtime classpath. 
+
+Annotated Service Contributor Methods
+
+  As an alternative to the naming convention, you may mark a method as a 
contributor method by placing the 
+  
{{{../apidocs/org/apache/tapestry5/ioc/annotations/Contribute.html}Contribute}} 
annotation on it. 
+  Tapestry will invoke this method just as if it starts with 'contribute'. The 
value attribute of the annotation 
+  is the type of service to contribute into. Based on this type Tapestry will 
find the service id provided as described 
+  {{{service.html}here}}. 
+  
++------+
+  @Contribute(Runnable.class)
+  public static void arbitraryNamedMethod(MappedConfiguration<String,String> 
configuration)
+  {
+    ...
+  }  
++------+
+
+  If several implementations of a service interface are provided Tapestry will 
throw an exception. 
+  In this case you should disambiguate by providing marker annotations or by 
using the naming convention (method starts with 'contribute').
+
++------+
+  public class MyModule
+  {
+    public static void bind(ServiceBinder binder)
+    {
+      binder.bind(Runnable.class, 
RunnableImpl.class).withId("Red").withMarker(RedMarker.class);
+      
+      binder.bind(Runnable.class, 
AnotherRunnableImpl.class).withId("BlueAndRed")
+            .withMarker(new Class[]{BlueMarker.class,RedMarker.class});
+    }
+  
+    @Contribute(Runnable.class)
+    @Marker({BlueMarker.class,RedMarker.class})
+    public static void arbitraryNamedMethod(MappedConfiguration<String,String> 
configuration)
+    {
+      ...
+    } 
+  } 
++------+
   
 Configuration Types
 

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationAmbiguousModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationAmbiguousModule.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationAmbiguousModule.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationAmbiguousModule.java
 Tue Jan 13 17:06:51 2009
@@ -0,0 +1,54 @@
+// 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.apache.tapestry5.ioc.internal;
+
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+
+public class ContributeViaAnnotationAmbiguousModule
+{
+    
+    public static void bind(ServiceBinder binder)
+    {
+        binder.bind(Runnable.class, RunnableImpl.class);
+        binder.bind(Runnable.class, 
AnotherRunnableImpl.class).withId("AnotherRunnableImpl");
+    }
+
+    
+    @Contribute(Runnable.class)
+    public void contributeMyService(MappedConfiguration configuration)
+    {
+        
+    }
+
+    public class RunnableImpl implements Runnable
+    {
+        public void run()
+        {
+            
+        }
+        
+    }
+    
+    public class AnotherRunnableImpl implements Runnable
+    {
+        public void run()
+        {
+            
+        }
+        
+    }
+}

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBinderMethodModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBinderMethodModule.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBinderMethodModule.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBinderMethodModule.java
 Tue Jan 13 17:06:51 2009
@@ -0,0 +1,45 @@
+// 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.apache.tapestry5.ioc.internal;
+
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+
+public class ContributeViaAnnotationCombindedWithBinderMethodModule
+{
+    
+    public static void bind(ServiceBinder binder)
+    {
+        binder.bind(Runnable.class, 
RunnableImpl.class).withId("RunnableBinderMethod");
+    }
+    
+    @Contribute(Runnable.class)
+    public static void contributeMyService(MappedConfiguration configuration)
+    {
+
+    }
+    
+    public class RunnableImpl implements Runnable
+    {
+
+        public void run()
+        {
+            
+        }
+        
+    }
+
+}

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBuilderMethodModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBuilderMethodModule.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBuilderMethodModule.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationCombindedWithBuilderMethodModule.java
 Tue Jan 13 17:06:51 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.apache.tapestry5.ioc.internal;
+
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.ServiceId;
+
+public class ContributeViaAnnotationCombindedWithBuilderMethodModule
+{
+    @ServiceId("RunnableBuilderMethod")
+    public Runnable build(){
+        return new Runnable(){
+
+            public void run()
+            {
+                
+            }
+            
+        };
+    }
+    
+    @Contribute(Runnable.class)
+    public void contributeMyService(MappedConfiguration configuration)
+    {
+
+    }
+
+}

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationWithMarkerModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationWithMarkerModule.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationWithMarkerModule.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaAnnotationWithMarkerModule.java
 Tue Jan 13 17:06:51 2009
@@ -0,0 +1,72 @@
+// 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.apache.tapestry5.ioc.internal;
+
+import org.apache.tapestry5.ioc.BlueMarker;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.RedMarker;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.Marker;
+
+public class ContributeViaAnnotationWithMarkerModule
+{
+    
+    public static void bind(ServiceBinder binder)
+    {
+        binder.bind(FoeService.class, 
FoeServiceImpl.class).withId("BlueAndRed")
+            .withMarker(new Class[]{RedMarker.class, BlueMarker.class});
+    }
+    
+    @Marker(RedMarker.class)
+    public static FoeService build()
+    { 
+        return new FoeService(){
+
+            public int foe()
+            {
+
+                return 0;
+            }};
+    }
+    
+    public static FoeService buildWithoutMarker()
+    { 
+        return new FoeService(){
+
+            public int foe()
+            {
+
+                return 0;
+            }};
+    }
+
+    
+    @Contribute(FoeService.class)
+    @Marker({BlueMarker.class, RedMarker.class})
+    public void contributeMyService(MappedConfiguration configuration)
+    {
+        
+    }
+    
+    public class FoeServiceImpl implements FoeService{
+
+        public int foe()
+        {
+            return 0;
+        }
+        
+    }
+}

Added: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaMethodAnnotationModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaMethodAnnotationModule.java?rev=734292&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaMethodAnnotationModule.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ContributeViaMethodAnnotationModule.java
 Tue Jan 13 17:06:51 2009
@@ -0,0 +1,29 @@
+// 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.apache.tapestry5.ioc.internal;
+
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+
+public class ContributeViaMethodAnnotationModule
+{
+    
+    @Contribute(Runnable.class)
+    public void contributeMyService(MappedConfiguration configuration)
+    {
+
+    }
+
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java?rev=734292&r1=734291&r2=734292&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImplTest.java
 Tue Jan 13 17:06:51 2009
@@ -278,6 +278,57 @@
     {
         attemptConfigurationMethod(SimpleModule.class, "Barney", 
"contributeBarney(Configuration)");
     }
+    
+    @Test
+    public void contribution_by_annotated_method()
+    {
+        attemptConfigurationMethod(ContributeViaMethodAnnotationModule.class, 
"Runnable", 
+                "contributeMyService(MappedConfiguration)");
+    }
+    
+    @Test
+    public void 
contribution_by_annotated_method_when_service_id_provided_by_builder_method()
+    {
+        
attemptConfigurationMethod(ContributeViaAnnotationCombindedWithBuilderMethodModule.class,
 "RunnableBuilderMethod", 
+                "contributeMyService(MappedConfiguration)");
+    }
+    
+    @Test
+    public void 
contribution_by_annotated_method_when_service_id_provided_by_binder_method()
+    {
+        
+        
attemptConfigurationMethod(ContributeViaAnnotationCombindedWithBinderMethodModule.class,
 "RunnableBinderMethod", 
+            "contributeMyService(MappedConfiguration)");
+    }
+    
+    @Test
+    public void contribution_by_annotated_method_ambiguous()  throws Exception
+    {
+        Class moduleClass = ContributeViaAnnotationAmbiguousModule.class;
+        
+        Method m = moduleClass.getMethod("contributeMyService", 
MappedConfiguration.class);
+        
+        Logger logger = mockLogger();
+        
+        try
+        {
+            new DefaultModuleDefImpl(moduleClass, logger, classFactory);       
     
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertEquals(ex.getMessage(), 
IOCMessages.tooManyServicesForContributeMethod(m, Runnable.class));
+        }
+
+    }
+     
+    @Test
+    public void contribution_by_annotated_method_with_marker()  throws 
Exception
+    {
+        
attemptConfigurationMethod(ContributeViaAnnotationWithMarkerModule.class, 
"BlueAndRed", 
+            "contributeMyService(MappedConfiguration)");
+
+    }
 
     @Test
     public void ordered_contribution_method()


Reply via email to