You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2003/06/20 17:26:09 UTC
cvs commit: jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external MapVariableSource.java VariableSourceOrder.xml TestExternalParser.java
hlship 2003/06/20 08:26:09
Modified: hivemind/src/test/hivemind/test/external
TestExternalParser.java
Added: hivemind/src/test/hivemind/test/external
MapVariableSource.java VariableSourceOrder.xml
Log:
Add tests to check that variable sources are consulted in the specified order.
Revision Changes Path
1.6 +39 -1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/TestExternalParser.java
Index: TestExternalParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/TestExternalParser.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestExternalParser.java 11 Jun 2003 14:13:29 -0000 1.5
+++ TestExternalParser.java 20 Jun 2003 15:26:09 -0000 1.6
@@ -288,4 +288,42 @@
assertEquals("${town}", e2.getContent());
}
+
+ public void testVariableSourceOrder() throws Exception
+ {
+ RegistryBuilder b = new RegistryBuilder();
+ DescriptorParser dp = new DescriptorParser();
+
+ b.processModule(_resolver, dp.parse(getMasterModuleLocation()));
+ b.processModule(_resolver, dp.parse(getLocation("VariableSourceOrder.xml")));
+
+ IRegistry r = b.constructRegistry();
+
+ List elements = r.getConfiguration("hivemind.test.external.Elements");
+ assertEquals(1, elements.size());
+
+ IElement e = (IElement) elements.get(0);
+
+ assertEquals("family", e.getElementName());
+
+ IAttribute a = (IAttribute) e.getAttributes().get(0);
+ assertEquals("husband", a.getName());
+ assertEquals("Homer Simpson", a.getValue());
+
+ List l2 = e.getElements();
+ IElement e2 = (IElement) l2.get(0);
+ assertEquals("Wife: Wilma Flintstone", e2.getContent());
+
+ e2 = (IElement) l2.get(1);
+ assertEquals("Barney Rubble", e2.getContent());
+
+ e2 = (IElement) l2.get(2);
+ assertEquals("Dino", e2.getContent());
+
+ e2 = (IElement) l2.get(3);
+ // No value for this variable.
+
+ assertEquals("${town}", e2.getContent());
+
+ }
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/MapVariableSource.java
Index: MapVariableSource.java
===================================================================
package hivemind.test.external;
import java.util.Map;
import org.apache.commons.hivemind.IVariableSource;
/**
* Allows a Map as the basis of a variable source.
*
* @author Howard Lewis Ship
* @version $Id: MapVariableSource.java,v 1.1 2003/06/20 15:26:09 hlship Exp $
*/
public class MapVariableSource implements IVariableSource
{
private Map _map;
public String valueForVariable(String variableName)
{
return (String)_map.get(variableName);
}
public Map getMap()
{
return _map;
}
public void setMap(Map map)
{
_map = map;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/external/VariableSourceOrder.xml
Index: VariableSourceOrder.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: VariableSourceOrder.xml,v 1.1 2003/06/20 15:26:09 hlship Exp $ -->
<module
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://jakarta.apache.org/commons/hivemind/schema/HiveMind_1.0.xsd"
id="hivemind.test.external"
version="1.0.0">
<contribute-configuration configuration-id="org.apache.commons.hivemind.VariableSource">
<create-instance class="org.apache.commons.hivemind.VariableSourceContribution">
<set property="order" value="1000"/>
<set-create property="source" class="hivemind.test.external.PropertiesVariableSource"/>
</create-instance>
<create-instance class="org.apache.commons.hivemind.VariableSourceContribution">
<set property="order" value="500"/>
<set-create property="source" class="hivemind.test.external.MapVariableSource">
<set-create property="map" class="java.util.HashMap">
<set property="husband" value="Homer Simpson"/>
</set-create>
</set-create>
</create-instance>
</contribute-configuration>
<configuration id="Elements" element-type="org.apache.commons.hivemind.IElement">
<xml path="Variables.xml"/>
</configuration>
</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org