vgritsenko 2003/12/24 05:49:53
Modified: java/src/org/apache/xindice/util Configuration.java java/tests/src/org/apache/xindice/util ConfigurationTest.java Log: Improve configuration test Revision Changes Path 1.16 +7 -5 xml-xindice/java/src/org/apache/xindice/util/Configuration.java Index: Configuration.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/util/Configuration.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Configuration.java 13 Dec 2003 00:22:34 -0000 1.15 +++ Configuration.java 24 Dec 2003 13:49:53 -0000 1.16 @@ -185,7 +185,8 @@ */ public boolean getBooleanAttribute(String name, boolean defValue) { try { - return "[true][yes][1][y][on]".indexOf("[" + getAttribute(name, defValue ? "1" : "0").toLowerCase() + "]") != -1; + String attr = getAttribute(name, defValue ? "1" : "0").toLowerCase(); + return "[true][yes][1][y][on]".indexOf("[" + attr + "]") != -1; } catch (Exception e) { return defValue; } @@ -778,8 +779,9 @@ /** * add adds an existing Configuration node to this Configuration node. - * Note! This method does NOT perform a deep copy on the DOM Node that - * newConfig manages. + * + * <strong>NOTE:</strong> This method does NOT perform a deep copy on the + * DOM Node that newConfig manages. * * @param newConfig The Configuration node to add * @throws ReadOnlyException if the Configuration is read-only 1.4 +60 -20 xml-xindice/java/tests/src/org/apache/xindice/util/ConfigurationTest.java Index: ConfigurationTest.java =================================================================== RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/util/ConfigurationTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ConfigurationTest.java 7 Aug 2003 20:13:27 -0000 1.3 +++ ConfigurationTest.java 24 Dec 2003 13:49:53 -0000 1.4 @@ -70,32 +70,72 @@ * @version CVS $Revision$, $Date$ * @author Vladimir R. Bossicard <[EMAIL PROTECTED]> */ -public class ConfigurationTest - extends TestCase { +public class ConfigurationTest extends TestCase { - public void testDefaultConfiguration() - throws Exception { - Document doc = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION); - Configuration config = new Configuration(doc); + Document document; + + protected void setUp() throws Exception { + document = DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION); + } + + /** + * Test getName, getChild, getAttribute, etc + */ + public void testGet() throws Exception { + Configuration config = new Configuration(document); + assertEquals("xindice", config.getName()); config = config.getChild("root-collection", false); assertEquals("root-collection", config.getName()); - assertEquals("./db/", config.getAttribute("dbroot")); assertEquals("db", config.getAttribute("name")); + + assertEquals("", config.getAttribute("does-not-exist")); + assertEquals("some-default-value", config.getAttribute("does-not-exist", "some-default-value")); + assertEquals(false, config.getBooleanAttribute("does-not-exist")); + assertEquals(true, config.getBooleanAttribute("does-not-exist", true)); + + config = config.getChild("queryengine", false); + assertEquals("queryengine", config.getName()); + + Configuration[] children = config.getChildren(); + assertEquals(2, children.length); + assertEquals("resolver", children[0].getName()); + assertEquals("resolver", children[1].getName()); } - public void testSubConfigurations() - throws Exception { - String document = "<drivers><driver class=\"a\"/><driver class=\"b\"/></drivers>"; - Document doc = DOMParser.toDocument(document); - Configuration config = new Configuration(doc); - -/* FIXME Configuration[] confs = config.getChildren("driver"); - assertEquals(2, confs.length); - assertEquals("a", confs[0].getAttribute("class")); - assertEquals("b", confs[1].getAttribute("class")); - */ + public void testEditReadonly() throws Exception { + Configuration config = new Configuration(document); + try { + config.getChild("does-not-exist", true); + fail("ReadOnlyException expected"); + } catch (ReadOnlyException e) { + // Expected + } + + try { + config.add("does-not-exist"); + fail("ReadOnlyException expected"); + } catch (ReadOnlyException e) { + // Expected + } + + try { + config.setAttribute("does-not-exist", 7); + fail("ReadOnlyException expected"); + } catch (ReadOnlyException e) { + // Expected + } } + public void testEdit() throws Exception { + Configuration config = new Configuration(document, false); + + Configuration child = config.getChild("does-not-exist", true); + assertEquals("does-not-exist", child.getName()); + assertEquals("does-not-exist", config.getChild("does-not-exist").getName()); + + child.setAttribute("does-not-exist", 7); + assertEquals(7, child.getIntAttribute("does-not-exist")); + } }