tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r730877 - in /tapestry/tapestry5/trunk/tapestry-ioc/src: main/java/org/apache/tapestry5/ioc/ main/java/org/apache/tapestry5/ioc/internal/ main/java/org/apache/tapestry5/ioc/internal/util/ test/java/org/apache/tapestry5/ioc/ test/java/org/ap...
Date Sat, 03 Jan 2009 00:34:28 GMT
Author: hlship
Date: Fri Jan  2 16:34:28 2009
New Revision: 730877

URL: http://svn.apache.org/viewvc?rev=730877&view=rev
Log:
TAP5-437: The OrderedConfiguration and MappedConfiguration interfaces should allow for override()
methods (similar to add()

Added:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OrderedConfigurationOverride.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ConfigurationOverrideModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/DuplicateConfigurationOverrideModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedConfigurationOverrideModule.java
Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/Orderer.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OrderedConfiguration.java
Fri Jan  2 16:34:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 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.
@@ -39,6 +39,17 @@
     void add(String id, T object, String... constraints);
 
     /**
+     * Overrides a normally contributed object.  Each override must match a single normally
contributed object.
+     *
+     * @param id          identifies object to override
+     * @param object      overriding object (may be null)
+     * @param constraints contrains for the overridden object, replacing constraints for
the original object (even if
+     *                    omitted, in which case the override object will have no orderring
contraints)
+     * @since 5.1.0.0
+     */
+    void override(String id, T object, String... constraints);
+
+    /**
      * Adds an ordered object by instantiating (with dependencies) the indicated class.
      *
      * @param id          of contribution (used for ordering)
@@ -47,4 +58,14 @@
      * @since 5.1.0.0
      */
     void addInstance(String id, Class<? extends T> clazz, String... constraints);
+
+    /**
+     * Instantiates an object and adds it as an override.
+     *
+     * @param id          of object to override
+     * @param clazz       to instantiate
+     * @param constraints override contraints
+     * @since 5.1.0.0
+     */
+    void overrideInstance(String id, Class<? extends T> clazz, String... constraints);
 }

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OrderedConfigurationOverride.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OrderedConfigurationOverride.java?rev=730877&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OrderedConfigurationOverride.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OrderedConfigurationOverride.java
Fri Jan  2 16:34:28 2009
@@ -0,0 +1,63 @@
+// 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.def.ContributionDef;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.Orderer;
+
+class OrderedConfigurationOverride<T>
+{
+    private final Orderer<T> orderer;
+
+    private final String id;
+
+    private final T replacementObject;
+
+    private final String[] constraints;
+
+    private final ContributionDef contribDef;
+
+    OrderedConfigurationOverride(Orderer<T> orderer, String id, T replacementObject,
String[] constraints,
+                                 ContributionDef contribDef)
+    {
+        this.orderer = orderer;
+        this.id = id;
+        this.replacementObject = replacementObject;
+        this.constraints = constraints;
+        this.contribDef = contribDef;
+    }
+
+    void apply()
+    {
+        try
+        {
+            orderer.override(id, replacementObject, constraints);
+        }
+        catch (Exception ex)
+        {
+            String message = String.format("Failure processing override from %s: %s",
+                                           contribDef,
+                                           InternalUtils.toMessage(ex));
+
+            throw new RuntimeException(message, ex);
+        }
+    }
+
+    public ContributionDef getContribDef()
+    {
+        return contribDef;
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
Fri Jan  2 16:34:28 2009
@@ -375,9 +375,10 @@
         Logger logger = getServiceLogger(serviceId);
 
         Orderer<T> orderer = new Orderer<T>(logger);
+        Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap();
 
         for (Module m : moduleToServiceDefs.keySet())
-            addToOrderedConfiguration(orderer, objectType, serviceDef, m);
+            addToOrderedConfiguration(orderer, overrides, objectType, serviceDef, m);
 
         // An ugly hack ... perhaps we should introduce a new builtin service so that this
can be
         // accomplished in the normal way?
@@ -395,6 +396,9 @@
             orderer.add("ServiceByMarker", (T) contribution);
         }
 
+        for (OrderedConfigurationOverride<T> override : overrides.values())
+            override.apply();
+
         return orderer.getOrdered();
     }
 
@@ -501,11 +505,12 @@
         }
     }
 
