hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r419543 - in /hivemind/branches/branch-2-0-annot: framework/src/java/org/apache/hivemind/definition/ framework/src/java/org/apache/hivemind/impl/ framework/src/test/org/apache/hivemind/impl/ xml/src/java/org/apache/hivemind/impl/ xml/src/te...
Date Thu, 06 Jul 2006 13:00:38 GMT
Author: ahuegen
Date: Thu Jul  6 06:00:37 2006
New Revision: 419543

URL: http://svn.apache.org/viewvc?rev=419543&view=rev
Log:
Fixed and restructured some more unit tests.

Added:
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestInterceptors.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplMessages.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplStrings.properties
    hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestXmlModuleDescriptorProcessor.java
Modified:
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java
    hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestServicePoint.java
    hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/definition/ModuleDefinition.java
Thu Jul  6 06:00:37 2006
@@ -7,6 +7,7 @@
 
 import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.Location;
+import org.apache.hivemind.util.Defense;
 
 public class ModuleDefinition
 {
@@ -28,12 +29,20 @@
     {
     }
 
+    /**
+     * @param id
+     * @param location
+     * @param resolver
+     * @param packageName  name of the package to search for class names within. If null,
it defaults to the id 
+     */
     public ModuleDefinition(String id, Location location, ClassResolver resolver, String
packageName)
     {
         _id = id;
         _location = location;
         _classResolver = resolver;
-        _packageName = packageName;
+        if (packageName != null)
+            _packageName = packageName;
+        else _packageName = id;
     }
 
     public ClassResolver getClassResolver()
@@ -66,6 +75,10 @@
         this._id = moduleId;
     }
 
+    /**
+     * Returns the name of the package to search for class names within. By default, the
package
+     * name will match the module id, but this can be overridden in the module descriptor.
+     */
     public String getPackageName()
     {
         return _packageName;

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplMessages.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
Thu Jul  6 06:00:37 2006
@@ -354,16 +354,6 @@
         return _formatter.format("module", module.getModuleId());
     }
 
-    static String unableToResolveSchema(String schemaId)
-    {
-        return _formatter.format("unable-to-resolve-schema", schemaId);
-    }
-
-    static String schemaNotVisible(String schemaId, String moduleId)
-    {
-        return _formatter.format("schema-not-visible", schemaId, moduleId);
-    }
-
     static String serviceNotVisible(String serviceId, Module module)
     {
         return _formatter.format("service-not-visible", serviceId, convertModule(module));

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
Thu Jul  6 06:00:37 2006
@@ -75,8 +75,6 @@
 null-module=the application
 module=module {0}
 
-unable-to-resolve-schema=Unable to resolve reference to schema ''{0}''.
-schema-not-visible=Schema ''{0}'' is not visible to module {1}.
 service-not-visible=Service point {0} is not visible to {1}.
 configuration-not-visible=Configuration point {0} is not visible to {1}.
 

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
Thu Jul  6 06:00:37 2006
@@ -107,7 +107,7 @@
         }
     }
 
