You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by kn...@apache.org on 2006/07/31 16:21:29 UTC

svn commit: r427127 [2/2] - in /hivemind/trunk: ./ framework/src/descriptor/META-INF/ framework/src/documentation/content/xdocs/ framework/src/java/org/apache/hivemind/ framework/src/java/org/apache/hivemind/impl/ framework/src/java/org/apache/hivemind...

Added: hivemind/trunk/framework/src/test/hivemind/test/services/TestAssemblyInstruction.java
URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/hivemind/test/services/TestAssemblyInstruction.java?rev=427127&view=auto
==============================================================================
--- hivemind/trunk/framework/src/test/hivemind/test/services/TestAssemblyInstruction.java (added)
+++ hivemind/trunk/framework/src/test/hivemind/test/services/TestAssemblyInstruction.java Mon Jul 31 07:21:27 2006
@@ -0,0 +1,379 @@
+// Copyright 2006 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 hivemind.test.services;
+
+import hivemind.test.services.impl.StringHolderImpl;
+
+import org.apache.commons.logging.Log;
+import org.apache.hivemind.AssemblyParameters;
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.ErrorLog;
+import org.apache.hivemind.Messages;
+import org.apache.hivemind.Registry;
+import org.apache.hivemind.internal.Module;
+import org.apache.hivemind.service.impl.AssemblyInstructionImpl;
+import org.apache.hivemind.service.impl.BuilderClassResolverFacet;
+import org.apache.hivemind.service.impl.BuilderErrorHandlerFacet;
+import org.apache.hivemind.service.impl.BuilderErrorLogFacet;
+import org.apache.hivemind.service.impl.BuilderFacet;
+import org.apache.hivemind.service.impl.BuilderLogFacet;
+import org.apache.hivemind.service.impl.BuilderMessagesFacet;
+import org.apache.hivemind.service.impl.BuilderServiceIdFacet;
+import org.apache.hivemind.test.HiveMindTestCase;
+import org.easymock.MockControl;
+
+/**
+ * Tests for the dependency injection logic of {@link AssemblyInstructionImpl} and various
+ * implementations of {@link org.apache.hivemind.service.impl.BuilderFacet}.
+ * 
+ * @author Knut Wannheden
+ */
+public class TestAssemblyInstruction extends HiveMindTestCase
+{
+    public void testPropertyInjection() throws Exception
+    {
+        Registry r = buildFrameworkRegistry("AssemblyInstructions.xml");
+
+        SimpleService s = (SimpleService) r.getService(
+                "hivemind.test.services.SimpleAssembly",
+                SimpleService.class);
+
+        assertEquals(99, s.add(1, 1));
+    }
+
+    public void testEventListener() throws Exception
+    {
+        Registry r = buildFrameworkRegistry("AssemblyInstructions.xml");
+
+        ZapEventProducer p = (ZapEventProducer) r.getService(
+                "hivemind.test.services.ZapEventProducer",
+                ZapEventProducer.class);
+
+        ZapEventConsumer c = (ZapEventConsumer) r.getService(
+                "hivemind.test.services.ZapEventConsumerAssembly",
+                ZapEventConsumer.class);
+
+        assertEquals(false, c.getDidZapWiggle());
+
+        p.fireZapDidWiggle(null);
+
+        assertEquals(true, c.getDidZapWiggle());
+    }
+
+    public void testBuilderErrorHandlerFacet()
+    {
+        AssemblyParameters p = newParameters();
+        Module m = newModule();
+        ErrorHandler eh = newErrorHandler();
+
+        trainGetInvokingModule(p, m);
+        trainGetErrorHandler(m, eh);
+
+        replayControls();
+
+        BuilderFacet f = new BuilderErrorHandlerFacet();
+
+        Object actual = f.getFacetValue(p, null);
+
+        assertSame(eh, actual);
+
+        verifyControls();
+    }
+
+    public void testBuilderClassResolverFacet()
+    {
+        AssemblyParameters p = newParameters();
+        Module m = newModule();
+        ClassResolver cr = getClassResolver();
+
+        trainGetInvokingModule(p, m);
+        trainGetClassResolver(m, cr);
+
+        replayControls();
+
+        BuilderClassResolverFacet fc = new BuilderClassResolverFacet();
+
+        Object result = fc.getFacetValue(p, null);
+
+        assertSame(cr, result);
+
+        verifyControls();
+    }
+
+    protected AssemblyParameters newParameters()
+    {
+        final MockControl control = MockControl.createNiceControl(AssemblyParameters.class);
+        addControl(control);
+        return (AssemblyParameters) control.getMock();
+    }
+
+    protected Module newModule()
+    {
+        final MockControl control = MockControl.createNiceControl(Module.class);
+        addControl(control);
+        return (Module) control.getMock();
+    }
+
+    protected ErrorHandler newErrorHandler()
+    {
+        return (ErrorHandler) newMock(ErrorHandler.class);
+    }
+
+    protected Log newLog()
+    {
+        return (Log) newMock(Log.class);
+    }
+
+    protected Messages newMessages()
+    {
+        return (Messages) newMock(Messages.class);
+    }
+
+    protected ErrorLog newErrorLog()
+    {
+        return (ErrorLog) newMock(ErrorLog.class);
+    }
+
+    public void testAutowire()
+    {
+        AssemblyParameters fp = newParameters();
+        Module module = newModule();
+        ErrorHandler eh = newErrorHandler();
+        Log log = newLog();
+        Messages messages = newMessages();
+        ErrorLog errorLog = newErrorLog();
+
+        AutowireTarget t = (AutowireTarget) newMock(AutowireTarget.class);
+
+        trainGetInvokingModule(fp, module);
+
+        trainGetLog(fp, log);
+        t.setLog(log);
+        trainDebug(fp, log, "Autowired property log to " + log);
+
+        trainGetClassResolver(module, getClassResolver());
+        t.setClassResolver(getClassResolver());
+        trainDebug(fp, log, "Autowired property classResolver to " + getClassResolver());
+
+        trainGetMessages(module, messages);
+        t.setMessages(messages);
+        trainDebug(fp, log, "Autowired property messages to " + messages);
+
+        trainGetErrorHandler(module, eh);
+        t.setErrorHandler(eh);
+        trainDebug(fp, log, "Autowired property errorHandler to " + eh);
+
+        trainGetServiceId(fp);
+        t.setServiceId("foo.bar.Baz");
+        trainDebug(fp, log, "Autowired property serviceId to foo.bar.Baz");
+
+        trainGetErrorLog(fp, errorLog);
+        t.setErrorLog(errorLog);
+        trainDebug(fp, log, "Autowired property errorLog to " + errorLog);
+
+        replayControls();
+
+        AssemblyInstructionImpl p = new AssemblyInstructionImpl();
+
+        p.addProperty(new BuilderLogFacet());
+        p.addProperty(new BuilderClassResolverFacet());
+        p.addProperty(new BuilderMessagesFacet());
+        p.addProperty(new BuilderErrorHandlerFacet());
+        p.addProperty(new BuilderServiceIdFacet());
+        p.addProperty(new BuilderErrorLogFacet());
+
+        p.assemble(t, fp);
+
+        verifyControls();
+    }
+
+    private void trainGetErrorLog(AssemblyParameters fp, ErrorLog errorLog)
+    {
+        fp.getErrorLog();
+        setReturnValue(fp, errorLog);
+    }
+
+    private void trainGetServiceId(AssemblyParameters fp)
+    {
+        fp.getServiceId();
+        setReturnValue(fp, "foo.bar.Baz");
+    }
+
+    private void trainGetErrorHandler(Module module, ErrorHandler eh)
+    {
+        module.getErrorHandler();
+        setReturnValue(module, eh);
+    }
+
+    private void trainGetMessages(Module module, Messages messages)
+    {
+        module.getMessages();
+        setReturnValue(module, messages);
+    }
+
+    private void trainGetClassResolver(Module module, ClassResolver resolver)
+    {
+        module.getClassResolver();
+        setReturnValue(module, resolver);
+    }
+
+    private void trainGetInvokingModule(AssemblyParameters fp, Module module)
+    {
+        fp.getInvokingModule();
+        getControl(fp).setDefaultReturnValue(module);
+    }
+
+    protected void trainGetServiceId(AssemblyParameters fp, String serviceId)
+    {
+        fp.getServiceId();
+        getControl(fp).setDefaultReturnValue(serviceId);
+    }
+
+    protected void trainGetLog(AssemblyParameters fp, Log log)
+    {
+        fp.getLog();
+        getControl(fp).setDefaultReturnValue(log);
+    }
+
+    private void trainDebug(AssemblyParameters fp, Log log, String string)
+    {
+        fp.getLog();
+        setReturnValue(fp, log);
+
+        log.isDebugEnabled();
+        setReturnValue(log, true);
+
+        log.debug(string);
+    }
+
+    /**
+     * Test that AssemblyInstructionImpl will invoke the "initializeService" method by default.
+     */
+    public void testAutowireInitializer()
+    {
+        AssemblyParameters fp = newParameters();
+        Module module = newModule();
+
+        InitializeFixture f = (InitializeFixture) newMock(InitializeFixture.class);
+
+        trainGetInvokingModule(fp, module);
+
+        f.initializeService();
+
+        replayControls();
+
+        AssemblyInstructionImpl p = new AssemblyInstructionImpl();
+
+        p.assemble(f, fp);
+
+        verifyControls();
+    }
+
+    /**
+     * Test that BuilderFactory will invoke the named initializer.
+     */
+    public void testInitializer()
+    {
+        AssemblyParameters fp = newParameters();
+        Module module = newModule();
+
+        InitializeFixture f = (InitializeFixture) newMock(InitializeFixture.class);
+
+        trainGetInvokingModule(fp, module);
+
+        f.initializeCustom();
+
+        replayControls();
+
+        AssemblyInstructionImpl p = new AssemblyInstructionImpl();
+        p.setInitializeMethod("initializeCustom");
+
+        p.assemble(f, fp);
+
+        verifyControls();
+    }
+
+    public void testAutowireServices()
+    {
+        AssemblyParameters fp = newParameters();
+        Module module = newModule();
+        Log log = newLog();
+
+        ServiceAutowireTarget f = (ServiceAutowireTarget) newMock(ServiceAutowireTarget.class);
+
+        trainGetInvokingModule(fp, module);
+        trainGetLog(fp, log);
+
+        StringHolder h = new StringHolderImpl();
+
+        trainContainsService(module, String.class, false);
+        trainContainsService(module, StringHolder.class, true);
+        trainGetService(module, StringHolder.class, h);
+        f.setStringHolder(h);
+        trainIsDebugEnabled(log);
+
+        replayControls();
+
+        AssemblyInstructionImpl p = new AssemblyInstructionImpl();
+        p.setAutowireServices(true);
+
+        p.assemble(f, fp);
+
+        verifyControls();
+    }
+
+    private void trainIsDebugEnabled(Log log)
+    {
+        log.isDebugEnabled();
+        setReturnValue(log, false);
+    }
+
+    private void trainGetService(Module module, Class serviceInterface, Object service)
+    {
+        module.getService(serviceInterface);
+        setReturnValue(module, service);
+    }
+
+    private void trainContainsService(Module module, Class serviceInterface, boolean containsService)
+    {
+        module.containsService(serviceInterface);
+        setReturnValue(module, containsService);
+    }
+
+    public void testAutowireServicesFailure()
+    {
+        AssemblyParameters fp = newParameters();
+        Module module = newModule();
+        Log log = newLog();
+
+        ServiceAutowireTarget f = (ServiceAutowireTarget) newMock(ServiceAutowireTarget.class);
+
+        trainGetInvokingModule(fp, module);
+        trainGetLog(fp, log);
+
+        trainContainsService(module, String.class, false);
+        trainContainsService(module, StringHolder.class, false);
+
+        replayControls();
+
+        AssemblyInstructionImpl p = new AssemblyInstructionImpl();
+        p.setAutowireServices(true);
+
+        p.assemble(f, fp);
+
+        verifyControls();
+    }
+}