-    private <T> void addToOrderedConfiguration(Orderer<T> orderer,
-                                               Class<T> valueType,
+    private <T> void addToOrderedConfiguration(final Orderer<T> orderer,
+                                               final Map<String, OrderedConfigurationOverride<T>>
overrides,
+                                               final Class<T> valueType,
                                                ServiceDef serviceDef, final Module module)
     {
-        String serviceId = serviceDef.getServiceId();
+        final String serviceId = serviceDef.getServiceId();
         Set<ContributionDef> contributions = module.getContributorDefsForService(serviceId);
 
         if (contributions.isEmpty()) return;
@@ -515,10 +520,6 @@
 
         final ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef,
classFactory, logger);
 
-        final OrderedConfiguration<T> validating = new ValidatingOrderedConfigurationWrapper<T>(orderer,
serviceId,
-                                                                                        
       valueType,
-                                                                                        
       resources);
-
         for (final ContributionDef def : contributions)
         {
             String description = IOCMessages.invokingMethod(def);
@@ -530,6 +531,10 @@
             {
                 public void run()
                 {
+                    OrderedConfiguration<T> validating =
+                            new ValidatingOrderedConfigurationWrapper<T>(orderer, overrides,
def, serviceId, valueType,
+                                                                         resources);
+
                     def.contribute(module, resources, validating);
                 }
             });

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapper.java
Fri Jan  2 16:34:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 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.
@@ -16,8 +16,12 @@
 
 import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.def.ContributionDef;
+import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.internal.util.Orderer;
 
+import java.util.Map;
+
 /**
  * Wraps a {@link java.util.List} as a {@link org.apache.tapestry5.ioc.OrderedConfiguration},
implementing validation of
  * values provided to an {@link org.apache.tapestry5.ioc.OrderedConfiguration}.
@@ -34,11 +38,19 @@
 
     private final ObjectLocator locator;
 
+    private final Map<String, OrderedConfigurationOverride<T>> overrides;
+
+    private final ContributionDef contribDef;
 
-    public ValidatingOrderedConfigurationWrapper(Orderer<T> orderer, String serviceId,
Class expectedType,
+    public ValidatingOrderedConfigurationWrapper(Orderer<T> orderer,
+                                                 Map<String, OrderedConfigurationOverride<T>>
overrides,
+                                                 ContributionDef contribDef, String serviceId,
+                                                 Class expectedType,
                                                  ObjectLocator locator)
     {
         this.orderer = orderer;
+        this.overrides = overrides;
+        this.contribDef = contribDef;
         this.serviceId = serviceId;
         this.expectedType = expectedType;
         this.locator = locator;
@@ -51,11 +63,30 @@
         orderer.add(id, object, constraints);
     }
 
+    public void override(String id, T object, String... constraints)
+    {
+        Defense.notBlank(id, "id");
+
+        checkValid(object);
+
+        OrderedConfigurationOverride existing = overrides.get(id);
+        if (existing != null)
+            throw new IllegalArgumentException(String.format("Contribution '%s' has already
been overridden (by %s).",
+                                                             id, existing.getContribDef()));
+
+        overrides.put(id, new OrderedConfigurationOverride(orderer, id, object, constraints,
contribDef));
+    }
+
     public void addInstance(String id, Class<? extends T> clazz, String... constraints)
     {
         add(id, locator.autobuild(clazz), constraints);
     }
 
+    public void overrideInstance(String id, Class<? extends T> clazz, String... constraints)
+    {
+        override(id, locator.autobuild(clazz), constraints);
+    }
+
     private void checkValid(T object)
     {
         if (object == null || expectedType.isInstance(object)) return;

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/Orderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/Orderer.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/Orderer.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/Orderer.java
Fri Jan  2 16:34:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 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.
@@ -100,6 +100,24 @@
         idToOrderable.put(id, orderable);
     }
 
+    public void override(Orderable<T> orderable)
+    {
+        lock.check();
+
+        String id = orderable.getId();
+
+        Orderable<T> existing = idToOrderable.get(id);
+
+        if (existing == null)
+            throw new IllegalArgumentException(
+                    String.format("Override for object '%s' is invalid as it does not match
an existing object.", id));
+
+        orderables.remove(existing);
+        orderables.add(orderable);
+
+        idToOrderable.put(id, orderable);
+    }
+
     /**
      * Adds an object to be ordered.
      *
@@ -116,6 +134,13 @@
         add(new Orderable<T>(id, target, constraints));
     }
 
+    public void override(String id, T target, String... constraints)
+    {
+        lock.check();
+
+        override(new Orderable<T>(id, target, constraints));
+    }
+
     public List<T> getOrdered()
     {
         lock.lock();

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ConfigurationOverrideModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ConfigurationOverrideModule.java?rev=730877&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ConfigurationOverrideModule.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/ConfigurationOverrideModule.java
Fri Jan  2 16:34:28 2009
@@ -0,0 +1,24 @@
+// 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;
+
+public class ConfigurationOverrideModule
+{
+    public static void contributeOrderedNames(OrderedConfiguration<String> configuration)
+    {
+        configuration.add("wilma", "WILMA", "after:barney");
+        configuration.override("fred", "Mr. Flintstone", "after:*");
+    }
+}

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/DuplicateConfigurationOverrideModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/DuplicateConfigurationOverrideModule.java?rev=730877&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/DuplicateConfigurationOverrideModule.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/DuplicateConfigurationOverrideModule.java
Fri Jan  2 16:34:28 2009
@@ -0,0 +1,24 @@
+// 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;
+
+public class DuplicateConfigurationOverrideModule
+{
+    public static void contributeOrderedNames(OrderedConfiguration<String> configuration)
+    {
+        configuration.override("fred", "Fred Flintstone");
+    }
+}
+

Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedConfigurationOverrideModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedConfigurationOverrideModule.java?rev=730877&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedConfigurationOverrideModule.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/FailedConfigurationOverrideModule.java
Fri Jan  2 16:34:28 2009
@@ -0,0 +1,24 @@
+// 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;
+
+public class FailedConfigurationOverrideModule
+{
+    public static void contributeOrderedNames(OrderedConfiguration<String> configuration)
+    {
+        // Failure: wilma doesn't exist
+        configuration.override("wilma", "WILMA", "after:barney");
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
Fri Jan  2 16:34:28 2009
@@ -1143,4 +1143,58 @@
 
         r.shutdown();
     }
+
+    @Test
+    public void successful_ordered_configuration_override()
+    {
+        Registry r = buildRegistry(FredModule.class, BarneyModule.class, ConfigurationOverrideModule.class);
+
+        NameListHolder service = r.getService("OrderedNames", NameListHolder.class);
+
+        List<String> names = service.getNames();
+
+        assertEquals(names, Arrays.asList("BARNEY", "WILMA", "Mr. Flintstone"));
+    }
+
+    @Test
+    public void failed_ordered_configuration_override()
+    {
+        Registry r = buildRegistry(FredModule.class, BarneyModule.class, FailedConfigurationOverrideModule.class);
+
+        NameListHolder service = r.getService("OrderedNames", NameListHolder.class);
+
+        try
+        {
+            service.getNames();
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertMessageContains(ex,
+                                  "Failure processing override from org.apache.tapestry5.ioc.FailedConfigurationOverrideModule.contributeOrderedNames(OrderedConfiguration)",
+                                  "Override for object 'wilma' is invalid as it does not
match an existing object.");
+        }
+    }
+
+    @Test
+    public void duplicate_ordered_configuration_override()
+    {
+        Registry r = buildRegistry(FredModule.class, BarneyModule.class, ConfigurationOverrideModule.class,
+                                   DuplicateConfigurationOverrideModule.class);
+
+        NameListHolder service = r.getService("OrderedNames", NameListHolder.class);
+
+        try
+        {
+            service.getNames();
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            // Can't get too specific since we don't know which module will get processed
first
+            assertMessageContains(ex,
+                                  "Error invoking service contribution method ",
+                                  "Contribution 'fred' has already been overridden");
+        }
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ValidatingOrderedConfigurationWrapperTest.java
Fri Jan  2 16:34:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 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.
@@ -41,7 +41,7 @@
         replay();
 
         OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(
-                orderer, "Service", Runnable.class, null);
+                orderer, null, null, "Service", Runnable.class, null);
 
         wrapper.add("id", contribution, "after:pre", "before:post");
 
@@ -68,7 +68,7 @@
         replay();
 
         OrderedConfiguration<Map> wrapper = new ValidatingOrderedConfigurationWrapper<Map>(
-                orderer, "Service", Map.class, locator);
+                orderer, null, null, "Service", Map.class, locator);
 
         wrapper.addInstance("id", HashMap.class, "after:pre", "before:post");
 
@@ -86,7 +86,7 @@
         replay();
 
         OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(
-                orderer, "Service", Runnable.class, null);
+                orderer, null, null, "Service", Runnable.class, null);
 
         wrapper.add("id", null);
 
@@ -104,7 +104,7 @@
 
         replay();
 
-        OrderedConfiguration wrapper = new ValidatingOrderedConfigurationWrapper(orderer,
"Service",
+        OrderedConfiguration wrapper = new ValidatingOrderedConfigurationWrapper(orderer,
null, null, "Service",
                                                                                  Runnable.class,
null);
 
         try

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java?rev=730877&r1=730876&r2=730877&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/OrdererTest.java
Fri Jan  2 16:34:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 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.
@@ -46,6 +46,57 @@
     }
 
     @Test
+    public void override()
+    {
+        Logger logger = mockLogger();
+
+        replay();
+
+        Orderer<String> o = new Orderer<String>(logger);
+
+        o.add("fred", "FRED");
+        o.add("barney", "BARNEY");
+        o.add("wilma", "WILMA");
+        o.add("betty", "BETTY");
+
+        o.override("barney", "Mr. Rubble", "before:*");
+
+        List<String> ordered = o.getOrdered();
+
+        assertEquals(ordered, Arrays.asList("Mr. Rubble", "FRED", "WILMA", "BETTY"));
+
+        verify();
+    }
+
+    @Test
+    public void failed_override()
+    {
+        Logger logger = mockLogger();
+
+        replay();
+
+        Orderer<String> o = new Orderer<String>(logger);
+
+        o.add("fred", "FRED");
+        o.add("barney", "BARNEY");
+        o.add("wilma", "WILMA");
+        o.add("betty", "BETTY");
+
+        try
+        {
+            o.override("bambam", "Mr. Rubble JR.", "before:*");
+            unreachable();
+        }
+        catch (IllegalArgumentException ex)
+        {
+            assertEquals(ex.getMessage(),
+                         "Override for object 'bambam' is invalid as it does not match an
existing object.");
+        }
+
+        verify();
+    }
+
+    @Test
     public void missing_constraint_type()
     {
         Logger logger = mockLogger();



Mime
View raw message