-    public void addModule(ModuleDefinition moduleDefinition)
+    private void addModule(ModuleDefinition moduleDefinition)
     {
         String id = moduleDefinition.getId();
 

Added: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestInterceptors.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestInterceptors.java?rev=419543&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestInterceptors.java
(added)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestInterceptors.java
Thu Jul  6 06:00:37 2006
@@ -0,0 +1,121 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.internal.Module;
+import org.apache.hivemind.internal.ServiceModel;
+import org.apache.hivemind.internal.ServiceModelFactory;
+import org.apache.hivemind.test.HiveMindTestCase;
+import org.easymock.MockControl;
+
+/**
+ * Test for interceptors.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 1.1
+ */
+public class TestInterceptors extends HiveMindTestCase
+{
+    public void testDefaultInterceptorOrdering()
+    {
+        Location l = newLocation();
+        Module module = newModule();
+
+        replayControls();
+
+        ServicePointImpl sp = new ServicePointImpl();
+        sp.setModule(module);
+        sp.setServiceInterfaceName("foo.bar.Baz");
+        sp.setExtensionPointId("zip.zap");
+        sp.setLocation(l);
+        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
+        interceptor1.setFactoryServiceId("SomeFactory1");
+        sp.addInterceptorContribution(interceptor1);
+        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
+        interceptor2.setFactoryServiceId("SomeFactory2");
+        sp.addInterceptorContribution(interceptor2);
+        sp.setExtensionPointId("ExtensionPointId");
+        final List ordered = sp.getOrderedInterceptorContributions();
+        assertNotNull(ordered);
+        assertEquals(2, ordered.size());
+        assertEquals(interceptor1, ordered.get(0));
+        assertEquals(interceptor2, ordered.get(1));
+        verifyControls();
+    }
+
+    public void testCustomInterceptorOrdering()
+    {
+        Location l = newLocation();
+        Module module = newModule();
+
+        replayControls();
+
+        ServicePointImpl sp = new ServicePointImpl();
+        sp.setModule(module);
+        sp.setServiceInterfaceName("foo.bar.Baz");
+        sp.setExtensionPointId("zip.zap");
+        sp.setLocation(l);
+        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
+        interceptor1.setFactoryServiceId("SomeFactory1");
+        sp.addInterceptorContribution(interceptor1);
+        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
+        interceptor2.setFactoryServiceId("SomeFactory2");
+        interceptor2.setFollowingInterceptorIds("SomeFactory1");
+        sp.addInterceptorContribution(interceptor2);
+        sp.setExtensionPointId("ExtensionPointId");
+        final List ordered = sp.getOrderedInterceptorContributions();
+        assertNotNull(ordered);
+        assertEquals(2, ordered.size());
+        assertEquals(interceptor2, ordered.get(0));
+        assertEquals(interceptor1, ordered.get(1));
+        verifyControls();
+    }
+
+    public void testInterceptorOrderingByName()
+    {
+        Location l = newLocation();
+        Module module = newModule();
+
+        replayControls();
+
+        ServicePointImpl sp = new ServicePointImpl();
+        sp.setModule(module);
+        sp.setServiceInterfaceName("foo.bar.Baz");
+        sp.setExtensionPointId("zip.zap");
+        sp.setLocation(l);
+        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
+        interceptor1.setFactoryServiceId("SomeFactory1");
+        interceptor1.setName("Interceptor1");
+        sp.addInterceptorContribution(interceptor1);
+        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
+        interceptor2.setFactoryServiceId("SomeFactory2");
+        interceptor2.setFollowingInterceptorIds("Interceptor1");
+        sp.addInterceptorContribution(interceptor2);
+        sp.setExtensionPointId("ExtensionPointId");
+        final List ordered = sp.getOrderedInterceptorContributions();
+        assertNotNull(ordered);
+        assertEquals(2, ordered.size());
+        assertEquals(interceptor2, ordered.get(0));
+        assertEquals(interceptor1, ordered.get(1));
+        verifyControls();
+    }
+}
\ No newline at end of file

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java
Thu Jul  6 06:00:37 2006
@@ -14,26 +14,16 @@
 
 package org.apache.hivemind.impl;
 
-import java.util.List;
-import java.util.Locale;
+import hivemind.test.FrameworkTestCase;
 
-import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hivemind.Element;
-import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.Location;
+import org.apache.hivemind.definition.ConfigurationPointDefinition;
+import org.apache.hivemind.definition.ModuleDefinition;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.definition.ServicePointDefinition;
 import org.apache.hivemind.internal.ConfigurationPoint;
 import org.apache.hivemind.internal.RegistryInfrastructure;
-import org.apache.hivemind.internal.Visibility;
-import org.apache.hivemind.parse.ConfigurationPointDescriptor;
-import org.apache.hivemind.parse.ContributionDescriptor;
-import org.apache.hivemind.parse.ModuleDescriptor;
-import org.apache.hivemind.schema.impl.SchemaImpl;
-import org.apache.hivemind.test.AggregateArgumentsMatcher;
-import org.apache.hivemind.test.ArgumentMatcher;
-import org.apache.hivemind.test.HiveMindTestCase;
-import org.apache.hivemind.test.TypeMatcher;
-import org.easymock.MockControl;
+import org.apache.hivemind.internal.ServicePoint;
 
 /**
  * Tests for {@link RegistryInfrastructureConstructor}.
@@ -41,251 +31,38 @@
  * @author Knut Wannheden
  * @since 1.1
  */
-public class TestRegistryInfrastructureConstructor extends HiveMindTestCase
+public class TestRegistryInfrastructureConstructor extends FrameworkTestCase
 {
     public void testFound()
     {
-        SchemaImpl schema = new SchemaImpl("module");
-        schema.setId("Baz");
-
         DefaultErrorHandler errorHandler = new DefaultErrorHandler();
 
-        ModuleDescriptor fooBar = new ModuleDescriptor(null, errorHandler);
-        fooBar.setModuleId("foo.bar");
+    	RegistryDefinition definition = new RegistryDefinition(errorHandler);
+    	
+        ModuleDefinition fooBar = createModuleDefinition("foo.bar");
 
-        fooBar.addSchema(schema);
+        ServicePointDefinition spd = createServicePointDefinition("sp1", Runnable.class);
 
-        ModuleDescriptor zipZoop = new ModuleDescriptor(null, errorHandler);
-        zipZoop.setModuleId("zip.zoop");
+        fooBar.addServicePoint(spd);
 
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-        cpd.setId("Zap");
-        cpd.setContributionsSchemaId("foo.bar.Baz");
+        ModuleDefinition zipZoop = createModuleDefinition("zip.zoop");
 
+        ConfigurationPointDefinition cpd = createConfigurationPointDefinition("cp1");
+        
         zipZoop.addConfigurationPoint(cpd);
+        
+        definition.addModule(fooBar);
+        definition.addModule(zipZoop);
 
         RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(errorHandler,
-                LogFactory.getLog(TestRegistryInfrastructureConstructor.class), null);
-
-        ric.addModuleDescriptor(fooBar);
-        ric.addModuleDescriptor(zipZoop);
-
-        RegistryInfrastructure registry = ric.constructRegistryInfrastructure(Locale.getDefault());
-
-        ConfigurationPoint point = registry.getConfigurationPoint("zip.zoop.Zap", null);
-        assertEquals(schema, point.getContributionsSchema());
-    }
-
-    public void testNotVisible()
-    {
-        MockControl ehControl = newControl(ErrorHandler.class);
-        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
-
-        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
-
-        SchemaImpl schema = new SchemaImpl("module");
-        schema.setId("Baz");
-        schema.setVisibility(Visibility.PRIVATE);
-
-        Location l = newLocation();
-
-        eh.error(log, ImplMessages.schemaNotVisible("foo.bar.Baz", "zip.zoop"), l, null);
-
-        replayControls();
-
-        ModuleDescriptor fooBar = new ModuleDescriptor(null, eh);
-        fooBar.setModuleId("foo.bar");
-
-        fooBar.addSchema(schema);
-
-        ModuleDescriptor zipZoop = new ModuleDescriptor(null, eh);
-        zipZoop.setModuleId("zip.zoop");
-
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-        cpd.setId("Zap");
-        cpd.setContributionsSchemaId("foo.bar.Baz");
-        cpd.setLocation(l);
-
-        zipZoop.addConfigurationPoint(cpd);
-
-        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
-
-        ric.addModuleDescriptor(fooBar);
-        ric.addModuleDescriptor(zipZoop);
-
-        ric.constructRegistryInfrastructure(Locale.getDefault());
-
-        verifyControls();
-    }
-
-    public void testNotFound()
-    {
-        MockControl ehControl = newControl(ErrorHandler.class);
-        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
-
-        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
-
-        Location l = newLocation();
-
-        eh.error(log, ImplMessages.unableToResolveSchema("foo.bar.Baz"), l, null);
-
-        replayControls();
-
-        ModuleDescriptor zipZoop = new ModuleDescriptor(null, eh);
-        zipZoop.setModuleId("zip.zoop");
-
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-        cpd.setId("Zap");
-        cpd.setContributionsSchemaId("foo.bar.Baz");
-        cpd.setLocation(l);
-
-        zipZoop.addConfigurationPoint(cpd);
-
-        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
-
-        ric.addModuleDescriptor(zipZoop);
-
-        ric.constructRegistryInfrastructure(Locale.getDefault());
-
-        verifyControls();
-    }
-
-    private Element newElement(String name)
-    {
-        ElementImpl e = new ElementImpl();
-
-        e.setElementName(name);
-
-        return e;
-    }
-
-    public void testConditionalExpressionTrue()
-    {
-        MockControl ehControl = newControl(ErrorHandler.class);
-        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
-
-        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
-
-        replayControls();
-
-        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), eh);
-        md.setModuleId("zip.zoop");
-
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-
-        cpd.setId("Fred");
-
-        md.addConfigurationPoint(cpd);
-
-        ContributionDescriptor cd = new ContributionDescriptor();
-        cd.setConfigurationId("Fred");
-        cd.setConditionalExpression("class " + Location.class.getName());
-
-        cd.addElement(newElement("foo"));
-
-        md.addContribution(cd);
-
-        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
-
-        ric.addModuleDescriptor(md);
-
-        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
-
-        List l = ri.getConfiguration("zip.zoop.Fred", null);
-
-        Element e = (Element) l.get(0);
-
-        assertEquals("foo", e.getElementName());
-
-        verifyControls();
-    }
-
-    public void testConditionalExpressionFalse()
-    {
-        MockControl ehControl = newControl(ErrorHandler.class);
-        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
-
-        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
-
-        replayControls();
-
-        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), eh);
-        md.setModuleId("zip.zoop");
-
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-
-        cpd.setId("Fred");
-
-        md.addConfigurationPoint(cpd);
-
-        ContributionDescriptor cd = new ContributionDescriptor();
-        cd.setConfigurationId("Fred");
-        cd.setConditionalExpression("class foo.bar.Baz");
-
-        cd.addElement(newElement("bar"));
-
-        md.addContribution(cd);
-
-        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
-
-        ric.addModuleDescriptor(md);
-
-        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
-
-        List l = ri.getConfiguration("zip.zoop.Fred", null);
-
-        assertTrue(l.isEmpty());
-
-        verifyControls();
-    }
-
-    public void testConditionalExpressionError()
-    {
-        MockControl ehControl = newControl(ErrorHandler.class);
-        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
-
-        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
-
-        Location location = newLocation();
-
-        eh.error(
-                log,
-                "Unexpected token <AND> in expression 'and class foo'.",
-                location,
-                new RuntimeException());
-        ehControl.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
-        { null, null, null, new TypeMatcher() }));
-
-        replayControls();
-
-        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), eh);
-        md.setModuleId("zip.zoop");
-
-        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
-
-        cpd.setId("Fred");
-
-        md.addConfigurationPoint(cpd);
-
-        ContributionDescriptor cd = new ContributionDescriptor();
-        cd.setConfigurationId("Fred");
-        cd.setConditionalExpression("and class foo");
-        cd.setLocation(location);
-
-        cd.addElement(newElement("bar"));
-
-        md.addContribution(cd);
-
-        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
-
-        ric.addModuleDescriptor(md);
-
-        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
+                LogFactory.getLog(TestXmlModuleDescriptorProcessor.class), null);
 