Modified: hivemind/trunk/framework/src/test/hivemind/test/services/TestBuilderFactory.java
URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/hivemind/test/services/TestBuilderFactory.java?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/framework/src/test/hivemind/test/services/TestBuilderFactory.java (original)
+++ hivemind/trunk/framework/src/test/hivemind/test/services/TestBuilderFactory.java Mon Jul 31 07:21:27 2006
@@ -26,20 +26,13 @@
 import org.apache.hivemind.ServiceImplementationFactoryParameters;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.service.impl.BuilderClassResolverFacet;
-import org.apache.hivemind.service.impl.BuilderErrorHandlerFacet;
-import org.apache.hivemind.service.impl.BuilderErrorLogFacet;
-import org.apache.hivemind.service.impl.BuilderFacet;
 import org.apache.hivemind.service.impl.BuilderFactoryLogic;
-import org.apache.hivemind.service.impl.BuilderLogFacet;
-import org.apache.hivemind.service.impl.BuilderMessagesFacet;
 import org.apache.hivemind.service.impl.BuilderParameter;
-import org.apache.hivemind.service.impl.BuilderServiceIdFacet;
 import org.apache.hivemind.test.HiveMindTestCase;
 import org.easymock.MockControl;
 
 /**
- * Tests for the standard {@link org.apache.hivemind.service.impl.BuilderFactory} service and
- * various implementations of {@link org.apache.hivemind.service.impl.BuilderFacet}.
+ * Tests for the standard {@link org.apache.hivemind.service.impl.BuilderFactory} service.
  * 
  * @author Howard Lewis Ship
  */
