incubator-composer-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject svn commit: r613775 [10/15] - in /incubator/composer: ./ core/ core/src/ core/src/java/ core/src/java/org/ core/src/java/org/apache/ core/src/java/org/apache/composer/ core/src/java/org/apache/composer/core/ core/src/java/org/apache/composer/core/adapt...
Date Mon, 21 Jan 2008 06:41:50 GMT
Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/OptInCachingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/OptInCachingTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/OptInCachingTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/OptInCachingTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentFactory;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.adapters.InstanceAdapter;
+import org.apache.composer.core.injectors.ConstructorInjection;
+import org.apache.composer.core.injectors.ConstructorInjector;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.tck.AbstractComponentFactoryTest;
+
+
+/**
+ * @author <a href="Rafal.Krzewski">rafal@caltha.pl</a>
+ */
+public class OptInCachingTestCase extends AbstractComponentFactoryTest {
+
+    protected ComponentFactory createComponentFactory() {
+        return new OptInCaching().wrap(new ConstructorInjection());
+    }
+
+    @Test public void testAddComponentDoesNotUseCachingBehaviorByDefault() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.addComponent("foo", String.class);
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(ConstructorInjector.class, foo.getClass());
+    }
+
+    @Test public void testAddComponentUsesOptinBehaviorWithRedundantCacheProperty() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.change(Characteristics.CACHE).addComponent("foo", String.class);
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(Cached.class, foo.getClass());
+        assertEquals(ConstructorInjector.class, ((AbstractBehavior) foo).getDelegate().getClass());
+    }
+
+    @Test public void testAddComponentNoesNotUseOptinBehaviorWhenNoCachePropertyIsSpecified() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.change(Characteristics.NO_CACHE).addComponent("foo", String.class);
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(ConstructorInjector.class, foo.getClass());
+    }
+
+    @Test public void testAddAdapterUsesDoesNotUseCachingBehaviorByDefault() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.addAdapter(new InstanceAdapter("foo", "bar", new NullLifecycleStrategy(), new NullComponentMonitor()));
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(InstanceAdapter.class, foo.getClass());
+    }
+
+    @Test public void testAddAdapterUsesCachingBehaviorWithHideImplProperty() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.change(Characteristics.CACHE).addAdapter(new InstanceAdapter("foo", "bar", new NullLifecycleStrategy(), new NullComponentMonitor()));
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(Cached.class, foo.getClass());
+        assertEquals(InstanceAdapter.class, ((AbstractBehavior) foo).getDelegate().getClass());
+    }
+
+    @Test public void testAddAdapterNoesNotUseImplementationHidingBehaviorWhenNoCachePropertyIsSpecified() {
+        DefaultContainer pico =
+            new DefaultContainer(new OptInCaching().wrap(new ConstructorInjection()));
+        pico.change(Characteristics.NO_CACHE).addAdapter(new InstanceAdapter("foo", "bar", new NullLifecycleStrategy(), new NullComponentMonitor()));
+        ComponentAdapter foo = pico.getComponentAdapter("foo");
+        assertEquals(InstanceAdapter.class, foo.getClass());
+    }
+
+
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingBehaviorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingBehaviorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingBehaviorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingBehaviorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.apache.composer.core.testmodel.CoupleBean;
+
+/**
+ *
+ * @author greg
+ */
+public class PropertyApplyingBehaviorTestCase {
+    @Test public void testBeanPropertyComponentAdapterCanUsePropertyEditors() {
+        Object c = PropertyApplicator.convert(CoupleBean.class.getName(), "a's name:Camilla;b's name:Charles;", this.getClass().getClassLoader());
+        assertNotNull(c);
+        assertTrue(c instanceof CoupleBean);
+        assertEquals("Camilla", ((CoupleBean) c).getPersonA().getName());
+        assertEquals("Charles", ((CoupleBean) c).getPersonB().getName());
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/PropertyApplyingTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,425 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.swing.JLabel;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentFactory;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.injectors.AdaptingInjection;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.tck.AbstractComponentFactoryTest;
+import org.apache.composer.core.testmodel.SimpleTouchable;
+import org.apache.composer.core.testmodel.Touchable;
+
+
+/**
+ * @author Aslak Helles&oslash;y
+ * @author Mirko Novakovic
+ */
+public class PropertyApplyingTestCase extends AbstractComponentFactoryTest {
+
+    public static class Foo {
+        public String message;
+
+        public void setMessage(String message) {
+            this.message = message;
+        }
+    }
+
+    public static class Failing {
+        public void setMessage(String message) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+    }
+
+    /**
+     * Class that contains all types of Java primitives, to test if they are
+     * set correctly.
+     *
+     * @author Mirko Novakovic
+     */
+    public static class Primitives {
+        public byte byte_;
+        public short short_;
+        public int int_;
+        public long long_;
+        public float float_;
+        public double double_;
+        public boolean boolean_;
+        public char char_;
+        public File file_;
+        public URL url_;
+        public Class class_;
+        public String string_;
+
+        public void setClass_(Class class_) {
+            this.class_ = class_;
+        }
+
+        public void setString_(String string_) {
+            this.string_ = string_;
+        }
+
+        public void setBoolean_(boolean boolean_) {
+            this.boolean_ = boolean_;
+        }
+
+        public void setByte_(byte byte_) {
+            this.byte_ = byte_;
+        }
+
+        public void setChar_(char char_) {
+            this.char_ = char_;
+        }
+
+        public void setDouble_(double double_) {
+            this.double_ = double_;
+        }
+
+        public void setFloat_(float float_) {
+            this.float_ = float_;
+        }
+
+        public void setInt_(int int_) {
+            this.int_ = int_;
+        }
+
+        public void setLong_(long long_) {
+            this.long_ = long_;
+        }
+
+        public void setShort_(short short_) {
+            this.short_ = short_;
+        }
+
+        public void setFile_(File file_) {
+            this.file_ = file_;
+        }
+
+        public void setUrl_(URL url_) {
+            this.url_ = url_;
+        }
+    }
+
+    public static class A {
+        private B b;
+
+        public void setB(B b) {
+            this.b = b;
+        }
+    }
+
+    public static class B {
+    }
+
+    @Test public void testSetProperties() {
+        ComponentAdapter adapter = createAdapterCallingSetMessage(Foo.class);
+        Foo foo = (Foo)adapter.getComponentInstance(null);
+        assertNotNull(foo);
+        assertEquals("hello", foo.message);
+    }
+
+    @Test public void testFailingSetter() {
+        ComponentAdapter adapter = createAdapterCallingSetMessage(Failing.class);
+        try {
+            adapter.getComponentInstance(null);
+            fail();
+        } catch (CompositionException e) {
+        }
+    }
+
+    protected ComponentFactory createComponentFactory() {
+        return new PropertyApplying().wrap(new AdaptingInjection());
+    }
+
+    @Test public void testPropertiesSetAfterAdapterCreationShouldBeTakenIntoAccount() {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     "foo",
+                                                                     Foo.class,
+                                                                     (Parameter[])null);
+
+        Map properties = new HashMap();
+        properties.put("message", "hello");
+        adapter.setProperties(properties);
+
+        Foo foo = (Foo)adapter.getComponentInstance(null);
+
+        assertEquals("hello", foo.message);
+    }
+
+    @Test public void testPropertySetAfterAdapterCreationShouldBeTakenIntoAccount() {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     "foo",
+                                                                     Foo.class,
+                                                                     (Parameter[])null);
+        adapter.setProperty("message", "hello");
+
+        Foo foo = (Foo)adapter.getComponentInstance(null);
+
+        assertEquals("hello", foo.message);
+    }
+
+
+    @Test public void testPropertiesTidiedUpAfterPicoUsage() {
+        DefaultContainer pico = new DefaultContainer(createComponentFactory());
+        pico.as(Characteristics.PROPERTY_APPLYING).addComponent("foo", Foo.class);
+        Foo foo = (Foo) pico.getComponent("foo");
+    }
+
+
+    @Test public void testDelegateIsAccessible() {
+        AbstractBehavior componentAdapter =
+            (AbstractBehavior)createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
+                                                                              new NullLifecycleStrategy(),
+                                                                              new Properties(Characteristics
+                                                                                  .CDI),
+                                                                              Touchable.class,
+                                                                              SimpleTouchable.class,
+                                                                              (Parameter[])null);
+
+        assertNotNull(componentAdapter.getDelegate());
+    }
+
+    private ComponentAdapter createAdapterCallingSetMessage(Class impl) {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+        Map properties = new HashMap();
+        properties.put("message", "hello");
+
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     impl,
+                                                                     impl,
+                                                                     (Parameter[])null);
+        adapter.setProperties(properties);
+        return adapter;
+    }
+
+    @Test public void testAllJavaPrimitiveAttributesShouldBeSetByTheAdapter() throws MalformedURLException {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+        Map properties = new HashMap();
+        properties.put("byte_", "1");
+        properties.put("short_", "2");
+        properties.put("int_", "3");
+        properties.put("long_", "4");
+        properties.put("float_", "5.0");
+        properties.put("double_", "6.0");
+        properties.put("char_", "a");
+        properties.put("boolean_", "true");
+        properties.put("file_", "/foo/bar");
+        properties.put("url_", "http://www.picocontainer.org/");
+        properties.put("string_", "g string");
+        properties.put("class_", "javax.swing.JLabel");
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     Primitives.class,
+                                                                     Primitives.class,
+                                                                     (Parameter[])null);
+        adapter.setProperties(properties);
+        Primitives primitives = (Primitives)adapter.getComponentInstance(null);
+
+        assertNotNull(primitives);
+        assertEquals(1, primitives.byte_);
+        assertEquals(2, primitives.short_);
+        assertEquals(3, primitives.int_);
+        assertEquals(4, primitives.long_);
+        assertEquals(5.0, primitives.float_, 0.1);
+        assertEquals(6.0, primitives.double_, 0.1);
+        assertEquals('a', primitives.char_);
+        assertEquals(true, primitives.boolean_);
+        assertEquals(new File("/foo/bar"), primitives.file_);
+        assertEquals(new URL("http://www.picocontainer.org/"), primitives.url_);
+        assertEquals("g string", primitives.string_);
+        assertEquals(JLabel.class, primitives.class_);
+    }
+
+    @Test public void testSetDependenComponentWillBeSetByTheAdapter() {
+        picoContainer.addComponent("b", B.class);
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+        Map properties = new HashMap();
+
+        // the second b is the key of the B implementation
+        properties.put("b", "b");
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     A.class,
+                                                                     A.class,
+                                                                     (Parameter[])null);
+        adapter.setProperties(properties);
+        picoContainer.addAdapter(adapter);
+        A a = picoContainer.getComponent(A.class);
+
+        assertNotNull(a);
+        assertNotNull(a.b);
+    }
+
+    @Test public void testPropertySetAfterWrappedAdapterCreationShouldBeTakenIntoAccount() {
+        Caching factory = (Caching) new Caching().wrap(createComponentFactory());
+
+        ComponentAdapter<?> adapter =
+            factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     "foo",
+                                                                     Foo.class,
+                                                                     (Parameter[])null);
+
+
+        PropertyApplicator pa = adapter.findAdapterOfType(PropertyApplicator.class);
+
+        pa.setProperty("message", "hello");
+
+        Foo foo = (Foo)adapter.getComponentInstance(null);
+
+        assertEquals("hello", foo.message);
+    }
+
+    @Test public void testSetBeanPropertiesWithValueObjects() {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+        Map properties = new HashMap();
+        properties.put("lenient", Boolean.FALSE);
+        properties.put("2DigitYearStart", new Date(0));
+
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     SimpleDateFormat.class,
+                                                                     SimpleDateFormat.class,
+                                                                     (Parameter[])null);
+        adapter.setProperties(properties);
+        picoContainer.addAdapter(adapter);
+
+
+        SimpleDateFormat dateFormat = picoContainer.getComponent(SimpleDateFormat.class);
+        assertNotNull(dateFormat);
+        assertEquals(false, dateFormat.isLenient());
+        assertEquals(new Date(0), dateFormat.get2DigitYearStart());
+    }
+
+
+    /** todo Is this test duplicated elsewhere?  --MR */
+    @Test public void testSetBeanPropertiesWithWrongNumberOfParametersThrowsPicoInitializationException() {
+        Object testBean = new Object() {
+            public void setMultiValues(String val1, String Val2) {
+                throw new IllegalStateException("Setter should never have been called");
+            }
+
+            public void setSomeString(String val1) {
+                throw new IllegalStateException("Setter should never have been called");
+            }
+        };
+
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     "TestBean",
+                                                                     testBean.getClass(),
+                                                                     (Parameter[])null);
+
+        Map properties = new HashMap();
+        properties.put("multiValues", "abcdefg");
+        adapter.setProperties(properties);
+
+        picoContainer.addAdapter(adapter);
+
+        try {
+            Object testResult = picoContainer.getComponent("TestBean");
+            fail(
+                "Getting a bad test result through PropertyApplicator should have thrown exception.  Instead got:" +
+                testResult);
+        } catch (CompositionException ex) {
+            //A-ok
+        }
+
+    }
+
+
+    @Test public void testSetBeanPropertiesWithInvalidValueTypes() {
+        PropertyApplying factory = (PropertyApplying)createComponentFactory();
+
+
+        Map properties = new HashMap();
+
+        // Set two digit year to a boolean (should throw error)
+        properties.put("2DigitYearStart", Boolean.FALSE);
+        PropertyApplicator adapter =
+            (PropertyApplicator)factory.createComponentAdapter(new NullComponentMonitor(),
+                                                                     new NullLifecycleStrategy(),
+                                                                     new Properties(Characteristics
+                                                                         .CDI),
+                                                                     SimpleDateFormat.class,
+                                                                     SimpleDateFormat.class,
+                                                                     (Parameter[])null);
+        adapter.setProperties(properties);
+        picoContainer.addAdapter(adapter);
+
+
+        try {
+            SimpleDateFormat dateFormat = picoContainer.getComponent(SimpleDateFormat.class);
+            fail(
+                "Getting a bad test result through PropertyApplicator should have thrown exception.  Instead got:" +
+                dateFormat);
+        } catch (ClassCastException ex) {
+            //A-ok
+        }
+
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/StoringTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/StoringTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/StoringTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/StoringTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,249 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+
+public class StoringTestCase {
+
+    public static class Foo {
+        public Foo(StringBuilder sb) {
+            sb.append("<Foo");
+        }
+    }
+
+    public static class Bar {
+        private final Foo foo;
+        public Bar(StringBuilder sb, Foo foo) {
+            this.foo = foo;
+            sb.append("<Bar");
+        }
+    }
+
+    @Test public void testThatForASingleThreadTheBehaviorIsTheSameAsPlainCaching() {
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        Storing storeCaching = new Storing();
+        DefaultContainer child = new DefaultContainer(storeCaching, parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+        Foo foo = child.getComponent(Foo.class);
+        Foo foo2 = child.getComponent(Foo.class);
+        assertNotNull(foo);
+        assertNotNull(foo2);
+        assertEquals(foo,foo2);
+        assertEquals("<Foo", sb.toString());
+        assertEquals("Stored:ConstructorInjector-class org.apache.composer.core.behaviors.StoringTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatTwoThreadsHaveSeparatedCacheValues() {
+
+        final Foo[] foos = new Foo[4];
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        final DefaultContainer child = new DefaultContainer(new Storing(), parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+        foos[0] = child.getComponent(Foo.class);
+
+        Thread thread = new Thread() {
+            public void run() {
+                foos[1] = child.getComponent(Foo.class);
+                foos[3] = child.getComponent(Foo.class);
+            }
+        };
+        thread.start();
+        foos[2] = child.getComponent(Foo.class);
+        sleepALittle();
+
+        assertNotNull(foos[0]);
+        assertNotNull(foos[1]);
+        assertNotNull(foos[2]);
+        assertNotNull(foos[3]);
+        assertSame(foos[0],foos[2]);
+        assertEquals(foos[1],foos[3]);
+        assertFalse(foos[0] == foos[1]);
+        assertEquals("<Foo<Foo", sb.toString());
+        assertEquals("Stored:ConstructorInjector-class org.apache.composer.core.behaviors.StoringTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatTwoThreadsHaveSeparatedCacheValuesForThreeScopeScenario() {
+
+        final Foo[] foos = new Foo[4];
+        final Bar[] bars = new Bar[4];
+
+        DefaultContainer appScope = new DefaultContainer(new Caching());
+        final DefaultContainer sessionScope = new DefaultContainer(new Storing(), appScope);
+        final DefaultContainer requestScope = new DefaultContainer(new Storing(), sessionScope);
+
+        appScope.addComponent(StringBuilder.class);
+        sessionScope.addComponent(Foo.class);
+        requestScope.addComponent(Bar.class);
+
+        StringBuilder sb = appScope.getComponent(StringBuilder.class);
+        foos[0] = sessionScope.getComponent(Foo.class);
+        bars[0] = requestScope.getComponent(Bar.class);
+
+        Thread thread = new Thread() {
+            public void run() {
+                foos[1] = sessionScope.getComponent(Foo.class);
+                bars[1] = requestScope.getComponent(Bar.class);
+                foos[3] = sessionScope.getComponent(Foo.class);
+                bars[3] = requestScope.getComponent(Bar.class);
+            }
+        };
+        thread.start();
+        foos[2] = sessionScope.getComponent(Foo.class);
+        bars[2] = requestScope.getComponent(Bar.class);
+        sleepALittle();
+
+        assertSame(bars[0],bars[2]);
+        assertEquals(bars[1],bars[3]);
+        assertFalse(bars[0] == bars[1]);
+        assertSame(bars[0].foo,foos[0]);
+        assertSame(bars[1].foo,foos[1]);
+        assertSame(bars[2].foo,foos[2]);
+        assertSame(bars[3].foo,foos[3]);
+        assertEquals("<Foo<Bar<Foo<Bar", sb.toString());
+        assertEquals("Stored:ConstructorInjector-class org.apache.composer.core.behaviors.StoringTestCase$Foo", sessionScope.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatCacheMapCanBeReUsedOnASubsequentThreadSimulatingASessionConcept() {
+
+        final Foo[] foos = new Foo[4];
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        final Storing storeCaching = new Storing();
+        final DefaultContainer child = new DefaultContainer(storeCaching, parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+
+        final Storing.StoreWrapper[] tmpMap = new Storing.StoreWrapper[1];
+        Thread thread = new Thread() {
+            public void run() {
+                foos[0] = child.getComponent(Foo.class);
+                foos[1] = child.getComponent(Foo.class);
+                tmpMap[0] = storeCaching.getCacheForThread();
+
+            }
+        };
+        thread.start();
+        sleepALittle();
+        thread = new Thread() {
+            public void run() {
+                storeCaching.putCacheForThread(tmpMap[0]);
+                foos[2] = child.getComponent(Foo.class);
+                foos[3] = child.getComponent(Foo.class);
+                tmpMap[0] = storeCaching.getCacheForThread();
+
+            }
+        };
+        thread.start();
+        sleepALittle();
+
+        assertNotNull(foos[0]);
+        assertNotNull(foos[1]);
+        assertNotNull(foos[2]);
+        assertNotNull(foos[3]);
+        assertSame(foos[0],foos[1]);
+        assertSame(foos[1],foos[2]);
+        assertSame(foos[2],foos[3]);
+        assertEquals("<Foo", sb.toString());
+        assertEquals("Stored:ConstructorInjector-class org.apache.composer.core.behaviors.StoringTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatCacheMapCanBeResetOnASubsequentThreadSimulatingASessionConcept() {
+
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        final Storing storeCaching = new Storing();
+        final DefaultContainer child = new DefaultContainer(storeCaching, parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+
+        Foo one = child.getComponent(Foo.class);
+        Foo two = child.getComponent(Foo.class);
+
+        assertNotNull(one);
+        assertNotNull(two);
+        assertSame(one,two);
+
+        storeCaching.resetCacheForThread();
+
+        Foo three = child.getComponent(Foo.class);
+        Foo four = child.getComponent(Foo.class);
+
+        assertNotNull(three);
+        assertNotNull(four);
+        assertNotSame(one,three);
+        assertSame(three,four);
+
+        assertEquals("<Foo<Foo", sb.toString());
+        assertEquals("Stored:ConstructorInjector-class org.apache.composer.core.behaviors.StoringTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatCacheMapCanBeDisabledSimulatingAnEndedRequest() {
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        final Storing storeCaching = new Storing();
+        final DefaultContainer child = new DefaultContainer(storeCaching, parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+
+        Foo one = child.getComponent(Foo.class);
+        Foo two = child.getComponent(Foo.class);
+
+        assertNotNull(one);
+        assertNotNull(two);
+        assertSame(one,two);
+
+        storeCaching.invalidateCacheForThread();
+
+        try {
+            Foo three = child.getComponent(Foo.class);
+            fail("should have barfed");
+        } catch (UnsupportedOperationException e) {
+            // expected
+        }
+    }
+
+
+    private void sleepALittle() {
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+        }
+    }
+
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/SynchronizedTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/SynchronizedTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/SynchronizedTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/SynchronizedTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,215 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Test;
+import org.apache.composer.core.BehaviorFactory;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.injectors.ConstructorInjection;
+import org.apache.composer.core.injectors.ConstructorInjector;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+/**
+ * @author Thomas Heller
+ * @author Aslak Helles&oslash;y
+ * @author J&ouml;rg Schaible
+ */
+public class SynchronizedTestCase {
+    private final Runner[] runner = new Runner[3];
+    private int blockerCounter = 0;
+
+    final class Runner implements Runnable {
+        public RuntimeException exception;
+        public Blocker blocker;
+        private final Container pico;
+
+        public Runner(Container pico) {
+            this.pico = pico;
+        }
+
+        public void run() {
+            try {
+                blocker = (Blocker) pico.getComponent("key");
+            } catch (RuntimeException e) {
+                exception = e;
+            }
+        }
+    }
+
+    public class Blocker {
+        public Blocker() throws InterruptedException {
+            final Thread thread = Thread.currentThread();
+            synchronized (thread) {
+                SynchronizedTestCase.this.blockerCounter++;
+                thread.wait();
+            }
+        }
+    }
+
+    private void initTest(ComponentAdapter componentAdapter) throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addComponent(this);
+        pico.addAdapter(componentAdapter);
+        blockerCounter = 0;
+
+        for(int i = 0; i < runner.length; ++i) {
+            runner[i] = new Runner(pico);
+        }
+        
+        Thread racer[] = new Thread[runner.length];
+        for(int i = 0; i < racer.length; ++i) {
+            racer[i] =  new Thread(runner[i]);
+        }
+
+        for (Thread aRacer2 : racer) {
+            aRacer2.start();
+            Thread.sleep(250);
+        }
+
+        for (Thread aRacer : racer) {
+            synchronized (aRacer) {
+                aRacer.notify();
+            }
+        }
+
+        for (Thread aRacer1 : racer) {
+            aRacer1.join();
+        }
+    }
+
+    @Test public void testRaceConditionIsHandledBySynchronizedComponentAdapter() throws InterruptedException {
+        ComponentAdapter componentAdapter = new Cached(new ConstructorInjector("key", Blocker.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false));
+        ComponentAdapter synchronizedComponentAdapter = makeComponentAdapter(componentAdapter);
+        initTest(synchronizedComponentAdapter);
+
+        assertEquals(1, blockerCounter);
+        for (Runner aRunner1 : runner) {
+            assertNull(aRunner1.exception);
+        }
+        for (Runner aRunner : runner) {
+            assertNotNull(aRunner.blocker);
+        }
+        for(int i = 1; i < runner.length; ++i) {
+            assertSame(runner[0].blocker, runner[i].blocker);
+        }
+    }
+
+    protected ComponentAdapter makeComponentAdapter(ComponentAdapter componentAdapter) {
+        return new Synchronized(componentAdapter);
+    }
+
+    @Test public void testRaceConditionIsNotHandledWithoutSynchronizedComponentAdapter() throws InterruptedException {
+        ComponentAdapter componentAdapter = new Cached(new ConstructorInjector("key", Blocker.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false));
+        initTest(componentAdapter);
+
+        assertNull(runner[0].exception);
+        assertEquals(3, blockerCounter);
+        for(int i = 1; i < runner.length; ++i) {
+            assertNull(runner[i].exception);
+        }
+    }
+
+    public void THIS_NATURALLY_FAILS_testSingletonCreationRace() throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addComponent("slow", SlowCtor.class);
+        runConcurrencyTest(pico);
+    }
+
+    public void THIS_NATURALLY_FAILS_testSingletonCreationWithSynchronizedAdapter() throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addAdapter(new Cached(makeComponentAdapter(new ConstructorInjector("slow", SlowCtor.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false))));
+        runConcurrencyTest(pico);
+    }
+
+    // This is overkill - an outer sync adapter is enough
+    @Test public void testSingletonCreationWithSynchronizedAdapterAndDoubleLocking() throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addAdapter(makeComponentAdapter(new Cached(new Synchronized(new ConstructorInjector("slow", SlowCtor.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false)))));
+        runConcurrencyTest(pico);
+    }
+
+    @Test public void testSingletonCreationWithSynchronizedAdapterOutside() throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addAdapter(makeComponentAdapter(new Cached(new ConstructorInjector("slow", SlowCtor.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false))));
+        runConcurrencyTest(pico);
+    }
+
+    @Test public void testSingletonCreationWithSynchronizedAdapterOutsideUsingFactory() throws InterruptedException {
+        DefaultContainer pico = new DefaultContainer(
+                makeBehaviorFactory().wrap(new Caching().wrap(new ConstructorInjection()))
+        );
+        pico.addComponent("slow", SlowCtor.class);
+        runConcurrencyTest(pico);
+    }
+
+    protected BehaviorFactory makeBehaviorFactory() {
+        return new Synchronizing();
+    }
+
+    private void runConcurrencyTest(final DefaultContainer pico) throws InterruptedException {
+        int size = 10;
+
+        Thread[] threads = new Thread[size];
+
+        final List out = Collections.synchronizedList(new ArrayList());
+
+        for (int i = 0; i < size; i++) {
+
+            threads[i] = new Thread(new Runnable() {
+                public void run() {
+                    try {
+                        out.add(pico.getComponent("slow"));
+                    } catch (Exception e) {
+                        // add ex? is e.equals(anotherEOfTheSameType) == true?
+                        out.add(new Date()); // add something else to indicate miss
+                    }
+                }
+            });
+        }
+
+        for (Thread thread1 : threads) {
+            thread1.start();
+        }
+        for (Thread thread : threads) {
+            thread.join();
+        }
+
+        List differentInstances = new ArrayList();
+
+        for (Object anOut : out) {
+
+            if (!differentInstances.contains(anOut)) {
+                differentInstances.add(anOut);
+            }
+        }
+
+        assertTrue("Only one singleton instance was created [we have " + differentInstances.size() + "]", differentInstances.size() == 1);
+    }
+
+    public static class SlowCtor {
+        public SlowCtor() throws InterruptedException {
+            Thread.sleep(50);
+        }
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/behaviors/ThreadCachingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/behaviors/ThreadCachingTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/behaviors/ThreadCachingTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/behaviors/ThreadCachingTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.behaviors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+
+public class ThreadCachingTestCase {
+
+    public static class Foo {
+        public Foo(StringBuilder sb) {
+            sb.append("<Foo");
+        }
+    }
+
+    public static class Bar {
+        private final Foo foo;
+        public Bar(StringBuilder sb, Foo foo) {
+            this.foo = foo;
+            sb.append("<Bar");
+        }
+    }
+
+    @Test public void testThatForASingleThreadTheBehaviorIsTheSameAsPlainCaching() {
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        DefaultContainer child = new DefaultContainer(new ThreadCaching(), parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+        Foo foo = child.getComponent(Foo.class);
+        Foo foo2 = child.getComponent(Foo.class);
+        assertNotNull(foo);
+        assertNotNull(foo2);
+        assertEquals(foo,foo2);
+        assertEquals("<Foo", sb.toString());
+        assertEquals("ThreadCached:ConstructorInjector-class org.apache.composer.core.behaviors.ThreadCachingTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatTwoThreadsHaveSeparatedCacheValues() {
+
+        final Foo[] foos = new Foo[4];
+
+        DefaultContainer parent = new DefaultContainer(new Caching());
+        final DefaultContainer child = new DefaultContainer(new ThreadCaching(), parent);
+
+        parent.addComponent(StringBuilder.class);
+        child.addComponent(Foo.class);
+
+        StringBuilder sb = parent.getComponent(StringBuilder.class);
+        foos[0] = child.getComponent(Foo.class);
+
+        Thread thread = new Thread() {
+            public void run() {
+                foos[1] = child.getComponent(Foo.class);
+                foos[3] = child.getComponent(Foo.class);
+            }
+        };
+        thread.start();
+        foos[2] = child.getComponent(Foo.class);
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+        }
+
+        assertNotNull(foos[0]);
+        assertNotNull(foos[1]);
+        assertNotNull(foos[2]);
+        assertNotNull(foos[3]);
+        assertSame(foos[0],foos[2]);
+        assertEquals(foos[1],foos[3]);
+        assertFalse(foos[0] == foos[1]);
+        assertEquals("<Foo<Foo", sb.toString());
+        assertEquals("ThreadCached:ConstructorInjector-class org.apache.composer.core.behaviors.ThreadCachingTestCase$Foo", child.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testThatTwoThreadsHaveSeparatedCacheValuesForThreeScopeScenario() {
+
+        final Foo[] foos = new Foo[4];
+        final Bar[] bars = new Bar[4];
+
+        DefaultContainer appScope = new DefaultContainer(new Caching());
+        final DefaultContainer sessionScope = new DefaultContainer(new ThreadCaching(), appScope);
+        final DefaultContainer requestScope = new DefaultContainer(new ThreadCaching(), sessionScope);
+
+        appScope.addComponent(StringBuilder.class);
+        sessionScope.addComponent(Foo.class);
+        requestScope.addComponent(Bar.class);
+
+        StringBuilder sb = appScope.getComponent(StringBuilder.class);
+        foos[0] = sessionScope.getComponent(Foo.class);
+        bars[0] = requestScope.getComponent(Bar.class);
+
+        Thread thread = new Thread() {
+            public void run() {
+                foos[1] = sessionScope.getComponent(Foo.class);
+                bars[1] = requestScope.getComponent(Bar.class);
+                foos[3] = sessionScope.getComponent(Foo.class);
+                bars[3] = requestScope.getComponent(Bar.class);
+            }
+        };
+        thread.start();
+        foos[2] = sessionScope.getComponent(Foo.class);
+        bars[2] = requestScope.getComponent(Bar.class);
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+        }
+
+        assertSame(bars[0],bars[2]);
+        assertEquals(bars[1],bars[3]);
+        assertFalse(bars[0] == bars[1]);
+        assertSame(bars[0].foo,foos[0]);
+        assertSame(bars[1].foo,foos[1]);
+        assertSame(bars[2].foo,foos[2]);
+        assertSame(bars[3].foo,foos[3]);
+        assertEquals("<Foo<Bar<Foo<Bar", sb.toString());
+        assertEquals("ThreadCached:ConstructorInjector-class org.apache.composer.core.behaviors.ThreadCachingTestCase$Foo", sessionScope.getComponentAdapter(Foo.class).toString());
+    }
+
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/CommandLineArgumentsContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/CommandLineArgumentsContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/CommandLineArgumentsContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/CommandLineArgumentsContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,193 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.annotations.Inject;
+import org.apache.composer.core.injectors.AbstractInjector;
+import org.apache.composer.core.injectors.AnnotatedFieldInjection;
+import org.apache.composer.core.injectors.SetterInjection;
+
+public class CommandLineArgumentsContainerTestCase {
+
+    @Test public void testBasicParsing() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {
+            "foo=bar", "foo2=12", "foo3=true", "foo4="
+        });
+        assertEquals("bar",apc.getComponent("foo"));
+        assertEquals("12",apc.getComponent("foo2"));
+        assertEquals("true",apc.getComponent("foo3"));
+        assertEquals("true",apc.getComponent("foo4"));
+    }
+
+    @Test public void testAsParentContainer() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {
+            "a=aaa", "b=bbb", "d=22"});
+        assertEquals("aaa",apc.getComponent("a"));
+        assertEquals("bbb",apc.getComponent("b"));
+        assertEquals("22",apc.getComponent("d"));
+
+        DefaultContainer dpc = new DefaultContainer(apc);
+        dpc.addComponent(NeedsString.class);
+        assertEquals("bbb", dpc.getComponent(NeedsString.class).val);
+    }
+
+    public static class NeedsString {
+        public String val;
+        public NeedsString(String b) {
+            val = b;
+        }
+    }
+
+    @Test public void testParsingWithDiffSeparator() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(":", new String[] {
+            "foo:bar", "foo2:12", "foo3:true"
+        });
+        assertEquals("bar",apc.getComponent("foo"));
+        assertEquals("12",apc.getComponent("foo2"));
+        assertEquals("true",apc.getComponent("foo3"));
+    }
+
+    @Test public void testParsingWithWrongSeparator() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(":", new String[] {
+            "foo=bar", "foo2=12", "foo3=true"
+        });
+        assertEquals("true",apc.getComponent("foo=bar"));
+        assertEquals("true",apc.getComponent("foo2=12"));
+        assertEquals("true",apc.getComponent("foo3=true"));
+    }
+
+    @Test public void testParsingOfPropertiesFile() throws IOException {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(":",
+                               new StringReader("foo:bar\nfoo2:12\nfoo3:true\n"));
+        assertEquals("bar",apc.getComponent("foo"));
+        assertEquals("12",apc.getComponent("foo2"));
+        assertEquals("true",apc.getComponent("foo3"));
+    }
+
+    @Test public void testParsingOfPropertiesFileAndArgs() throws IOException {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(":",
+                               new StringReader("foo:bar\nfoo2:12\n"), new String[] {"foo3:true"});
+        assertEquals("bar",apc.getComponent("foo"));
+        assertEquals("12",apc.getComponent("foo2"));
+        assertEquals("true",apc.getComponent("foo3"));
+    }
+
+    @Test public void testParsingOfPropertiesFileAndArgsWithClash() throws IOException {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(":",
+                               new StringReader("foo:bar\nfoo2:99\n"), new String[] {"foo2:12","foo3:true"});
+        assertEquals("bar",apc.getComponent("foo"));
+        assertEquals("12",apc.getComponent("foo2"));
+        assertEquals("true",apc.getComponent("foo3"));
+    }
+
+    @Test public void testbyTypeFailsEvenIfOneOfSameType() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {
+            "foo=bar"});
+        assertEquals("bar",apc.getComponent("foo"));
+        assertNull(apc.getComponent(String.class));
+    }
+
+    @Test public void testUnsatisfiableIfNoSuitableTyesForInjection() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {"zz=zz"});
+        DefaultContainer pico = new DefaultContainer(apc);
+        pico.as(Characteristics.USE_NAMES).addComponent(NeedsAFew.class);
+        try {
+            Object foo = pico.getComponent(NeedsAFew.class);
+            fail();
+        } catch (AbstractInjector.UnsatisfiableDependenciesException e) {
+            // expetced;
+        }
+    }
+    public static class NeedsAFew {
+        private final String a;
+        private final int b;
+        private final boolean c;
+        public NeedsAFew(String a, int b, boolean c) {
+            this.a = a;
+            this.b = b;
+            this.c = c;
+        }
+    }
+
+    @Test public void testConstructorInjectionComponentCanDependOnConfig() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {"a=a", "b=2", "c=true"});
+        DefaultContainer pico = new DefaultContainer(apc);
+        pico.addConfig("zzz","zzz");
+        pico.as(Characteristics.USE_NAMES).addComponent(NeedsAFew.class);
+        NeedsAFew needsAFew = pico.getComponent(NeedsAFew.class);
+        assertNotNull(needsAFew);
+        assertEquals("a", needsAFew.a);
+        assertEquals(2, needsAFew.b);
+        assertEquals(true, needsAFew.c);
+    }
+
+    public static class NeedsAFew2 {
+        private String a;
+        private int b;
+        private boolean c;
+
+        public void setA(String a) {
+            this.a = a;
+        }
+
+        public void setB(int b) {
+            this.b = b;
+        }
+
+        public void setC(boolean c) {
+            this.c = c;
+        }
+    }
+
+    @Test public void testSetterInjectionComponentCanDependOnConfig() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {"a=a", "b=2", "c=true"});
+        DefaultContainer pico = new DefaultContainer(new SetterInjection(), apc);
+        pico.addConfig("zzz","zzz");
+        pico.as(Characteristics.USE_NAMES).addComponent(NeedsAFew2.class);
+        NeedsAFew2 needsAFew = pico.getComponent(NeedsAFew2.class);
+        assertNotNull(needsAFew);
+        assertEquals("a", needsAFew.a);
+        assertEquals(2, needsAFew.b);
+        assertEquals(true, needsAFew.c);
+    }
+
+    public static class NeedsAFew3 {
+        @Inject
+        private String a;
+        @Inject
+        private int b;
+        @Inject
+        private boolean c;
+    }
+
+    @Test public void testAnnotatedFieldInjectionComponentCanDependOnConfig() {
+        CommandLineArgumentsContainer apc = new CommandLineArgumentsContainer(new String[] {"a=a", "b=2", "c=true"});
+        DefaultContainer pico = new DefaultContainer(new AnnotatedFieldInjection(), apc);
+        pico.addConfig("zzz","zzz");
+        pico.as(Characteristics.USE_NAMES).addComponent(NeedsAFew3.class);
+        NeedsAFew3 needsAFew = pico.getComponent(NeedsAFew3.class);
+        assertNotNull(needsAFew);
+        assertEquals("a", needsAFew.a);
+        assertEquals(2, needsAFew.b);
+        assertEquals(true, needsAFew.c);
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/DelegatingMutableContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/DelegatingMutableContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/DelegatingMutableContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/DelegatingMutableContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ *****************************************************************************/
+
+package org.apache.composer.core.containers;
+
+import java.util.Properties;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.tck.AbstractContainerTest;
+
+
+public class DelegatingMutableContainerTestCase extends AbstractContainerTest {
+
+    protected MutableContainer createPicoContainer(Container parent) {
+        return new MyDelegatingMutableContainer(new DefaultContainer());
+    }
+
+    protected Properties[] getProperties() {
+        return new Properties[] { Characteristics.NO_CACHE, Characteristics.NO_HIDE_IMPL};
+    }
+
+    @SuppressWarnings("serial")
+	private static class MyDelegatingMutableContainer extends AbstractDelegatingMutableContainer {
+        public MyDelegatingMutableContainer(MutableContainer parent) {
+            super(parent);
+        }
+
+        public MutableContainer makeChildContainer() {
+            return new MyDelegatingMutableContainer(this);
+        }
+    }
+
+
+    @Test public void testAcceptImplementsBreadthFirstStrategy() {
+        // don't run this one.
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/EmptyContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/EmptyContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/EmptyContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/EmptyContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by the committers                                           *
+ *****************************************************************************/
+
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.apache.composer.core.NameBinding;
+import org.apache.composer.core.Container;
+
+/**
+ * @author Mauro Talevi
+ */
+public class EmptyContainerTestCase {
+
+    @Test public void testReturnValues() {
+        Container pico = new EmptyContainer();
+        assertNull(pico.getComponentAdapter(null, (NameBinding) null));
+        assertNull(pico.getComponentAdapter(null, (NameBinding) null));
+        assertTrue(pico.getComponentAdapters().isEmpty());
+        assertTrue(pico.getComponentAdapters(null).isEmpty());
+        assertNull(pico.getComponent(null));
+        assertNull(pico.getComponent(null));
+        assertTrue(pico.getComponents().isEmpty());
+        assertTrue(pico.getComponents(null).isEmpty());
+        assertNull(pico.getParent());
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/ImmutableContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/ImmutableContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/ImmutableContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/ImmutableContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by Paul Hammant                                             *
+ *****************************************************************************/
+
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.apache.composer.core.tck.MockFactory.mockeryWithCountingNamingScheme;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.NameBinding;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.ContainerVisitor;
+
+
+/**
+ * @author Paul Hammant
+ * @author J&ouml;rg Schaible
+ */
+@RunWith(JMock.class)
+public class ImmutableContainerTestCase {
+
+	private Mockery mockery = mockeryWithCountingNamingScheme();
+	
+    @Test public void testImmutingOfNullBarfs() {
+        try {
+            new ImmutableContainer(null);
+            fail("Should have barfed");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    @Test public void testVisitingOfImmutableContainerWorks() {
+        final DefaultContainer pico = new DefaultContainer();
+        Object foo = new Object();
+        final ComponentAdapter componentAdapter = pico.addComponent(foo).getComponentAdapter(foo.getClass(), (NameBinding) null);
+
+        final ContainerVisitor fooVisitor = mockery.mock(ContainerVisitor.class);
+        mockery.checking(new Expectations() {{
+            one(fooVisitor).visitContainer(with(same(pico)));
+        	one(fooVisitor).visitComponentAdapter(with(same(componentAdapter)));
+        }});
+        Container ipc = new ImmutableContainer(pico);
+        ipc.accept(fooVisitor);
+    }
+
+    @Test public void testProxyEquals() throws Exception {
+        DefaultContainer pico = new DefaultContainer();
+        Container ipc = new ImmutableContainer(pico);
+        assertEquals(ipc, ipc);
+        assertEquals(ipc, new ImmutableContainer(pico));
+    }
+
+    @Test public void testHashCodeIsSame() throws Exception {
+        DefaultContainer pico = new DefaultContainer();
+        assertEquals(pico.hashCode(), new ImmutableContainer(pico).hashCode());
+    }
+    
+    @Test public void testDoesNotEqualsToNull() {
+        DefaultContainer pico = new DefaultContainer();
+        Container ipc = new ImmutableContainer(pico);
+        assertFalse(ipc.equals(null));
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/ImplementationHidingWithDefaultContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/ImplementationHidingWithDefaultContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/ImplementationHidingWithDefaultContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/ImplementationHidingWithDefaultContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ *****************************************************************************/
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import junit.framework.AssertionFailedError;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.behaviors.Caching;
+import org.apache.composer.core.behaviors.ImplementationHiding;
+import org.apache.composer.core.injectors.ConstructorInjection;
+import org.apache.composer.core.tck.AbstractImplementationHidingContainerTest;
+
+/**
+ *
+ * @author Aslak Helles&oslash;y
+ */
+public class ImplementationHidingWithDefaultContainerTestCase extends AbstractImplementationHidingContainerTest {
+
+    protected MutableContainer createImplementationHidingPicoContainer() {
+        return createPicoContainer(null);
+    }
+
+    protected Properties[] getProperties() {
+        return new Properties[] {Characteristics.NO_CACHE, Characteristics.NO_HIDE_IMPL};
+    }
+
+    protected MutableContainer createPicoContainer(Container parent) {
+        return new DefaultContainer(new Caching().wrap(new ImplementationHiding().wrap(new ConstructorInjection())), parent);
+    }
+    
+    @Test public void testSameInstanceCanBeUsedAsDifferentTypeWhenCaching() {
+        // we're choosing a CAF for DPC, thus Caching (a default) not enabled.
+        try {
+            super.testSameInstanceCanBeUsedAsDifferentTypeWhenCaching();
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().indexOf("expected same:<org.apache.composer.core.testmodel.WashableTouchable@") > -1);
+            assertTrue(e.getMessage().indexOf("was not:<org.apache.composer.core.testmodel.WashableTouchable@") > -1);
+        }
+
+    }
+
+    @Test public void testAcceptImplementsBreadthFirstStrategy() {
+        super.testAcceptImplementsBreadthFirstStrategy();
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/PropertiesContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/PropertiesContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/PropertiesContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/PropertiesContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,46 @@
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Properties;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+
+/**
+ * test that properties container works properly
+ * @author k.pribluda
+ */
+public class PropertiesContainerTestCase {
+	/**
+	 * all properties specified in constructor shall be
+	 * placed into container as strings
+	 *
+	 */
+	@Test public void testThatAllPropertiesAreAdded() {
+		Properties properties = new Properties();
+		
+		properties.put("foo","bar");
+		properties.put("blurge","bang");
+		
+		
+		PropertiesContainer container = new PropertiesContainer(properties);
+		assertEquals("bar",container.getComponent("foo"));
+		assertEquals("bang",container.getComponent("blurge"));
+	}
+	
+	/**
+	 * inquiry shall be delegated to parent container
+	 */
+	@Test public void testThatParentDelegationWorks() {
+		DefaultContainer parent = new DefaultContainer();
+		String stored = new String("glam");
+		parent.addComponent("glam",stored);
+		
+		PropertiesContainer contaienr = new PropertiesContainer(new Properties(),parent);
+		
+		assertSame(stored,contaienr.getComponent("glam"));
+	}
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/containers/SystemPropertiesContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/containers/SystemPropertiesContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/containers/SystemPropertiesContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/containers/SystemPropertiesContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,25 @@
+package org.apache.composer.core.containers;
+
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+/**
+ * test capabilities of system properties providing container. 
+ * @author k.pribluda
+ *
+ */
+public class SystemPropertiesContainerTestCase {
+
+	
+	/**
+	 * all the content of system properties shall be made available
+	 *  through this contaienr. 
+	 */
+	@Test public void testThatAllSystemPropertiesAreCopied() {
+		SystemPropertiesContainer container = new SystemPropertiesContainer();
+		for(Object key: System.getProperties().keySet()) {
+			assertSame(System.getProperties().get(key),container.getComponent(key));
+		}
+	}
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/AbstractComponentMonitorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/AbstractComponentMonitorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/AbstractComponentMonitorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/AbstractComponentMonitorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,154 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.apache.composer.core.tck.MockFactory.mockeryWithCountingNamingScheme;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.Vector;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.ComponentMonitorStrategy;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.injectors.ConstructorInjector;
+import org.apache.composer.core.monitors.AbstractComponentMonitor;
+
+/**
+ * @author Mauro Talevi
+ */
+@RunWith(JMock.class)
+public class AbstractComponentMonitorTestCase {
+
+	private Mockery mockery = mockeryWithCountingNamingScheme();
+	
+    @Test public void testDelegatingMonitorThrowsExpectionWhenConstructionWithNullDelegate(){
+        try {
+            new AbstractComponentMonitor(null);
+            fail("NPE expected");
+        } catch (NullPointerException e) {
+            assertEquals("NPE", "monitor", e.getMessage());
+        }
+    }
+
+    @Test public void testDelegatingMonitorThrowsExpectionWhenChangingToNullMonitor(){
+        AbstractComponentMonitor dcm = new AbstractComponentMonitor();
+        try {
+            dcm.changeMonitor(null);
+            fail("NPE expected");
+        } catch (NullPointerException e) {
+            assertEquals("NPE", "monitor", e.getMessage());
+        }
+    }
+
+    @Test public void testDelegatingMonitorCanChangeMonitorInDelegateThatDoesSupportMonitorStrategy() {
+        ComponentMonitor monitor = mockMonitorWithNoExpectedMethods();
+        AbstractComponentMonitor dcm = new AbstractComponentMonitor(mockMonitorThatSupportsStrategy(monitor));
+        dcm.changeMonitor(monitor);
+        assertEquals(monitor, dcm.currentMonitor());
+        dcm.instantiating(null, null, null);
+    }
+
+    @Test public void testDelegatingMonitorChangesDelegateThatDoesNotSupportMonitorStrategy() {
+        ComponentMonitor delegate = mockMonitorWithNoExpectedMethods();
+        AbstractComponentMonitor dcm = new AbstractComponentMonitor(delegate);
+        ComponentMonitor monitor = mockMonitorWithNoExpectedMethods();
+        assertEquals(delegate, dcm.currentMonitor());
+        dcm.changeMonitor(monitor);
+        assertEquals(monitor, dcm.currentMonitor());
+    }
+
+    @Test public void testDelegatingMonitorReturnsDelegateThatDoesNotSupportMonitorStrategy() {
+        ComponentMonitor delegate = mockMonitorWithNoExpectedMethods();
+        AbstractComponentMonitor dcm = new AbstractComponentMonitor(delegate);
+        assertEquals(delegate, dcm.currentMonitor());
+    }
+
+    private ComponentMonitor mockMonitorWithNoExpectedMethods() {
+        return mockery.mock(ComponentMonitor.class);
+    }
+
+    private ComponentMonitor mockMonitorThatSupportsStrategy(final ComponentMonitor currentMonitor) {
+    	final TestMonitorThatSupportsStrategy monitor = mockery.mock(TestMonitorThatSupportsStrategy.class);
+    	mockery.checking(new Expectations(){{
+            one(monitor).changeMonitor(with(equal(currentMonitor)));
+            one(monitor).currentMonitor();
+            will(returnValue(currentMonitor));
+            one(monitor).instantiating(with(any(Container.class)), with(any(ComponentAdapter.class)), with(any(Constructor.class)));
+    	}});
+        return monitor;
+    }
+
+    @Test public void testMonitoringHappensBeforeAndAfterInstantiation() throws NoSuchMethodException {
+        final Vector ourIntendedInjectee0 = new Vector();
+        final String ourIntendedInjectee1 = "hullo";
+        DefaultContainer parent = new DefaultContainer();
+        final ComponentMonitor monitor = mockery.mock(ComponentMonitor.class);
+        final DefaultContainer child = new DefaultContainer(new AbstractComponentMonitor(monitor), parent);
+        final Constructor needsACoupleOfThings = NeedsACoupleOfThings.class.getConstructors()[0];
+        final Matcher<Long> durationIsGreaterThanOrEqualToZero = new BaseMatcher<Long>() {
+			public boolean matches(Object item) {
+                Long duration = (Long)item;
+                return 0 <= duration;
+			}
+
+			public void describeTo(Description description) {
+				description.appendText("The endTime wasn't after the startTime");
+			}
+        };
+        final Matcher<Object> isANACOTThatWozCreated = new BaseMatcher<Object>() {
+			public boolean matches(Object item) {
+                return item instanceof NeedsACoupleOfThings;
+			}
+
+			public void describeTo(Description description) {
+				description.appendText("Should have been a NeedsACoupleOfThings");
+			}
+        };
+        final Matcher<Object[]> collectionAndStringWereInjected = new BaseMatcher<Object[]>() {
+			public boolean matches(Object item) {
+				 Object[] args = (Object[]) item;
+				 return args.length == 2 && args[0] == ourIntendedInjectee0 && args[1] == ourIntendedInjectee1;
+			}
+			public void describeTo(Description description) {
+				description.appendText("Should have injected our intended vector and string");
+			}
+        };
+        mockery.checking(new Expectations(){{
+        	one(monitor).instantiating(with(same(child)), with(any(ConstructorInjector.class)), with(equal(needsACoupleOfThings)));
+        	will(returnValue(needsACoupleOfThings));
+        	one(monitor).instantiated(with(same(child)), with(any(ConstructorInjector.class)), with(equal(needsACoupleOfThings)), with(isANACOTThatWozCreated), with(collectionAndStringWereInjected), with(durationIsGreaterThanOrEqualToZero));
+        }});
+        parent.addComponent(ourIntendedInjectee0);
+        parent.addComponent(ourIntendedInjectee1);
+        child.addComponent(NeedsACoupleOfThings.class);
+        child.getComponent(NeedsACoupleOfThings.class);
+    }
+
+    public static class NeedsACoupleOfThings {
+        public NeedsACoupleOfThings(Collection collection, String string) {
+        }
+    }
+
+    public static interface TestMonitorThatSupportsStrategy extends ComponentMonitor, ComponentMonitorStrategy {
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/ChildContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/ChildContainerTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/ChildContainerTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/ChildContainerTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.parameters.ComponentParameter;
+import org.apache.composer.core.testmodel.AlternativeTouchable;
+import org.apache.composer.core.testmodel.DependsOnTouchable;
+import org.apache.composer.core.testmodel.SimpleTouchable;
+import org.apache.composer.core.testmodel.Touchable;
+
+/**
+ * @author Paul Hammant
+ * @author Aslak Helles&oslash;y
+ * @author Rafal Krzewski
+ */
+public class ChildContainerTestCase {
+
+    @Test public void testParentContainerWithComponentWithEqualKeyShouldBeShadowedByChild() throws Exception {
+        DefaultContainer parent = new DefaultContainer();
+        DefaultContainer child = new DefaultContainer(parent);
+
+        parent.addComponent("key", AlternativeTouchable.class);
+        child.addComponent("key", SimpleTouchable.class);
+        child.addComponent(DependsOnTouchable.class);
+
+        DependsOnTouchable dot = child.getComponent(DependsOnTouchable.class);
+        assertEquals(SimpleTouchable.class, dot.getTouchable().getClass());
+    }
+
+    @Test public void testParentComponentRegisteredAsClassShouldBePreffered() throws Exception {
+        DefaultContainer parent = new DefaultContainer();
+        DefaultContainer child = new DefaultContainer(parent);
+
+        parent.addComponent(Touchable.class, AlternativeTouchable.class);
+        child.addComponent("key", SimpleTouchable.class);
+        child.addComponent(DependsOnTouchable.class);
+
+        DependsOnTouchable dot = child.getComponent(DependsOnTouchable.class);
+        assertEquals(AlternativeTouchable.class, dot.getTouchable().getClass());
+    }
+
+    @Test public void testResolveFromParentByType() {
+        MutableContainer parent = new DefaultContainer();
+        parent.addComponent(Touchable.class, SimpleTouchable.class);
+
+        MutableContainer child = new DefaultContainer(parent);
+        child.addComponent(DependsOnTouchable.class);
+
+        assertNotNull(child.getComponent(DependsOnTouchable.class));
+    }
+
+    @Test public void testResolveFromParentByKey() {
+        MutableContainer parent = new DefaultContainer();
+        parent.addComponent(Touchable.class, SimpleTouchable.class);
+
+        MutableContainer child = new DefaultContainer(parent);
+        child.addComponent(DependsOnTouchable.class, DependsOnTouchable.class,
+                           new ComponentParameter(Touchable.class));
+
+        assertNotNull(child.getComponent(DependsOnTouchable.class));
+    }
+
+    @Test public void testResolveFromGrandParentByType() {
+        MutableContainer grandParent = new DefaultContainer();
+        grandParent.addComponent(Touchable.class, SimpleTouchable.class);
+
+        MutableContainer parent = new DefaultContainer(grandParent);
+
+        MutableContainer child = new DefaultContainer(parent);
+        child.addComponent(DependsOnTouchable.class);
+
+        assertNotNull(child.getComponent(DependsOnTouchable.class));
+    }
+
+    @Test public void testResolveFromGrandParentByKey() {
+        MutableContainer grandParent = new DefaultContainer();
+        grandParent.addComponent(Touchable.class, SimpleTouchable.class);
+
+        MutableContainer parent = new DefaultContainer(grandParent);
+
+        MutableContainer child = new DefaultContainer(parent);
+        child.addComponent(DependsOnTouchable.class, DependsOnTouchable.class,
+                           new ComponentParameter(Touchable.class));
+
+        assertNotNull(child.getComponent(DependsOnTouchable.class));
+    }
+}



Mime
View raw message