You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/03/14 18:17:37 UTC
svn commit: r385838 [2/2] - in /beehive/trunk/netui: ./ src/core/
src/core/org/apache/beehive/netui/core/chain/
src/core/org/apache/beehive/netui/core/chain/impl/
src/core/org/apache/beehive/netui/core/chain/web/
src/core/org/apache/beehive/netui/core/...
Added: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml?rev=385838&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml (added)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml Tue Mar 14 09:17:31 2006
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<catalog xmlns="http://beehive.apache.org/netui/2004/server/config">
+ <chain name="echo-1234">
+ <command id="1" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo 1</value>
+ </custom-property>
+ </command>
+ <command id="2" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo 2</value>
+ </custom-property>
+ </command>
+ <command id="3" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo 3</value>
+ </custom-property>
+ </command>
+ <command id="4" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo 4</value>
+ </custom-property>
+ </command>
+ </chain>
+ <chain name="echo-abc">
+ <command id="1" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo aaa</value>
+ </custom-property>
+ </command>
+ <command id="2" classname="org.apache.beehive.netui.test.core.chain.commands.EchoCommand">
+ <custom-property>
+ <name>message</name>
+ <value>echo bbb</value>
+ </custom-property>
+ </command>
+ </chain>
+ <command name="configurable" classname="org.apache.beehive.netui.test.core.chain.commands.ConfigurableCommand">
+ <custom-property>
+ <name>foo</name>
+ <value>Homer</value>
+ </custom-property>
+ <custom-property>
+ <name>bar</name>
+ <value>54321</value>
+ </custom-property>
+ </command>
+</catalog>
\ No newline at end of file
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/tools/AssertHelper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/tools/AssertHelper.java?rev=385838&r1=385837&r2=385838&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/tools/AssertHelper.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/tools/AssertHelper.java Tue Mar 14 09:17:31 2006
@@ -22,15 +22,19 @@
import junit.framework.AssertionFailedError;
/**
- * Helpers; these are assertEquals(...), etc... methods that JUnit does not provide.
- * <p/>
+ * <p>
+ * Helpers for performing asserts between types that JUnit doesn't support.
+ * </p>
+ * <p>
* Many of these methods compare String[] to some Java type and convert the String into
* the compare-to type such as a Boolean, boolean, or Float.
- * <p/>
+ * </p>
+ * <p>
* Note, for the double / floating comparisons, these may fail on some VMs because of precision
* comparison problems.
+ * </p>
*/
-public class AssertHelper {
+public final class AssertHelper {
public static void assertEquals(double expected, double actual) {
if(expected != actual)
@@ -44,13 +48,7 @@
public static void assertEquals(String[] exp, String[] act) {
checkArrays(exp, act);
-
- for(int i = 0; i < exp.length; i++) {
- if(!exp[i].equals(act[i]))
- throw new AssertionFailedError("The values expected[" + i + "]=\"" + exp[i] + "\" does not equal actual[" + i + "]=\"" + act[i] + "\"");
- }
-
- return;
+ compareArrays(exp, act);
}
public static void assertEquals(String[] exp, boolean[] act) {
@@ -60,8 +58,6 @@
if(Boolean.valueOf(exp[i]).booleanValue() != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, int[] act) {
@@ -71,8 +67,6 @@
if(Integer.parseInt(exp[i]) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, char[] act) {
@@ -82,8 +76,6 @@
if(exp[i].charAt(0) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, byte[] act) {
@@ -93,8 +85,6 @@
if(Byte.valueOf(exp[i]).byteValue() != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, double[] act) {
@@ -104,8 +94,6 @@
if(Double.parseDouble(exp[i]) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, float[] act) {
@@ -115,8 +103,6 @@
if(Float.parseFloat(exp[i]) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, long[] act) {
@@ -126,8 +112,6 @@
if(Long.parseLong(exp[i]) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, short[] act) {
@@ -137,8 +121,6 @@
if(Short.parseShort(exp[i]) != act[i])
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Boolean[] act) {
@@ -152,8 +134,6 @@
else if(Boolean.valueOf(exp[i]).booleanValue() != act[i].booleanValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Byte[] act) {
@@ -167,8 +147,6 @@
else if(Byte.valueOf(exp[i]).byteValue() != act[i].byteValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Integer[] act) {
@@ -178,8 +156,6 @@
if(Integer.parseInt(exp[i]) != act[i].intValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Character[] act) {
@@ -189,8 +165,6 @@
if(exp[i].charAt(0) != act[i].charValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Double[] act) {
@@ -200,8 +174,6 @@
if(Double.parseDouble(exp[i]) != act[i].doubleValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Float[] act) {
@@ -211,8 +183,6 @@
if(Float.parseFloat(exp[i]) != act[i].floatValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Long[] act) {
@@ -222,8 +192,6 @@
if(Long.parseLong(exp[i]) != act[i].longValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
public static void assertEquals(String[] exp, Short[] act) {
@@ -233,8 +201,6 @@
if(Long.parseLong(exp[i]) != act[i].shortValue())
throw new AssertionFailedError("The values expected[" + i + "]=" + exp[i] + " does not equal actual[" + i + "]=" + act[i]);
}
-
- return;
}
private static void checkArrays(Object exp, Object act) {
@@ -245,10 +211,19 @@
else if(exp == null && act != null)
throw new AssertionFailedError("The actual array is non-null and the expected array is null.");
- assert exp.getClass().isArray() == true;
- assert act.getClass().isArray() == true;
+ if(!exp.getClass().isArray())
+ throw new AssertionFailedError("The expected type should be an array but is \"" + exp.getClass().getName());
+ if(!act.getClass().isArray())
+ throw new AssertionFailedError("The actual type should be an array but is \"" + act.getClass().getName());
if(Array.getLength(exp) != Array.getLength(act))
throw new AssertionFailedError("The actual and expected value arrays are not of equal length");
+ }
+
+ private static void compareArrays(Object[] exp, Object[] act) {
+ for(int i = 0; i < exp.length; i++) {
+ if(!exp[i].equals(act[i]))
+ throw new AssertionFailedError("The values expected[" + i + "]=\"" + exp[i] + "\" does not equal actual[" + i + "]=\"" + act[i] + "\"");
+ }
}
}
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/ConfigBeanTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/ConfigBeanTest.java?rev=385838&r1=385837&r2=385838&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/ConfigBeanTest.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/ConfigBeanTest.java Tue Mar 14 09:17:31 2006
@@ -1,4 +1,4 @@
-/**
+/*
Copyright 2004 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,7 @@
import org.apache.beehive.netui.util.config.parser.NetUIConfigParser;
import org.apache.beehive.netui.util.config.bean.NetUIConfig;
import org.apache.beehive.netui.util.config.bean.DocType;
+import org.apache.beehive.netui.util.config.bean.IdJavascript;
import org.apache.beehive.netui.util.xml.XmlInputStreamResolver;
/**
@@ -33,35 +34,103 @@
public class ConfigBeanTest
extends TestCase {
+ /**
+ * Test to ensure that the ConfigUtil only allows configuration of the webapp to be performed once.
+ *
+ * @throws Exception
+ */
public void testConfigUtil()
throws Exception {
XmlInputStreamResolver xmlResolver = new TestXmlInputStreamResolver("WEB-INF/beehive-netui-config.xml");
- ConfigUtil.init(xmlResolver);
+ /*
+ Just ensure that some configuration is loaded.
+ */
+ if(!ConfigUtil.isInit())
+ ConfigUtil.init(xmlResolver);
NetUIConfig config = ConfigUtil.getConfig();
assertNotNull(config);
assertFalse(config.getPageFlowConfig().isEnableSelfNesting());
assertTrue(config.getJspTagConfig().getDocType() == DocType.HTML4_LOOSE_QUIRKS);
+
+ boolean caughtException = false;
+ try {
+ ConfigUtil.init(xmlResolver);
+ }
+ catch(Exception e) {
+ if(e instanceof ConfigInitializationException)
+ caughtException = true;
+ }
+
+ assertTrue(caughtException);
}
public void testValidationFailure()
throws Exception {
- Throwable failureCause = null;
+ boolean caughtException = false;
try {
- loadConfigBean("org/apache/beehive/netui/test/util/config/instances/beehive-netui-config-fail-validation.xml");
+ parseNetUIConfig("org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-fail-validation.xml");
}
catch(Throwable e) {
- /* assume that a ConfigInitializationException resulted from a failure in XML validation */
+ /* assumes that a ConfigInitializationException resulted from a failure in XML validation */
if(e instanceof ConfigInitializationException)
- return;
- else failureCause = e;
+ caughtException = true;
}
+ assertTrue(caughtException);
+ }
+
+ public void testParsing()
+ throws Exception {
+ String resourcePath = "org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-default.xml";
+
+ NetUIConfig config = parseNetUIConfig(resourcePath);
+
+ assertNotNull(config);
+ assertNotNull(config.getJspTagConfig());
+
+ assertTrue(config.getJspTagConfig().getDocType() == DocType.HTML4_LOOSE_QUIRKS);
+ assertTrue(config.getJspTagConfig().getIdJavascript() == IdJavascript.DEFAULT);
+ assertNull(config.getJspTagConfig().getTreeImageLocation());
+
+ assertNotNull(config.getTypeConverters());
+ assertTrue(config.getTypeConverters().length > 0);
+ assertEquals("org.foo.FooBean", config.getTypeConverters()[0].getType());
+ assertEquals("org.foo.FooBeanConverter", config.getTypeConverters()[0].getConverterClass());
+ }
+
+ public void testParsingWithChain()
+ throws Exception {
+ String resourcePath = "org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-with-chain.xml";
+
+ NetUIConfig config = parseNetUIConfig(resourcePath);
+
+ assertNotNull(config);
+ assertNotNull(config.getJspTagConfig());
+
+ assertTrue(config.getJspTagConfig().getDocType() == DocType.HTML4_LOOSE_QUIRKS);
+ assertTrue(config.getJspTagConfig().getIdJavascript() == IdJavascript.DEFAULT);
+ assertNull(config.getJspTagConfig().getTreeImageLocation());
+
+ assertNotNull(config.getTypeConverters());
+ assertTrue(config.getTypeConverters().length > 0);
+ assertEquals("org.foo.FooBean", config.getTypeConverters()[0].getType());
+ assertEquals("org.foo.FooBeanConverter", config.getTypeConverters()[0].getConverterClass());
+ }
+
+ public void testParsingPageFlowConfig()
+ throws Exception {
+ String resourcePath = "org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-pageflowConfig.xml";
+
+ NetUIConfig netuiConfig = parseNetUIConfig(resourcePath);
+
+ assertEquals(314, netuiConfig.getPageFlowConfig().getMaxForwardsPerRequest());
+ assertEquals(10, netuiConfig.getPageFlowConfig().getMaxNestingStackDepth());
+ assertFalse(netuiConfig.getPageFlowConfig().isEnableSelfNesting());
- throw new IllegalStateException("Expected validation failure but did not receive one", failureCause);
}
- private NetUIConfig loadConfigBean(String resourcePath)
+ private NetUIConfig parseNetUIConfig(String resourcePath)
throws Exception {
XmlInputStreamResolver xmlResolver = new TestXmlInputStreamResolver(resourcePath);
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/SchemaValidationTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/SchemaValidationTest.java?rev=385838&r1=385837&r2=385838&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/SchemaValidationTest.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/SchemaValidationTest.java Tue Mar 14 09:17:31 2006
@@ -26,7 +26,6 @@
import junit.framework.TestCase;
import org.apache.beehive.netui.util.xml.XmlInputStreamResolver;
-import org.apache.beehive.netui.util.config.ConfigInitializationException;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;
import org.xml.sax.EntityResolver;
@@ -45,7 +44,7 @@
new TestXmlInputStreamResolver("org/apache/beehive/netui/util/config/schema/beehive-netui-config.xsd");
XmlInputStreamResolver xmlInputStreamResolver =
- new TestXmlInputStreamResolver("org/apache/beehive/netui/test/util/config/instances/beehive-netui-config-default.xml");
+ new TestXmlInputStreamResolver("org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-default.xml");
InputStream xsdIs = xsdInputStreamResolver.getInputStream();
InputStream xmlIs = xmlInputStreamResolver.getInputStream();
@@ -68,7 +67,7 @@
new TestXmlInputStreamResolver("org/apache/beehive/netui/util/config/schema/beehive-netui-config.xsd");
XmlInputStreamResolver xmlInputStreamResolver =
- new TestXmlInputStreamResolver("org/apache/beehive/netui/test/util/config/instances/invalid-beehive-netui-config-default.xml");
+ new TestXmlInputStreamResolver("org/apache/beehive/netui/test/util/config/xmls/invalid-beehive-netui-config-default.xml");
InputStream xsdIs = xsdInputStreamResolver.getInputStream();
InputStream xmlIs = xmlInputStreamResolver.getInputStream();
Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java?rev=385838&r1=385837&r2=385838&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java Tue Mar 14 09:17:31 2006
@@ -32,18 +32,13 @@
private static final String DEFAULT_CONFIG = "WEB-INF/beehive-netui-config.xml";
public static void testInit() {
-
- InputStream is = null;
try {
- XmlInputStreamResolver xmlResolver = new TestXmlInputStreamResolver(DEFAULT_CONFIG);
- internalInit(null); //xmlResolver);
+ internalInit(null);
} catch(ConfigInitializationException cie) {
/*
sometimes bad form to do this, but in the default case for testing,
- it's convenient to just bail with a runtime exception to just
- fail the test
+ it's convenient to just bail with a runtime exception to just fail the test
*/
-
throw new IllegalStateException("Caught exception initializing the default config file \"" + DEFAULT_CONFIG + "\"", cie);
}
}
Added: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-with-chain.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-with-chain.xml?rev=385838&view=auto
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-with-chain.xml (added)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/xmls/beehive-netui-config-with-chain.xml Tue Mar 14 09:17:31 2006
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<netui-config xmlns="http://beehive.apache.org/netui/2004/server/config">
+
+ <expression-languages>
+ <default-language>netuiel</default-language>
+ <expression-language>
+ <name>netuiel</name>
+ <factory-class>org.apache.beehive.netui.script.el.ExpressionEvaluatorImpl$NetUIELEngineFactory</factory-class>
+ </expression-language>
+ </expression-languages>
+
+ <type-converters>
+ <type-converter>
+ <type>org.foo.FooBean</type>
+ <converter-class>org.foo.FooBeanConverter</converter-class>
+ </type-converter>
+ </type-converters>
+
+ <request-interceptors>
+ <global>
+ <request-interceptor>
+ <interceptor-class>org.apache.beehive.netui.tags.tree.TreeCRI</interceptor-class>
+ </request-interceptor>
+ <request-interceptor>
+ <interceptor-class>org.apache.beehive.netui.tags.divpanel.DivPanelCRI</interceptor-class>
+ </request-interceptor>
+ </global>
+ </request-interceptors>
+
+ <prefix-handlers>
+ <prefix-handler>
+ <name>checkbox_key</name>
+ <handler-class>org.apache.beehive.netui.tags.html.CheckBox$CheckBoxPrefixHandler</handler-class>
+ </prefix-handler>
+ <prefix-handler>
+ <name>checkbox_group_key</name>
+ <handler-class>org.apache.beehive.netui.tags.html.CheckBoxGroup$CheckboxGroupPrefixHandler</handler-class>
+ </prefix-handler>
+ <prefix-handler>
+ <name>radio_button_group_key</name>
+ <handler-class>org.apache.beehive.netui.tags.html.RadioButtonGroup$RadioButtonGroupPrefixHandler</handler-class>
+ </prefix-handler>
+ <prefix-handler>
+ <name>select_key</name>
+ <handler-class>org.apache.beehive.netui.tags.html.Select$SelectPrefixHandler</handler-class>
+ </prefix-handler>
+ </prefix-handlers>
+
+ <catalog>
+ <chain name="xhr-servlet">
+ <command id="1" classname="Foobar"/>
+ <command id="2" classname="Raboof"/>
+ </chain>
+ </catalog>
+
+</netui-config>
+