@@ -76,34 +69,6 @@
                 + "hivemind\\.test\\.services\\.impl\\.MockRunnable\\):");
     }
 
-    public void testBuilderErrorHandlerFacet()
-    {
-        MockControl c = newControl(Module.class);
-        Module m = (Module) c.getMock();
-
-        ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
-
-        MockControl pc = newControl(ServiceImplementationFactoryParameters.class);
-        ServiceImplementationFactoryParameters p = (ServiceImplementationFactoryParameters) pc
-                .getMock();
-
-        p.getInvokingModule();
-        pc.setReturnValue(m);
-
-        m.getErrorHandler();
-        c.setReturnValue(eh);
-
-        replayControls();
-
-        BuilderFacet f = new BuilderErrorHandlerFacet();
-
-        Object actual = f.getFacetValue(p, null);
-
-        assertSame(eh, actual);
-
-        verifyControls();
-    }
-
     public void testSetErrorHandler() throws Exception
     {
         Registry r = buildFrameworkRegistry("SetErrorHandler.xml");
@@ -126,34 +91,6 @@
         assertNotNull(h.getErrorHandler());
     }
 
-    public void testBuilderClassResolverFacet()
-    {
-        ClassResolver cr = (ClassResolver) newMock(ClassResolver.class);
-
-        MockControl pc = newControl(ServiceImplementationFactoryParameters.class);
-        ServiceImplementationFactoryParameters p = (ServiceImplementationFactoryParameters) pc
-                .getMock();
-
-        MockControl control = newControl(Module.class);
-        Module module = (Module) control.getMock();
-
-        p.getInvokingModule();
-        pc.setReturnValue(module);
-
-        module.getClassResolver();
-        control.setReturnValue(cr);
-
-        replayControls();
-
-        BuilderClassResolverFacet fc = new BuilderClassResolverFacet();
-
-        Object result = fc.getFacetValue(p, null);
-
-        assertSame(cr, result);
-
-        verifyControls();
-    }
-
     public void testSetClassResolver() throws Exception
     {
         Registry r = buildFrameworkRegistry("SetClassResolver.xml");
@@ -178,12 +115,17 @@
 
     protected ServiceImplementationFactoryParameters newParameters()
     {
-        return (ServiceImplementationFactoryParameters) newMock(ServiceImplementationFactoryParameters.class);
+        final MockControl control = MockControl
+                .createNiceControl(ServiceImplementationFactoryParameters.class);
+        addControl(control);
+        return (ServiceImplementationFactoryParameters) control.getMock();
     }
 
     protected Module newModule()
     {
-        return (Module) newMock(Module.class);
+        final MockControl control = MockControl.createNiceControl(Module.class);
+        addControl(control);
+        return (Module) control.getMock();
     }
 
     protected ErrorHandler newErrorHandler()
@@ -206,105 +148,6 @@
         return (ErrorLog) newMock(ErrorLog.class);
     }
 
