hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r415201 [2/2] - in /jakarta/hivemind/branches/branch-2-0-annot/xml/src: descriptor/META-INF/ java/org/apache/hivemind/ java/org/apache/hivemind/ant/ java/org/apache/hivemind/impl/ java/org/apache/hivemind/parse/ java/org/apache/hivemind/sch...
Date Sun, 18 Jun 2006 21:52:43 GMT
Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
(from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java&r1=413141&r2=415201&rev=415201&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
(original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
Sun Jun 18 14:52:39 2006
@@ -17,7 +17,9 @@
 import hivemind.test.services.StringHolder;
 import hivemind.test.services.impl.StringHolderImpl;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -25,15 +27,18 @@
 import java.util.TreeSet;
 
 import org.apache.hivemind.Location;
+import org.apache.hivemind.TranslatorManager;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.schema.SchemaProcessor;
 import org.apache.hivemind.schema.Translator;
 import org.apache.hivemind.schema.impl.AttributeModelImpl;
 import org.apache.hivemind.schema.impl.ElementModelImpl;
 import org.apache.hivemind.schema.impl.SchemaImpl;
+import org.apache.hivemind.schema.rules.AddToMapRule;
 import org.apache.hivemind.schema.rules.CreateObjectRule;
 import org.apache.hivemind.schema.rules.InvokeParentRule;
 import org.apache.hivemind.schema.rules.NullTranslator;
+import org.apache.hivemind.schema.rules.PushAttributeRule;
 import org.apache.hivemind.schema.rules.ReadAttributeRule;
 import org.apache.hivemind.schema.rules.ReadContentRule;
 import org.apache.hivemind.test.HiveMindTestCase;
@@ -52,8 +57,11 @@
     {
         MockControl control = newControl(Module.class);
         Module m = (Module) control.getMock();
+        
+        MockControl tmControl = newControl(TranslatorManager.class);
+        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
 
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
 
         em.setElementName("fred");
         em.setContentTranslator("smart");
@@ -67,9 +75,8 @@
 
         em.addRule(new InvokeParentRule("addElement"));
 
-        SchemaImpl schema = new SchemaImpl();
+        SchemaImpl schema = new SchemaImpl("module");
         schema.addElementModel(em);
-        schema.setModule(m);
 
         SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
 
@@ -78,6 +85,9 @@
         element.setContent("flintstone");
 
         List elements = Collections.singletonList(element);
+        
+        m.getModule("module");
+        control.setReturnValue(m);
 
         m.resolveType("hivemind.test.services.impl.StringHolderImpl");
         control.setReturnValue(StringHolderImpl.class);
@@ -85,17 +95,16 @@
         m.expandSymbols("flintstone", null);
         control.setReturnValue("flintstone");
 
-        m.getTranslator("smart");
-        control.setReturnValue(new NullTranslator());
-
+        tm.getTranslator("smart");
+        tmControl.setReturnValue(new NullTranslator());
+         
         replayControls();
 
-        p.process(elements, m);
-
-        List l = p.getElements();
+        List dest = new ArrayList();
+        p.process(dest, elements, m, tm);
 
-        assertEquals(1, l.size());
-        StringHolder h = (StringHolder) l.get(0);
+        assertEquals(1, dest.size());
+        StringHolder h = (StringHolder) dest.get(0);
 
         assertEquals("flintstone", h.getValue());
 
@@ -106,8 +115,11 @@
     {
         MockControl control = newControl(Module.class);
         Module m = (Module) control.getMock();
+        
+        MockControl tmControl = newControl(TranslatorManager.class);
+        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
 
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
 
         em.setElementName("fred");
         // No content handler specified
@@ -121,9 +133,8 @@
 
         em.addRule(new InvokeParentRule("addElement"));
 
-        SchemaImpl schema = new SchemaImpl();
+        SchemaImpl schema = new SchemaImpl("module");
         schema.addElementModel(em);
-        schema.setModule(m);
 
         SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
 
@@ -139,14 +150,16 @@
         m.expandSymbols("flintstone", null);
         control.setReturnValue("flintstone");
 
+        m.getModule("module");
+        control.setReturnValue(m);
+        
         replayControls();
 
-        p.process(elements, m);
-
-        List l = p.getElements();
+        List dest = new ArrayList();
+        p.process(dest, elements, m, tm);
 
-        assertEquals(1, l.size());
-        StringHolder h = (StringHolder) l.get(0);
+        assertEquals(1, dest.size());
+        StringHolder h = (StringHolder) dest.get(0);
 
         assertEquals("flintstone", h.getValue());
 
@@ -157,8 +170,11 @@
     {
         MockControl control = newControl(Module.class);
         Module m = (Module) control.getMock();
+        
+        MockControl tmControl = newControl(TranslatorManager.class);
+        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
 
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
 
         AttributeModelImpl am = new AttributeModelImpl();
         am.setName("wife");
@@ -177,9 +193,8 @@
 
         em.addRule(new InvokeParentRule("addElement"));
 
-        SchemaImpl schema = new SchemaImpl();
+        SchemaImpl schema = new SchemaImpl("module");
         schema.addElementModel(em);
-        schema.setModule(m);
 
         SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
 
@@ -188,6 +203,9 @@
         element.addAttribute(new AttributeImpl("wife", "wilma"));
 
         List elements = Collections.singletonList(element);
+        
+        m.getModule("module");
+        control.setReturnValue(m);
 
         m.resolveType("hivemind.test.services.impl.StringHolderImpl");
         control.setReturnValue(StringHolderImpl.class);
@@ -195,17 +213,16 @@
         m.expandSymbols("wilma", null);
         control.setReturnValue("wilma");
 
-        m.getTranslator("service");
-        control.setReturnValue(new NullTranslator());
+        tm.getTranslator("service");
+        tmControl.setReturnValue(new NullTranslator());
 
         replayControls();
 
-        p.process(elements, m);
+        List dest = new ArrayList();
+        p.process(dest, elements, m, tm);
 
-        List l = p.getElements();
-
-        assertEquals(1, l.size());
-        StringHolder h = (StringHolder) l.get(0);
+        assertEquals(1, dest.size());
+        StringHolder h = (StringHolder) dest.get(0);
 
         assertEquals("wilma", h.getValue());
 
@@ -246,34 +263,41 @@
 
     public void testKeyedElement()
     {
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
+        
+        MockControl tmControl = newControl(TranslatorManager.class);
+        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
 
         em.setElementName("cartoon");
-        em.setKeyAttribute("name");
 
         AttributeModelImpl am = new AttributeModelImpl();
         am.setName("name");
         am.setTranslator("cartoon");
 
         em.addAttributeModel(am);
+        
+        PushAttributeRule nameRule = new PushAttributeRule();
+        nameRule.setAttributeName("name");
 
+        em.addRule(nameRule);
+        
         em.addRule(new CreateObjectRule("StringHolderImpl"));
-
+        
         ReadContentRule rule = new ReadContentRule();
         rule.setPropertyName("value");
 
         em.addRule(rule);
+        
+        InvokeParentRule rule2 = new InvokeParentRule("put");
+        rule2.setParameterCount(2);
+        em.addRule(rule2);
 
-        em.addRule(new InvokeParentRule("addElement"));
-
-        SchemaImpl schema = new SchemaImpl();
+        SchemaImpl schema = new SchemaImpl("module");
         schema.addElementModel(em);
 
         MockControl control = newControl(Module.class);
         Module m = (Module) control.getMock();
 
-        schema.setModule(m);
-
         SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
 
         ElementImpl element = new ElementImpl();
@@ -283,8 +307,14 @@
 
         List elements = Collections.singletonList(element);
 
-        m.getTranslator("cartoon");
-        control.setReturnValue(new NullTranslator());
+        tm.getTranslator("cartoon");
+        tmControl.setReturnValue(new NullTranslator());
+        
+        m.expandSymbols("${flintstone}", null);
+        control.setReturnValue("flintstone");
+        
+        m.getModule("module");
+        control.setReturnValue(m);
 
         m.resolveType("StringHolderImpl");
         control.setReturnValue(StringHolderImpl.class);
@@ -292,14 +322,14 @@
         m.expandSymbols("${fred}", null);
         control.setReturnValue("fred");
 
-        m.expandSymbols("${flintstone}", null);
-        control.setReturnValue("flintstone");
+        m.expandSymbols("${fred}", null);
+        control.setReturnValue("fred");
 
         MockControl tControl = newControl(Translator.class);
         Translator t = (Translator) tControl.getMock();
 
-        m.getTranslator("cartoon");
-        control.setReturnValue(t);
+//        tm.getTranslator("cartoon");
+//        tmControl.setReturnValue(t);
 
         Object flintstoneKey = new Object();
         t.translate(m, Object.class, "flintstone", element.getLocation());
@@ -307,13 +337,13 @@
 
         replayControls();
 
-        p.process(elements, m);
+        Map dest = new HashMap();
+        p.process(dest, elements, m, tm);
 
-        Map map = p.getMappedElements();
-
-        assertEquals(1, map.size());
-        StringHolder h = (StringHolder) map.get(flintstoneKey);
+        assertEquals(1, dest.size());
+        StringHolder h = (StringHolder) dest.get(flintstoneKey);
 
+        assertNotNull(h);
         assertEquals("fred", h.getValue());
 
         verifyControls();
@@ -326,7 +356,7 @@
      */
     public void testUniqueElement()
     {
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
 
         em.setElementName("cartoon");
 
@@ -347,7 +377,7 @@
 
         em.addRule(new InvokeParentRule("addElement"));
 
-        SchemaImpl schema = new SchemaImpl();
+        SchemaImpl schema = new SchemaImpl("module");
         schema.addElementModel(em);
 
         MockControl control1 = newControl(Module.class);
@@ -356,8 +386,6 @@
         MockControl control2 = newControl(Module.class);
         Module m2 = (Module) control2.getMock();
 
-        schema.setModule(m1);
-
         SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
 
         Location location1 = newLocation();
@@ -378,59 +406,66 @@
 
         MockControl tControl1 = newControl(Translator.class);
         Translator t1 = (Translator) tControl1.getMock();
-
-        m1.getTranslator("qualified-id");
-        control1.setReturnValue(t1);
-
-        String flintstoneKeyModule1 = "m1.flintstone";
-        t1.translate(m1, Object.class, "flintstone", element1.getLocation());
-        tControl1.setReturnValue(flintstoneKeyModule1);
-
+        
+        MockControl tmControl = newControl(TranslatorManager.class);
+        TranslatorManager tm = (TranslatorManager) tmControl.getMock();
+        
+        m1.getModule("module");
+        control1.setReturnValue(m1);
+        
+        m2.getModule("module");
+        control2.setReturnValue(m2);
+        
         m1.resolveType("StringHolderImpl");
         control1.setReturnValue(StringHolderImpl.class);
-
+        
         m1.expandSymbols("flintstone", location1);
         control1.setReturnValue("flintstone");
+        
+        m2.resolveType("StringHolderImpl");
+        control2.setReturnValue(StringHolderImpl.class);
+        
+        m2.expandSymbols("flintstone", location2);
+        control2.setReturnValue("flintstone");
+        
+        tm.getTranslator("qualified-id");
+        tmControl.setReturnValue(t1);
 
-        m1.getTranslator("qualified-id");
-        control1.setReturnValue(t1);
+        String flintstoneKeyModule1 = "m1.flintstone";
+        t1.translate(m1, Object.class, "flintstone", element1.getLocation());
+        tControl1.setReturnValue(flintstoneKeyModule1);
+        tm.getTranslator("qualified-id");
+        tmControl.setReturnValue(t1);
 
         t1.translate(m1, String.class, "flintstone", element1.getLocation());
         tControl1.setReturnValue(flintstoneKeyModule1);
 
-        m1.resolveType("StringHolderImpl");
-        control1.setReturnValue(StringHolderImpl.class);
-
         MockControl tControl2 = newControl(Translator.class);
         Translator t2 = (Translator) tControl2.getMock();
 
-        m2.getTranslator("qualified-id");
-        control2.setReturnValue(t2);
+        tm.getTranslator("qualified-id");
+        tmControl.setReturnValue(t2);
 
         String flintstoneKeyModule2 = "m2.flintstone";
         t2.translate(m2, Object.class, "flintstone", element2.getLocation());
         tControl2.setReturnValue(flintstoneKeyModule2);
 
-        m2.expandSymbols("flintstone", location2);
-        control2.setReturnValue("flintstone");
-
-        m2.getTranslator("qualified-id");
-        control2.setReturnValue(t2);
+        tm.getTranslator("qualified-id");
+        tmControl.setReturnValue(t2);
 
         t2.translate(m2, String.class, "flintstone", element2.getLocation());
         tControl2.setReturnValue(flintstoneKeyModule2);
 
         replayControls();
 
-        p.process(elements1, m1);
-        p.process(elements2, m2);
-
-        List list = p.getElements();
+        List dest = new ArrayList();
+        p.process(dest, elements1, m1, tm);
+        p.process(dest, elements2, m2, tm);
 
-        assertEquals(2, list.size());
+        assertEquals(2, dest.size());
 
         Set keys = new TreeSet();
-        for (Iterator iter = list.iterator(); iter.hasNext();)
+        for (Iterator iter = dest.iterator(); iter.hasNext();)
         {
             StringHolderImpl element = (StringHolderImpl) iter.next();
             keys.add(element.getValue());
@@ -444,7 +479,7 @@
 
     public void testGetAttributeDefault()
     {
-        ElementModelImpl em = new ElementModelImpl();
+        ElementModelImpl em = new ElementModelImpl("module");
         em.setElementName("fred");
 
         AttributeModelImpl am = new AttributeModelImpl();

Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestContains.java
(from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestContains.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestContains.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestContains.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestContains.java&r1=413141&r2=415201&rev=415201&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestContains.java
(original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestContains.java
Sun Jun 18 14:52:39 2006
@@ -12,7 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package hivemind.test;
+package org.apache.hivemind.xml;
+
+import hivemind.test.FrameworkTestCase;
+import hivemind.test.IMultipleService;
+import hivemind.test.IUniqueService;
 
 import org.apache.hivemind.Registry;
 

Copied: jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestSubModule.java
(from r413141, jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestSubModule.java)
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestSubModule.java?p2=jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestSubModule.java&p1=jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestSubModule.java&r1=413141&r2=415201&rev=415201&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/framework/src/test/hivemind/test/TestSubModule.java
(original)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/TestSubModule.java
Sun Jun 18 14:52:39 2006
@@ -12,8 +12,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package hivemind.test;
+package org.apache.hivemind.xml;
 
+import hivemind.test.FrameworkTestCase;
 import hivemind.test.services.SimpleService;
 
 import org.apache.hivemind.Registry;

Added: jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/XmlTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/XmlTestCase.java?rev=415201&view=auto
==============================================================================
--- jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/XmlTestCase.java
(added)
+++ jakarta/hivemind/branches/branch-2-0-annot/xml/src/test/org/apache/hivemind/xml/XmlTestCase.java
Sun Jun 18 14:52:39 2006
@@ -0,0 +1,61 @@
+// 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.xml;
+
+import hivemind.test.FrameworkTestCase;
+
+import org.apache.hivemind.Resource;
+import org.apache.hivemind.impl.DefaultErrorHandler;
+import org.apache.hivemind.parse.DependencyDescriptor;
+import org.apache.hivemind.parse.ModuleDescriptor;
+import org.apache.hivemind.parse.XmlResourceProcessor;
+
+/**
+ * Base class for xml specific tests.
+ * 
+ * @author Achim Huegen
+ */
+public abstract class XmlTestCase extends FrameworkTestCase
+{
+
+    protected ModuleDescriptor parse(String file)
+        throws Exception
+    {
+        Resource location = getResource(file);
+        DefaultErrorHandler eh = new DefaultErrorHandler();
+
+        XmlResourceProcessor p = new XmlResourceProcessor(_resolver, eh);
+
+        ModuleDescriptor result = p.processResource(location);
+
+        return result;
+    }
+
+    /**
+     * Convenience method for creating a
+     * {@link org.apache.hivemind.parse.DependencyDescriptor}.
+     */
+    protected DependencyDescriptor createDependencyDescriptor(String moduleId, String version)
+    {
+        DependencyDescriptor result = new DependencyDescriptor();
+
+        result.setModuleId(moduleId);
+        result.setVersion(version);
+        result.setLocation(newLocation());
+
+        return result;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message