-        List l = ri.getConfiguration("zip.zoop.Fred", null);
+        RegistryInfrastructure registryInfrastructure = ric.constructRegistryInfrastructure(definition);
 
-        assertTrue(l.isEmpty());
+        ServicePoint sp = registryInfrastructure.getServicePoint("foo.bar.sp1", null);
+        assertNotNull(sp);
 
-        verifyControls();
+        ConfigurationPoint cp = registryInfrastructure.getConfigurationPoint("zip.zoop.cp1",
null);
+        assertNotNull(cp);
     }
 }

Modified: hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestServicePoint.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestServicePoint.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestServicePoint.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestServicePoint.java
Thu Jul  6 06:00:37 2006
@@ -75,90 +75,6 @@
         verifyControls();
     }
 
-    public void testDefaultInterceptorOrdering()
-    {
-        Location l = newLocation();
-        Module module = newModule();
-
-        replayControls();
-
-        ServicePointImpl sp = new ServicePointImpl();
-        sp.setModule(module);
-        sp.setServiceInterfaceName("foo.bar.Baz");
-        sp.setExtensionPointId("zip.zap");
-        sp.setLocation(l);
-        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
-        interceptor1.setFactoryServiceId("SomeFactory1");
-        sp.addInterceptorContribution(interceptor1);
-        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
-        interceptor2.setFactoryServiceId("SomeFactory2");
-        sp.addInterceptorContribution(interceptor2);
-        sp.setExtensionPointId("ExtensionPointId");
-        final List ordered = sp.getOrderedInterceptorContributions();
-        assertNotNull(ordered);
-        assertEquals(2, ordered.size());
-        assertEquals(interceptor1, ordered.get(0));
-        assertEquals(interceptor2, ordered.get(1));
-        verifyControls();
-    }
-
-    public void testCustomInterceptorOrdering()
-    {
-        Location l = newLocation();
-        Module module = newModule();
-
-        replayControls();
-
-        ServicePointImpl sp = new ServicePointImpl();
-        sp.setModule(module);
-        sp.setServiceInterfaceName("foo.bar.Baz");
-        sp.setExtensionPointId("zip.zap");
-        sp.setLocation(l);
-        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
-        interceptor1.setFactoryServiceId("SomeFactory1");
-        sp.addInterceptorContribution(interceptor1);
-        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
-        interceptor2.setFactoryServiceId("SomeFactory2");
-        interceptor2.setFollowingInterceptorIds("SomeFactory1");
-        sp.addInterceptorContribution(interceptor2);
-        sp.setExtensionPointId("ExtensionPointId");
-        final List ordered = sp.getOrderedInterceptorContributions();
-        assertNotNull(ordered);
-        assertEquals(2, ordered.size());
-        assertEquals(interceptor2, ordered.get(0));
-        assertEquals(interceptor1, ordered.get(1));
-        verifyControls();
-    }
-
-    public void testInterceptorOrderingByName()
-    {
-        Location l = newLocation();
-        Module module = newModule();
-
-        replayControls();
-
-        ServicePointImpl sp = new ServicePointImpl();
-        sp.setModule(module);
-        sp.setServiceInterfaceName("foo.bar.Baz");
-        sp.setExtensionPointId("zip.zap");
-        sp.setLocation(l);
-        final ServiceInterceptorContributionImpl interceptor1 = new ServiceInterceptorContributionImpl();
-        interceptor1.setFactoryServiceId("SomeFactory1");
-        interceptor1.setName("Interceptor1");
-        sp.addInterceptorContribution(interceptor1);
-        final ServiceInterceptorContributionImpl interceptor2 = new ServiceInterceptorContributionImpl();
-        interceptor2.setFactoryServiceId("SomeFactory2");
-        interceptor2.setFollowingInterceptorIds("Interceptor1");
-        sp.addInterceptorContribution(interceptor2);
-        sp.setExtensionPointId("ExtensionPointId");
-        final List ordered = sp.getOrderedInterceptorContributions();
-        assertNotNull(ordered);
-        assertEquals(2, ordered.size());
-        assertEquals(interceptor2, ordered.get(0));
-        assertEquals(interceptor1, ordered.get(1));
-        verifyControls();
-    }
-
     public void testResultNotAssignableToServiceInterface()
     {
         Location l = newLocation();

Added: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplMessages.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplMessages.java?rev=419543&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplMessages.java
(added)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplMessages.java
Thu Jul  6 06:00:37 2006
@@ -0,0 +1,39 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.impl;
+
+
+/**
+ * Used to format messages used in errors and log output for classes within the impl package.
+ * 
+ * @author Howard Lewis Ship
+ */
+class XmlImplMessages
+{
+    private static final MessageFormatter _formatter = new MessageFormatter(ImplMessages.class,
+            "XmlImplStrings");
+
+
+    static String unableToResolveSchema(String schemaId)
+    {
+        return _formatter.format("unable-to-resolve-schema", schemaId);
+    }
+
+    static String schemaNotVisible(String schemaId, String moduleId)
+    {
+        return _formatter.format("schema-not-visible", schemaId, moduleId);
+    }
+    
+}
\ No newline at end of file

Added: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplStrings.properties
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplStrings.properties?rev=419543&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplStrings.properties
(added)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlImplStrings.properties
Thu Jul  6 06:00:37 2006
@@ -0,0 +1,16 @@
+# Copyright 2004, 2005 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.
+
+unable-to-resolve-schema=Unable to resolve reference to schema ''{0}''.
+schema-not-visible=Schema ''{0}'' is not visible to module {1}.

Modified: hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java?rev=419543&r1=419542&r2=419543&view=diff
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
(original)
+++ hivemind/branches/branch-2-0-annot/xml/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProcessor.java
Thu Jul  6 06:00:37 2006
@@ -8,7 +8,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.ErrorHandler;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.conditional.EvaluationContextImpl;
@@ -343,8 +342,7 @@
                 Schema schema = findSchema(sourceModule, cpd.getContributionsSchemaId(),
cpd.getLocation());
                 
                 if (schema == null) {
-                    // TODO annotations: Exceptionhandling, errorHandler benutzen
-                    throw new ApplicationRuntimeException("Schema could not be resolved");
+                    // Error-Handling has been done in findSchema already
                 } else {
                     xmlNature.setSchema(schema);
                     XmlConfigurationConstructor constructor = (XmlConfigurationConstructor)
point.getConstructor();
@@ -373,8 +371,7 @@
                 // Store the schema in the nature
                 Schema schema = findSchema(sourceModule, spd.getParametersSchemaId(), spd.getLocation());
                 if (schema == null) {
-                    // TODO annotations: Exceptionhandling, errorHandler benutzen
-                    throw new ApplicationRuntimeException("Schema could not be resolved");
+                    // Error-Handling has been done in findSchema already
                 } else {
                     xmlNature.setParametersSchema(schema);
                     xmlNature.setParametersCount(spd.getParametersCount());
@@ -395,25 +392,24 @@
     }
     
     /**
-     * Schemas are held locally. Todo: Move to XMLRegistryNature
      * @param schemaId
      * @param referencingModule
-     * @param reference
-     * @return
+     * @param location
+     * @return  
      */
-    private Schema getSchema(String schemaId, String referencingModule, Location reference)
+    private Schema getSchema(String schemaId, String referencingModule, Location location)
     {
         Schema schema = (Schema) getXmlRegistryNature().getSchema(schemaId);
 
         if (schema == null)
             _errorHandler
-                    .error(_log, ImplMessages.unableToResolveSchema(schemaId), reference,
null);
+                    .error(_log, XmlImplMessages.unableToResolveSchema(schemaId), location,
null);
         else if (!schema.visibleToModule(referencingModule))
         {
             _errorHandler.error(
                     _log,
-                    ImplMessages.schemaNotVisible(schemaId, referencingModule),
-                    reference,
+                    XmlImplMessages.schemaNotVisible(schemaId, referencingModule),
+                    location,
                     null);
             schema = null;
         }

Added: hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestXmlModuleDescriptorProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestXmlModuleDescriptorProcessor.java?rev=419543&view=auto
==============================================================================
--- hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestXmlModuleDescriptorProcessor.java
(added)
+++ hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestXmlModuleDescriptorProcessor.java
Thu Jul  6 06:00:37 2006
@@ -0,0 +1,305 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.hivemind.impl;
+
+import hivemind.test.FrameworkTestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.Element;
+import org.apache.hivemind.ErrorHandler;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.definition.ConfigurationPointDefinition;
+import org.apache.hivemind.definition.RegistryDefinition;
+import org.apache.hivemind.impl.natures.XmlConfigurationPointNature;
+import org.apache.hivemind.internal.Visibility;
+import org.apache.hivemind.parse.ConfigurationPointDescriptor;
+import org.apache.hivemind.parse.ContributionDescriptor;
+import org.apache.hivemind.parse.ModuleDescriptor;
+import org.apache.hivemind.schema.impl.SchemaImpl;
+import org.apache.hivemind.test.AggregateArgumentsMatcher;
+import org.apache.hivemind.test.ArgumentMatcher;
+import org.apache.hivemind.test.TypeMatcher;
+import org.easymock.MockControl;
+
+/**
+ * Tests for {@link XmlModuleDescriptorProcessor}.
+ * 
+ * @author Knut Wannheden
+ * @since 1.1
+ */
+public class TestXmlModuleDescriptorProcessor extends FrameworkTestCase
+{
+    /**
+     * Tests if a schema referenced by id from a configuration point is resolved correctly,
if it is
+     * defined in another module.
+     */
+    public void testSchemaResolving()
+    {
+        SchemaImpl schema = new SchemaImpl("module");
+        schema.setId("Baz");
+
+        DefaultErrorHandler errorHandler = new DefaultErrorHandler();
+        RegistryDefinition definition = new RegistryDefinition(errorHandler);
+
+        ModuleDescriptor fooBar = new ModuleDescriptor(null, errorHandler);
+        fooBar.setModuleId("foo.bar");
+
+        fooBar.addSchema(schema);
+
+        ModuleDescriptor zipZoop = new ModuleDescriptor(null, errorHandler);
+        zipZoop.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+        cpd.setId("Zap");
+        cpd.setContributionsSchemaId("foo.bar.Baz");
+
+        zipZoop.addConfigurationPoint(cpd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
+                errorHandler);
+        processor.processModuleDescriptor(fooBar);
+        processor.processModuleDescriptor(zipZoop);
+        processor.resolveSchemas();
+
+        ConfigurationPointDefinition point = definition.getConfigurationPoint("zip.zoop.Zap");
+        XmlConfigurationPointNature xmlNature = (XmlConfigurationPointNature) point
+                .getNature(XmlConfigurationPointNature.class);
+        assertNotNull(xmlNature);
+        assertEquals(schema, xmlNature.getSchema());
+    }
+
+    /**
+     * Tests if a schema referenced by id from a configuration point is not visible, if it
is
+     * defined as private in another module.
+     */
+    public void testSchemaNotVisible()
+    {
+        MockControl ehControl = newControl(ErrorHandler.class);
+        ErrorHandler errorHandler = (ErrorHandler) ehControl.getMock();
+
+        Log log = LogFactory.getLog(XmlModuleDescriptorProcessor.class);
+
+        SchemaImpl schema = new SchemaImpl("foo.bar");
+        schema.setId("Baz");
+        schema.setVisibility(Visibility.PRIVATE);
+
+        RegistryDefinition definition = new RegistryDefinition(errorHandler);
+
+        Location l = newLocation();
+
+        errorHandler.error(
+                log,
+                XmlImplMessages.schemaNotVisible("foo.bar.Baz", "zip.zoop"),
+                l,
+                null);
+
+        replayControls();
+
+        ModuleDescriptor fooBar = new ModuleDescriptor(null, errorHandler);
+        fooBar.setModuleId("foo.bar");
+
+        fooBar.addSchema(schema);
+
+        ModuleDescriptor zipZoop = new ModuleDescriptor(null, errorHandler);
+        zipZoop.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+        cpd.setId("Zap");
+        cpd.setContributionsSchemaId("foo.bar.Baz");
+        cpd.setLocation(l);
+
+        zipZoop.addConfigurationPoint(cpd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
+                errorHandler);
+        processor.processModuleDescriptor(fooBar);
+        processor.processModuleDescriptor(zipZoop);
+        processor.resolveSchemas();
+
+        verifyControls();
+    }
+
+    public void testSchemaNotFound()
+    {
+        ErrorHandler errorHandler = new DefaultErrorHandler();
+
+        Log log = LogFactory.getLog(XmlModuleDescriptorProcessor.class);
+
+        RegistryDefinition definition = new RegistryDefinition(errorHandler);
+
+        Location l = newLocation();
+
+        errorHandler.error(log, XmlImplMessages.unableToResolveSchema("foo.bar.Baz"), l,
null);
+
+        replayControls();
+
+        ModuleDescriptor zipZoop = new ModuleDescriptor(null, errorHandler);
+        zipZoop.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+        cpd.setId("Zap");
+        cpd.setContributionsSchemaId("foo.bar.Baz");
+        cpd.setLocation(l);
+
+        zipZoop.addConfigurationPoint(cpd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
+                errorHandler);
+        processor.processModuleDescriptor(zipZoop);
+        processor.resolveSchemas();
+
+        verifyControls();
+    }
+
+    private Element newElement(String name)
+    {
+        ElementImpl e = new ElementImpl();
+
+        e.setElementName(name);
+
+        return e;
+    }
+
+    public void testContributionConditionalExpressionTrue()
+    {
+        ErrorHandler errorHandler = new DefaultErrorHandler();
+
+        RegistryDefinition definition = new RegistryDefinition(errorHandler);
+
+        replayControls();
+
+        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), errorHandler);
+        md.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+
+        cpd.setId("Fred");
+
+        md.addConfigurationPoint(cpd);
+
+        ContributionDescriptor cd = new ContributionDescriptor();
+        cd.setConfigurationId("Fred");
+        cd.setConditionalExpression("class " + Location.class.getName());
+
+        cd.addElement(newElement("foo"));
+
+        md.addContribution(cd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
+                errorHandler);
+        processor.processModuleDescriptor(md);
+
+        definition.resolveExtensions();
+
+        ConfigurationPointDefinition configurationPoint = definition
+                .getConfigurationPoint("zip.zoop.Fred");
+
+        assertTrue(configurationPoint.getContributions().size() > 0);
+
+        verifyControls();
+    }
+
+    public void testConditionalExpressionFalse()
+    {
+        ErrorHandler errorHandler = new DefaultErrorHandler();
+
+        RegistryDefinition definition = new RegistryDefinition(errorHandler);
+
+        replayControls();
+
+        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), errorHandler);
+        md.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+
+        cpd.setId("Fred");
+
+        md.addConfigurationPoint(cpd);
+
+        ContributionDescriptor cd = new ContributionDescriptor();
+        cd.setConfigurationId("Fred");
+        cd.setConditionalExpression("class foo.bar.Baz");
+
+        cd.addElement(newElement("foo"));
+
+        md.addContribution(cd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
+                errorHandler);
+        processor.processModuleDescriptor(md);
+
+        definition.resolveExtensions();
+
+        ConfigurationPointDefinition configurationPoint = definition
+                .getConfigurationPoint("zip.zoop.Fred");
+
+        assertTrue(configurationPoint.getContributions().isEmpty());
+
+        verifyControls();
+    }
+
+    public void testConditionalExpressionError()
+    {
+        MockControl ehControl = newControl(ErrorHandler.class);
+        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
+
+        RegistryDefinition definition = new RegistryDefinition(eh);
+
+        Log log = LogFactory.getLog(XmlModuleDescriptorProcessor.class);
+
+        Location location = newLocation();
+
+        eh.error(
+                log,
+                "Unexpected token <AND> in expression 'and class foo'.",
+                location,
+                new RuntimeException());
+        ehControl.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
+        { null, null, null, new TypeMatcher() }));
+
+        replayControls();
+
+        ModuleDescriptor md = new ModuleDescriptor(getClassResolver(), eh);
+        md.setModuleId("zip.zoop");
+
+        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
+
+        cpd.setId("Fred");
+
+        md.addConfigurationPoint(cpd);
+
+        ContributionDescriptor cd = new ContributionDescriptor();
+        cd.setConfigurationId("Fred");
+        cd.setConditionalExpression("and class foo");
+        cd.setLocation(location);
+
+        cd.addElement(newElement("bar"));
+
+        md.addContribution(cd);
+
+        XmlModuleDescriptorProcessor processor = new XmlModuleDescriptorProcessor(definition,
eh);
+        processor.processModuleDescriptor(md);
+
+        definition.resolveExtensions();
+
+        ConfigurationPointDefinition configurationPoint = definition
+                .getConfigurationPoint("zip.zoop.Fred");
+
+        assertTrue(configurationPoint.getContributions().isEmpty());
+
+        verifyControls();
+    }
+}
\ No newline at end of file



Mime
View raw message