-    public void testAutowire()
-    {
-        ServiceImplementationFactoryParameters fp = newParameters();
-        Module module = newModule();
-        ErrorHandler eh = newErrorHandler();
-        Log log = newLog();
-        Messages messages = newMessages();
-        ErrorLog errorLog = newErrorLog();
-
-        // Normally I try and get all the invocations into chronological
-        // order ... but with this refactoring, that's painful; these
-        // are in an order that appeases junit.
-
-        trainGetLog(fp, log);
-
-        trainGetServiceId(fp, "foo.bar.Baz");
-
-        trainGetInvokingModule(fp, module);
-
-        trainResolveType(module, "hivemind.test.services.AutowireTarget", AutowireTarget.class);
-
-        trainGetLog(fp, log);
-
-        trainDebug(fp, log, "Autowired property log to " + log);
-
-        trainGetInvokingModule(fp, module);
-
-        trainGetClassResolver(module, getClassResolver());
-
-        trainDebug(fp, log, "Autowired property classResolver to " + getClassResolver());
-
-        trainGetInvokingModule(fp, module);
-
-        trainGetMessages(module, messages);
-
-        trainDebug(fp, log, "Autowired property messages to " + messages);
-
-        trainGetInvokingModule(fp, module);
-
-        trainGetErrorHandler(module, eh);
-
-        trainDebug(fp, log, "Autowired property errorHandler to " + eh);
-
-        trainGetServiceId(fp);
-
-        trainDebug(fp, log, "Autowired property serviceId to foo.bar.Baz");
-
-        trainGetErrorLog(fp, errorLog);
-
-        trainDebug(fp, log, "Autowired property errorLog to " + errorLog);
-
-        replayControls();
-
-        BuilderParameter p = new BuilderParameter();
-
-        p.setClassName(AutowireTarget.class.getName());
-        p.addProperty(new BuilderLogFacet());
-        p.addProperty(new BuilderClassResolverFacet());
-        p.addProperty(new BuilderMessagesFacet());
-        p.addProperty(new BuilderErrorHandlerFacet());
-        p.addProperty(new BuilderServiceIdFacet());
-        p.addProperty(new BuilderErrorLogFacet());
-
-        AutowireTarget t = (AutowireTarget) execute(fp, p);
-
-        assertSame(eh, t.getErrorHandler());
-        assertSame(getClassResolver(), t.getClassResolver());
-        assertSame(messages, t.getMessages());
-        assertSame(log, t.getLog());
-        assertEquals("foo.bar.Baz", t.getServiceId());
-        assertSame(errorLog, t.getErrorLog());
-
-        verifyControls();
-    }
-
-    private void trainGetErrorLog(ServiceImplementationFactoryParameters fp, ErrorLog errorLog)
-    {
-        fp.getErrorLog();
-        setReturnValue(fp, errorLog);
-    }
-
-    private void trainGetServiceId(ServiceImplementationFactoryParameters fp)
-    {
-        fp.getServiceId();
-        setReturnValue(fp, "foo.bar.Baz");
-    }
-
-    private void trainGetErrorHandler(Module module, ErrorHandler eh)
-    {
-        module.getErrorHandler();
-        setReturnValue(module, eh);
-    }
-
-    private void trainGetMessages(Module module, Messages messages)
-    {
-        module.getMessages();
-        setReturnValue(module, messages);
-    }
-
     private void trainGetClassResolver(Module module, ClassResolver resolver)
     {
         module.getClassResolver();
@@ -317,137 +160,16 @@
         setReturnValue(module, type);
     }
 
-    private void trainGetInvokingModule(ServiceImplementationFactoryParameters fp, Module module)
-    {
-        fp.getInvokingModule();
-        setReturnValue(fp, module);
-    }
-
     protected void trainGetServiceId(ServiceImplementationFactoryParameters fp, String serviceId)
     {
         fp.getServiceId();
-        setReturnValue(fp, serviceId);
+        getControl(fp).setDefaultReturnValue(serviceId);
     }
 
     protected void trainGetLog(ServiceImplementationFactoryParameters fp, Log log)
     {
         fp.getLog();
-        setReturnValue(fp, log);
-    }
-
-    private void trainDebug(ServiceImplementationFactoryParameters fp, Log log, String string)
-    {
-        fp.getLog();
-        setReturnValue(fp, log);
-
-        log.isDebugEnabled();
-        setReturnValue(log, true);
-
-        log.debug(string);
-    }
-
-    /**
-     * Test that BuilderFactory will invoke the "initializeService" method by default.
-     */
-    public void testAutowireInitializer()
-    {
-        Module module = newModule();
-        ServiceImplementationFactoryParameters fp = newParameters();
-        Log log = newLog();
-
-        trainGetLog(fp, log);
-        trainGetServiceId(fp, "foo");
-        trainGetInvokingModule(fp, module);
-        trainResolveType(
-                module,
-                "hivemind.test.services.InitializeFixture",
-                InitializeFixture.class);
-
-        replayControls();
-
-        BuilderParameter p = new BuilderParameter();
-
-        p.setClassName(InitializeFixture.class.getName());
-
-        InitializeFixture f = (InitializeFixture) execute(fp, p);
-
-        // Check which method was actually invoked (if any)
-
-        assertEquals("initializeService", f.getMethod());
-
-        verifyControls();
-    }
-
-    /**
-     * Test that BuilderFactory will invoke the named initializer.
-     */
-    public void testInitializer()
-    {
-        ServiceImplementationFactoryParameters fp = newParameters();
-        Module module = newModule();
-        Log log = newLog();
-
-        trainGetLog(fp, log);
-        trainGetServiceId(fp, "foo");
-        trainGetInvokingModule(fp, module);
-        trainResolveType(
-                module,
-                "hivemind.test.services.InitializeFixture",
-                InitializeFixture.class);
-
-        replayControls();
-
-        BuilderParameter p = new BuilderParameter();
-
-        p.setClassName(InitializeFixture.class.getName());
-        p.setInitializeMethod("initializeCustom");
-
-        InitializeFixture f = (InitializeFixture) execute(fp, p);
-
-        assertEquals("initializeCustom", f.getMethod());
-
-        verifyControls();
-    }
-
-    public void testAutowireServices()
-    {
-        ServiceImplementationFactoryParameters fp = newParameters();
-        Module module = newModule();
-        Log log = newLog();
-
-        trainGetLog(fp, log);
-        trainGetServiceId(fp, "foo");
-        trainGetInvokingModule(fp, module);
-        trainResolveType(
-                module,
-                "hivemind.test.services.ServiceAutowireTarget",
-                ServiceAutowireTarget.class);
-
-        StringHolder h = new StringHolderImpl();
-
-        trainContainsService(module, String.class, false);
-        trainContainsService(module, StringHolder.class, true);
-        trainGetService(module, StringHolder.class, h);
-        trainIsDebugEnabled(log);
-
-        replayControls();
-
-        BuilderParameter parameter = new BuilderParameter();
-
-        parameter.setClassName(ServiceAutowireTarget.class.getName());
-        parameter.setAutowireServices(true);
-
-        ServiceAutowireTarget service = (ServiceAutowireTarget) execute(fp, parameter);
-
-        assertSame(h, service.getStringHolder());
-
-        verifyControls();
-    }
-
-    private void trainIsDebugEnabled(Log log)
-    {
-        log.isDebugEnabled();
-        setReturnValue(log, false);
+        getControl(fp).setDefaultReturnValue(log);
     }
 
     private void trainGetService(Module module, Class serviceInterface, Object service)
@@ -460,37 +182,6 @@
     {
         module.containsService(serviceInterface);
         setReturnValue(module, containsService);
-    }
-
-    public void testAutowireServicesFailure()
-    {
-        ServiceImplementationFactoryParameters fp = newParameters();
-        Module module = newModule();
-        Log log = newLog();
-
-        trainGetLog(fp, log);
-        trainGetServiceId(fp, "foo.bar");
-        trainGetInvokingModule(fp, module);
-        trainResolveType(
-                module,
-                "hivemind.test.services.ServiceAutowireTarget",
-                ServiceAutowireTarget.class);
-
-        trainContainsService(module, String.class, false);
-        trainContainsService(module, StringHolder.class, false);
-
-        replayControls();
-
-        BuilderParameter parameter = new BuilderParameter();
-
-        parameter.setClassName(ServiceAutowireTarget.class.getName());
-        parameter.setAutowireServices(true);
-
-        ServiceAutowireTarget service = (ServiceAutowireTarget) execute(fp, parameter);
-
-        assertNull(service.getStringHolder());
-
-        verifyControls();
     }
 
     public void testAutowireConstructor() throws Exception

Modified: hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java
URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java (original)
+++ hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestBuilderFactory.java Mon Jul 31 07:21:27 2006
@@ -45,7 +45,9 @@
     {
         Location l = newLocation();
 
-        MockControl fpc = newControl(ServiceImplementationFactoryParameters.class);
+        MockControl fpc = MockControl
+                .createNiceControl(ServiceImplementationFactoryParameters.class);
+        addControl(fpc);
         ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc
                 .getMock();
 
@@ -57,20 +59,20 @@
         MockControl errorLogc = newControl(ErrorLog.class);
         ErrorLog errorLog = (ErrorLog) errorLogc.getMock();
 
-        fp.getLog();
-        fpc.setReturnValue(log);
-
         fp.getServiceId();
-        fpc.setReturnValue("foo.Bar");
+        fpc.setDefaultReturnValue("foo.Bar");
 
         fp.getInvokingModule();
-        fpc.setReturnValue(module);
+        fpc.setDefaultReturnValue(module);
 
         module.resolveType("org.apache.hivemind.service.impl.InitializerErrorRunnable");
         mc.setReturnValue(InitializerErrorRunnable.class);
 
+        fp.getLog();
+        fpc.setDefaultReturnValue(log);
+
         fp.getErrorLog();
-        fpc.setReturnValue(errorLog);
+        fpc.setDefaultReturnValue(errorLog);
 
         Throwable cause = new ApplicationRuntimeException("Failure in initializeService().");
 
@@ -96,12 +98,12 @@
 
         verifyControls();
     }
-    
+
     public void testListPropertyAutowire() throws Exception
     {
-        final Registry reg = buildFrameworkRegistry( "ListProperty.xml" );
-        ListPropertyBean bean = ( ListPropertyBean )reg.getService( ListPropertyBean.class );
-        assertNull( bean.getList() );
-        
+        final Registry reg = buildFrameworkRegistry("ListProperty.xml");
+        ListPropertyBean bean = (ListPropertyBean) reg.getService(ListPropertyBean.class);
+        assertNull(bean.getList());
+
     }
 }

Modified: hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java
URL: http://svn.apache.org/viewvc/hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java (original)
+++ hivemind/trunk/framework/src/test/org/apache/hivemind/service/impl/TestObjectTranslator.java Mon Jul 31 07:21:27 2006
@@ -18,6 +18,7 @@
 
 import org.apache.hivemind.ErrorLog;
 import org.apache.hivemind.internal.Module;
+import org.apache.hivemind.schema.rules.SmartTranslator;
 import org.apache.hivemind.service.ObjectProvider;
 import org.apache.hivemind.test.HiveMindTestCase;
 import org.easymock.MockControl;
@@ -30,24 +31,22 @@
 public class TestObjectTranslator extends HiveMindTestCase
 {
 
-    public void testBadLocator()
+    public void testWithoutPrefix()
     {
         ObjectTranslator ot = new ObjectTranslator();
 
         Module module = (Module) newMock(Module.class);
 
-        ErrorLog el = (ErrorLog) newMock(ErrorLog.class);
-
-        ot.setErrorLog(el);
         ot.setContributions(Collections.EMPTY_MAP);
 
-        el.error("Object provider selector 'badprefix' is not properly formatted.", null, null);
+        module.getTranslator("smart");
+        getControl(module).setReturnValue(new SmartTranslator());
 
         replayControls();
 
-        Object result = ot.translate(module, Object.class, "badprefix", null);
+        Object result = ot.translate(module, Object.class, "99", null);
 
-        assertNull(result);
+        assertEquals("99", result);
 
         verifyControls();
     }

Added: hivemind/trunk/src/documentation/content/xdocs/assembly.xml
URL: http://svn.apache.org/viewvc/hivemind/trunk/src/documentation/content/xdocs/assembly.xml?rev=427127&view=auto
==============================================================================
--- hivemind/trunk/src/documentation/content/xdocs/assembly.xml (added)
+++ hivemind/trunk/src/documentation/content/xdocs/assembly.xml Mon Jul 31 07:21:27 2006
@@ -0,0 +1,218 @@
+<?xml version="1.0"?>
+<!-- 
+   Copyright 2006 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.
+-->
+
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.3//EN"
+	"http://xml.apache.org/forrest/dtd/document-v13.dtd" [
+	<!ENTITY projectroot '../'>
+	<!ENTITY % common-links SYSTEM "../links.ent">
+	%common-links;
+	]>
+<document>
+	<header>
+		<title>Assembly Instructions</title>
+	</header>
+	<body>
+		<p>Assembly instructions are used to initialize the core service implementation object 
+			created by a service implementation factory. This initialization usually involves injecting 
+			dependencies (services, configurations, or other objects), registering the service as 
+			event listener, and calling an initialization method.</p>
+		<p>An assembly instruction is specified using an &_assembly; element right after the 
+			factory parameter elements inside the &_invoke-factory; element:</p>
+		<source><![CDATA[
+<assembly autowire-services="..." initialize-method="...">
+    
+    <set property="..." value="..."/>
+    <listener service-id="..." event-type-name="..."/>
+
+</assembly>]]> </source>
+		<p>The attributes of the <code>&_assembly;</code> element are used to control 
+			autowiring and specify the initialization method. Nested elements supply dependencies to 
+			inject (<code>&lt;set&gt;</code> elements) and other services with which should be 
+			registered as an event listener (<code>&lt;listener&gt;</code> elements).</p>
+
+      <note>
+      	When the &hivemind.BuilderFactory; is used there is actually no need for assembly 
+      	instructions, as the BuilderFactory can perform all of that itself. Assembly instructions have 
+      	the advantage of being applicable to all service implementation factories (including the 
+      	BuilderFactory) and thus don't require any support in the factory.
+      </note>
+
+		<section>
+			<title>assembly</title>
+			<table>
+				<tr>
+					<th>Attribute</th>
+					<th>Required ?</th>
+					<th>Description</th>
+				</tr>
+		        <tr>
+					<td>autowire-services</td>
+					<td>no</td>
+					<td>If true (the default), then HiveMind will attempt to
+					  automatically wire services and some common properties to properties of the 
+					  core service implementation with setter methods (see notes below).
+					</td>
+		        </tr>
+				<tr>
+					<td>initialize-method</td>
+					<td>no</td>
+					<td>The name of a method (public, no parameters) to invoke after the
+						service is constructed, to allow it to perform any final
+						initialization before being put into use. Defaults to 
+						<code>initializeService</code>.</td>
+				</tr>
+			</table>
+			<p>The remaining elements are enclosed by the &_assembly; element,
+				and are used to configure properties	of the core service implementation.</p>
+		</section>
+    
+    <section>
+      <title>Autowiring</title>
+      
+      <p>
+        With <code>autowire-services</code> set to true the assembly instruction will cause some 
+        dependencies to be injected automatically through setter methods. It will not only attempt to inject 
+        services but also certain common properties. The assembly instruction works this out by looking for 
+        setter methods with standard names <em>and</em> types:
+      </p>
+      
+      <table>
+        <tr>
+          <th>Property name</th>
+          <th>Property / parameter type</th>
+        </tr>
+        <tr>
+          <td>classResolver</td>
+          <td>&api.ClassResolver;</td>
+        </tr>
+        <tr>
+          <td>errorHandler</td>
+          <td>&api.ErrorHandler;</td>
+        </tr>
+        <tr>
+          <td>errorLog</td>
+          <td>&api.ErrorLog;</td>
+        </tr>
+        <tr>
+          <td>log</td>
+          <td>
+            <code>org.apache.commons.logging.Log</code>
+          </td>
+        </tr>
+        <tr>
+          <td>messages</td>
+          <td>&api.Messages;</td>
+          <td/>
+        </tr>
+        <tr>
+          <td>serviceId</td>
+          <td>String</td>
+        </tr>
+      </table>
+      
+      <p>
+        As noted the assembly instruction will also cause services to be injected into the core service implementation. 
+        Through every writable property whose type is an interface (with the exception 
+        of the common parameters / properties listed above) and hasn't been set otherwise the assembly instruction will 
+        attempt to inject a service.  This attempt may fail if there is <em>no</em> visible service or <em>more than 
+        one</em> visible service implementing the given interface.  (Visibility is checked with respect to the module 
+        declaring the constructed service's implementation.)
+      </p>
+      
+      <p>
+        If the service injection fails (due to one of the reasons given above) the assembly instruction will 
+        log an error immedeately upon failed injection.
+      </p>
+      
+      <p>
+        Autowiring may be  complicated by the fact that one module may define a service point that will tangentially affect the
+        construction of a service in another module (simply by implementing the same service interface).  In this situation, 
+        service autowiring can be turned off, by setting the <code>autowire-services</code> attribute to false.
+      </p>
+      
+      <p>
+       Once all properties have been set (possibly by autowiring), an initializer method will be invoked.  If the 
+       <code>initialize-method</code> attribute is <em>not</em> specified, and the service implementation includes a 
+       public method <code>initializeService()</code> (no parameters, returns void), then <code>initializeService()</code> 
+       will be invoked as the initializer.
+      </p>
+      
+    </section>
+    
+	<section>
+		<title>Service Property Configuring Elements</title>
+		<section>
+			<title>listener</title>
+			<table>
+				<tr>
+					<th>Attribute</th>
+					<th>Description</th>
+				</tr>
+				<tr>
+					<td>service-id</td>
+					<td>The service which produces events. The service must provide, in
+						its service interface, the necessary add and remove listener
+						methods.</td>
+				</tr>
+				<tr>
+					<td>name</td>
+					<td>The name of an event set to be registered. If not specified, all
+						applicable event sets are used.</td>
+				</tr>
+			</table>
+			<p>If the name attribute is not specified, then HiveMind will
+				register for all applicable event sets. For each event set provided by
+				the specified service, HiveMind will check to see if the core service
+				implementation object implements the corresponding listener
+				interface ... if so, the core service implementation is added as a
+				listener. When the name attribute is specified, the core service 
+				implementation object is registered as a listener of just that single type.</p>
+			<p>Event notifications go directly to the core service implementation;
+				they don't go through any proxies or interceptors for the service. The
+				service <em>instance</em> must implement the listener interface, the
+				constructed service's service interface <em>does not</em> have to
+				extend the listener interface. In other words, event notifications are
+				"behind the scenes", not part of the public API of the service.</p>
+			<p>It is perfectly acceptible to include multiple &lt;listener&gt;
+				elements for a number of different event producing services.</p>
+			<p>It is not enough for the event producer service to have an add
+				listener method (i.e., <code>
+				addPropertyChangeListener(PropertyChangeListener)</code>). To be
+				recognized as an event set, there must also be a corresponding remove
+				listener method (i.e., <code>
+				removePropertyChangeListener(PropertyChangeListener)</code>), even
+				though HiveMind does not make use of the remove method. This is
+				an offshoot of how the JavaBeans API defines event sets.</p>
+		</section>
+      <section>
+        <title>set</title>
+          <table>
+            <tr><th>Attribute</th> <th>Description</th></tr>
+            <tr>
+              <td>property</td>
+              <td>The name of the property to set.</td>
+            </tr>
+            <tr>
+              <td>value</td>
+              <td>The <em>selector</em> used to find an object value.  The selector consists of a prefix (such as 
+                "service" or "configuration"), a colon, and a <em>locator</em> whose interpretation is defined by 
+                the prefix.  For example, <code>service:MyService</code>.  See &hivemind.ObjectProviders;.</td>
+            </tr>
+          </table>
+      </section>
+	</body>
+</document>

Modified: hivemind/trunk/src/documentation/content/xdocs/descriptor.xml
URL: http://svn.apache.org/viewvc/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/src/documentation/content/xdocs/descriptor.xml (original)
+++ hivemind/trunk/src/documentation/content/xdocs/descriptor.xml Mon Jul 31 07:21:27 2006
@@ -33,6 +33,37 @@
 		<p>The descriptor is named <code>hivemodule.xml</code> and is stored in the
 			META-INF directory of the module.</p>
 		<p>The root element of the descriptor is the &module; element.</p>
+
+		<section>
+			<title>assembly</title>
+			<p>&_assembly; is used to define an attribute within an &invoke-factory; element. Inside
+				a &contribution;, only known attributes are allowed in elements; unknown
+				attributes will be logged as an error and ignored. In addition, some
+				attributes are required; again, errors occur if the contributed element
+				does not provide a value for the attribute.</p>
+			<table>
+				<tr>
+					<th>Attribute</th>
+					<th>Type</th>
+					<th>Required ?</th>
+					<th>Description</th>
+				</tr>
+				<tr>
+					<td>autowire-services</td>
+					<td>boolean</td>
+					<td>no</td>
+					<td>The name of the attribute.</td>
+				</tr>
+				<tr>
+					<td>initialize-method</td>
+					<td>string</td>
+					<td>no</td>
+					<td>If true, the attribute must be provided in the contributed
+						configuration element. The default is false.</td>
+				</tr>
+			</table>
+			<p><link href="site:assembly">documented separately</link>.</p>
+		</section>
 		<section>
 			<title>attribute</title>
 			<p>&_attribute; is used to define an attribute within an &element;. Inside
@@ -435,8 +466,10 @@
 				</tr>
 			</table>
 			<p>A service factory defines its parameters in terms of a schema. The
-				content of the &_invoke-factory; is converted, in accordance with the
-				factory's schema, and provided to the factory.</p>
+				content of the &_invoke-factory; (excluding any &assembly; elements) is 
+				converted, in accordance with the factory's schema, and provided to the factory.</p>
+			<p>The &_invoke-factory; element may additionally contain &assembly; elements to
+				initialize the service implementation created by the factory.</p>
 			<note>
         Additional service models can be defined via the &hivemind.ServiceModels;
 				configuration point.</note>

Modified: hivemind/trunk/src/documentation/content/xdocs/links.ent
URL: http://svn.apache.org/viewvc/hivemind/trunk/src/documentation/content/xdocs/links.ent?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/src/documentation/content/xdocs/links.ent (original)
+++ hivemind/trunk/src/documentation/content/xdocs/links.ent Mon Jul 31 07:21:27 2006
@@ -77,6 +77,9 @@
 <!ENTITY _invoke-factory '&lt;invoke-factory&gt;'>
 <!ENTITY invoke-factory '<link href="&projectroot;descriptor.html#invoke-factory">&_invoke-factory;</link>'>
 
+<!ENTITY _assembly '&lt;assembly&gt;'>
+<!ENTITY assembly '<link href="&projectroot;descriptor.html#assembly">&_assembly;</link>'>
+
 <!ENTITY _interceptor '&lt;interceptor&gt;'>
 <!ENTITY interceptor '<link href="&projectroot;descriptor.html#interceptor">&_interceptor;</link>'>
 

Modified: hivemind/trunk/src/documentation/content/xdocs/services.xml
URL: http://svn.apache.org/viewvc/hivemind/trunk/src/documentation/content/xdocs/services.xml?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/src/documentation/content/xdocs/services.xml (original)
+++ hivemind/trunk/src/documentation/content/xdocs/services.xml Mon Jul 31 07:21:27 2006
@@ -124,9 +124,14 @@
 					identify the JNDI name of the EJB's home interface, as well as the
 					home interface class itself.</p>
 				<p>Parameters to factory services are the XML elements enclosed by the &_invoke-factory;
-					element. Much like a configuration contribution, these parameters are
-					converted from XML into Java objects before being provided to the
+					element excluding any &assembly; elements. Much like a configuration contribution, 
+					these parameters are	converted from XML into Java objects before being provided to the
 					factory.</p>
+				<p>Enclosed &_assembly; elements represent assembly instructions with which the core
+					service implementation object created by the service implementation factory may be
+					initialized. This initilization encompasses dependency injection, event listener registration, 
+					and invoking any initialization method. <link href="site:assembly">Assembly 
+					instructions</link> are documented separately.</p>
 				<p>The most common service factory is &hivemind.BuilderFactory;. It is
 					used to construct a service and then set properties of the service
 					implementation object.</p>

Modified: hivemind/trunk/src/documentation/content/xdocs/site.xml
URL: http://svn.apache.org/viewvc/hivemind/trunk/src/documentation/content/xdocs/site.xml?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/src/documentation/content/xdocs/site.xml (original)
+++ hivemind/trunk/src/documentation/content/xdocs/site.xml Mon Jul 31 07:21:27 2006
@@ -33,6 +33,7 @@
       <hivedoc label="HiveDoc" href="hivedoc.html"/>
       <descriptor label="Module  Descriptor" href="descriptor.html"/>
       <rules label="Contribution Processing Rules" href="rules.html"/>
+      <assembly label="Assembly Instructions" href="assembly.html"/>
       <dependencies label="Dependencies" href="dependencies.html"/>
       <conditional label="Conditional Contributions" href="conditional.html"/>
       <serial label="Serializing Services" href="serializing.html"/>

Modified: hivemind/trunk/status.xml
URL: http://svn.apache.org/viewvc/hivemind/trunk/status.xml?rev=427127&r1=427126&r2=427127&view=diff
==============================================================================
--- hivemind/trunk/status.xml (original)
+++ hivemind/trunk/status.xml Mon Jul 31 07:21:27 2006
@@ -29,6 +29,10 @@
   </todo>
   <changes>
     <release version="1.2-alpha-1" date="unreleased">
+      <action type="add" dev="KW">Added &lt;assembly&gt; element as child of &lt;invoke-factory&gt; to provide dependency 
+      	injection logic a la BuilderFactory for custom service implementation factories.</action>
+      <action type="add" dev="KW">The &quot;object&quot; translator will now translate input values without colon separator 
+      	using the &quot;smart&quot; translator.</action>
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-162">Performance bottleneck with threaded
         services</action>
       <action type="update" dev="HLS" fixes-bug="HIVEMIND-175">Extend the Messages interface to