hlship 2003/08/06 13:52:07 Modified: hivemind/src/test/hivemind/test/rules TestClassTranslator.java hivemind/src/test/hivemind/test/parse TestDescriptorParser.java hivemind/src/java/org/apache/commons/hivemind/parse DescriptorParser.java hivemind/src/test/hivemind/test HiveMindSuite.java Added: hivemind/src/test/hivemind/test/rules InvokeFailure.xml WrongType.xml TestInvokeParentRule.java hivemind/src/test/hivemind/test/parse BadElement.xml MissingAttribute.xml BadAttribute.xml Log: Extend the test suite, fill in some minor gaps; fix a minor error in DescriptorParser when reporting errors inside <schema>. Revision Changes Path 1.3 +15 -1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestClassTranslator.java Index: TestClassTranslator.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestClassTranslator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestClassTranslator.java 5 Aug 2003 17:16:29 -0000 1.2 +++ TestClassTranslator.java 6 Aug 2003 20:52:07 -0000 1.3 @@ -59,9 +59,11 @@ import hivemind.test.HiveMindTestCase; +import org.apache.commons.hivemind.Registry; import org.apache.commons.hivemind.impl.ElementImpl; import org.apache.commons.hivemind.schema.SchemaProcessor; import org.apache.commons.hivemind.schema.rules.ClassTranslator; +import org.apache.commons.hivemind.schema.rules.RuleUtils; import org.apache.tapestry.ILocation; import org.apache.tapestry.Location; import org.apache.tapestry.spec.BaseLocatable; @@ -125,4 +127,16 @@ } + public void testWrongType() throws Exception + { + Registry r = buildRegistry("WrongType.xml"); + + interceptLogging(); + + r.getExtensionPointElements("hivemind.test.rules.WrongType"); + + checkLoggingEvent( + RuleUtils.class.getName(), + "Unable to set property value of [EMAIL PROTECTED] to {} \\(at datum/value\\): "); + } } 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/InvokeFailure.xml Index: InvokeFailure.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <!-- $Id: InvokeFailure.xml,v 1.1 2003/08/06 20:52:07 hlship Exp $ --> <module id="hivemind.test.rules" version="1.0.0"> <extension-point id="InvokeFailure"> <schema> <element name="datum"> <attribute name="key" required="true"/> <attribute name="value" required="true"/> <rules> <create-object class="hivemind.test.config.impl.Datum"/> <read-attribute property="key" attribute="key"/> <read-attribute property="value" attribute="value"/> <invoke-parent method="failure"/> </rules> </element> </schema> </extension-point> <extension point-id="InvokeFailure"> <datum key="key1" value="value1"/> <datum key="key2" value="value2"/> </extension> </module> 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/WrongType.xml Index: WrongType.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <!-- $Id: WrongType.xml,v 1.1 2003/08/06 20:52:07 hlship Exp $ --> <module id="hivemind.test.rules" version="1.0.0"> <extension-point id="WrongType"> <schema> <element name="datum"> <rules> <create-object class="hivemind.test.config.impl.Datum"/> <invoke-parent method="addElement"/> </rules> <element name="key"> <rules> <read-content property="key"/> </rules> </element> <element name="value"> <rules> <read-content property="value" translator="class"/> </rules> </element> </element> </schema> </extension-point> <extension point-id="WrongType"> <datum> <key>key</key> <value>java.util.HashMap</value> </datum> </extension> </module> 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/rules/TestInvokeParentRule.java Index: TestInvokeParentRule.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package hivemind.test.rules; import hivemind.test.HiveMindTestCase; import org.apache.commons.hivemind.Registry; import org.apache.commons.hivemind.schema.rules.InvokeParentRule; import org.apache.tapestry.ApplicationRuntimeException; public class TestInvokeParentRule extends HiveMindTestCase { public TestInvokeParentRule(String name) { super(name); } public void testInvokeFailure() throws Exception { Registry r = buildRegistry("InvokeFailure.xml"); try { r.getExtensionPointElements("hivemind.test.rules.InvokeFailure"); unreachable(); } catch (ApplicationRuntimeException ex) { checkException( ex, "Unable to construct configuration hivemind.test.rules.InvokeFailure: Error invoking method failure on org.apache.commons.hivemind.impl.SchemaProcessorImpl"); Throwable inner = findNestedException(ex); checkException( inner, "No such accessible method: failure() on object: org.apache.commons.hivemind.impl.SchemaProcessorImpl"); } } public void testGetMethod() { InvokeParentRule r = new InvokeParentRule(); r.setMethodName("foo"); assertEquals("foo", r.getMethodName()); } } 1.18 +70 -24 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java Index: TestDescriptorParser.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- TestDescriptorParser.java 1 Aug 2003 19:05:24 -0000 1.17 +++ TestDescriptorParser.java 6 Aug 2003 20:52:07 -0000 1.18 @@ -69,6 +69,7 @@ import org.apache.commons.hivemind.Element; import org.apache.commons.hivemind.Occurances; import org.apache.commons.hivemind.parse.CreateInstanceDescriptor; +import org.apache.commons.hivemind.parse.DescriptorParser; import org.apache.commons.hivemind.parse.ExtendServiceDescriptor; import org.apache.commons.hivemind.parse.ExtensionDescriptor; import org.apache.commons.hivemind.parse.ExtensionPointDescriptor; @@ -82,6 +83,7 @@ import org.apache.commons.hivemind.schema.rules.CreateObjectRule; import org.apache.commons.hivemind.schema.rules.ReadAttributeRule; import org.apache.commons.hivemind.schema.rules.ReadContentRule; +import org.apache.tapestry.ApplicationRuntimeException; /** * Tests for parsing a HiveModule descriptor into a @@ -241,7 +243,7 @@ ModuleDescriptor md = parse("GenericModule.xml"); Schema schema = md.getExtensionPoint("MyExtensionPoint").getSchema(); - assertNotNull(schema.getLocation()); + assertNotNull(schema.getLocation()); List l = schema.getElementModel(); assertEquals(2, l.size()); @@ -260,7 +262,7 @@ am = (AttributeModel) al.get(1); assertEquals("biff", am.getName()); - + em = (ElementModel) l.get(1); assertEquals("foo2", em.getElementName()); @@ -305,31 +307,75 @@ assertEquals("addElement", rule4.getMethodName()); } - + public void testParametersSchema() throws Exception { - ModuleDescriptor md = parse("GenericModule.xml"); - Schema schema = md.getService("MyServiceFactory").getParametersSchema(); - - assertNotNull(schema); - - assertNotNull(schema.getLocation()); - List l = schema.getElementModel(); - - assertEquals(1, l.size()); - - ElementModel em = (ElementModel)l.get(0); - - assertEquals("myParameter", em.getElementName()); + ModuleDescriptor md = parse("GenericModule.xml"); + Schema schema = md.getService("MyServiceFactory").getParametersSchema(); + + assertNotNull(schema); + + assertNotNull(schema.getLocation()); + List l = schema.getElementModel(); + + assertEquals(1, l.size()); + + ElementModel em = (ElementModel) l.get(0); + + assertEquals("myParameter", em.getElementName()); } - + public void testSchemaRef() throws Exception { - ModuleDescriptor md = parse("SchemaRef.xml"); - - Schema schema1 = md.getExtensionPoint("One").getSchema(); - Schema schema2 = md.getExtensionPoint("Two").getSchema(); - - assertSame(schema1, schema2); + ModuleDescriptor md = parse("SchemaRef.xml"); + + Schema schema1 = md.getExtensionPoint("One").getSchema(); + Schema schema2 = md.getExtensionPoint("Two").getSchema(); + + assertSame(schema1, schema2); + } + + public void testBadElement() throws Exception + { + try + { + parse("BadElement.xml"); + + unreachable(); + } + catch (ApplicationRuntimeException ex) + { + checkException( + ex, + "Unexpected element bad-element within module/service/parameters-schema/element"); + } + } + + public void testBadAttribute() throws Exception + { + interceptLogging(); + + parse("BadAttribute.xml"); + + checkLoggingEvent( + DescriptorParser.class.getName(), + "Unknown attribute 'bad-attribute' in element module/extension-point/schema \\(at .*\\)"); + + } + + public void testMissingAttribute() throws Exception + { + try + { + parse("MissingAttribute.xml"); + + unreachable(); + } + catch (ApplicationRuntimeException ex) + { + checkException( + ex, + "Missing required attribute 'name' in element module/extension-point/schema/element"); + } } } 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/BadElement.xml Index: BadElement.xml =================================================================== <?xml version="1.0"?> <!-- $Id: BadElement.xml,v 1.1 2003/08/06 20:52:07 hlship Exp $ --> <module id="hivemind.test.parse" version="1.0.0"> <description>Description of the Module.</description> <extension-point id="MyExtensionPoint" occurs="1..n"> <description>Description of MyExtensionPoint.</description> <schema> <element name="foo1"> <description> Identifies a foo that will be fnorded. </description> <attribute name="bar" required="true"/> <attribute name="biff"> <description>Optional pointer to the biff glob thingey.</description> </attribute> <rules> <create-object class="package.Foo1"/> <read-attribute property="bazomatic" attribute="bar"/> <read-content property="description"/> <invoke-parent method="addElement"/> </rules> </element> <element name="foo2"> <description> The glomp that will be used during the fnord. </description> <attribute name="zip"/> <attribute name="fred"/> <rules> <create-object class="package.Foo2"/> <read-attribute property="zipId" attribute="zip"/> <read-attribute property="fred" attribute="fred"/> <set-parent property="container"/> <invoke-parent method="addChild"/> </rules> <element name="foo3"> <description> Optional element used to identify a glup that will be involed in the fnordification. </description> <attribute name="gnip"/> <rules> <create-object class="package.Foo3"/> <read-attribute property="gnipId" attribute="gnip"/> <invoke-parent method="addGnipHolder"/> </rules> </element> </element> </schema> </extension-point> <extension point-id="MyExtensionPoint"> <foo1 bar="baz"> foo1 content </foo1> <foo2 zip="zap" fred="barney"> <foo3 gnip="gnop"/> </foo2> </extension> <service id="MyService1" interface="package.MyService"> <description> Description of MyService1. </description> <create-instance class="package.impl.MyServiceImpl"/> <interceptor service-id="MyInterceptor" order="1000"/> <interceptor service-id="OtherInterceptor"/> </service> <extend-service service-id="othermodule.OtherService"> <interceptor service-id="MyInterceptor"/> </extend-service> <service id="MyServiceFactory" interface="org.apache.commons.hivemind.ServiceImplementationFactory"> <parameters-schema> <element name="myParameter"> <rules> <create-object class="package.impl.MyParameterHolder"/> <read-content property="parameterValue"/> <invoke-parent method="addElement"/> </rules> <bad-element/> </element> </parameters-schema> </service> </module> 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/MissingAttribute.xml Index: MissingAttribute.xml =================================================================== <?xml version="1.0"?> <!-- $Id: MissingAttribute.xml,v 1.1 2003/08/06 20:52:07 hlship Exp $ --> <module id="hivemind.test.parse" version="1.0.0"> <description>Description of the Module.</description> <extension-point id="MyExtensionPoint" occurs="1..n"> <description>Description of MyExtensionPoint.</description> <schema> <!-- should have name attribute --> <element> <description> Identifies a foo that will be fnorded. </description> <attribute name="bar" required="true"/> <attribute name="biff"> <description>Optional pointer to the biff glob thingey.</description> </attribute> <rules> <create-object class="package.Foo1"/> <read-attribute property="bazomatic" attribute="bar"/> <read-content property="description"/> <invoke-parent method="addElement"/> </rules> </element> <element name="foo2"> <description> The glomp that will be used during the fnord. </description> <attribute name="zip"/> <attribute name="fred"/> <rules> <create-object class="package.Foo2"/> <read-attribute property="zipId" attribute="zip"/> <read-attribute property="fred" attribute="fred"/> <set-parent property="container"/> <invoke-parent method="addChild"/> </rules> <element name="foo3"> <description> Optional element used to identify a glup that will be involed in the fnordification. </description> <attribute name="gnip"/> <rules> <create-object class="package.Foo3"/> <read-attribute property="gnipId" attribute="gnip"/> <invoke-parent method="addGnipHolder"/> </rules> </element> </element> </schema> </extension-point> <extension point-id="MyExtensionPoint"> <foo1 bar="baz"> foo1 content </foo1> <foo2 zip="zap" fred="barney"> <foo3 gnip="gnop"/> </foo2> </extension> <service id="MyService1" interface="package.MyService"> <description> Description of MyService1. </description> <create-instance class="package.impl.MyServiceImpl"/> <interceptor service-id="MyInterceptor" order="1000"/> <interceptor service-id="OtherInterceptor"/> </service> <extend-service service-id="othermodule.OtherService"> <interceptor service-id="MyInterceptor"/> </extend-service> <service id="MyServiceFactory" interface="org.apache.commons.hivemind.ServiceImplementationFactory"> <parameters-schema> <element name="myParameter"> <rules> <create-object class="package.impl.MyParameterHolder"/> <read-content property="parameterValue"/> <invoke-parent method="addElement"/> </rules> </element> </parameters-schema> </service> </module> 1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/BadAttribute.xml Index: BadAttribute.xml =================================================================== <?xml version="1.0"?> <!-- $Id: BadAttribute.xml,v 1.1 2003/08/06 20:52:07 hlship Exp $ --> <module id="hivemind.test.parse" version="1.0.0"> <description>Description of the Module.</description> <extension-point id="MyExtensionPoint" occurs="1..n"> <description>Description of MyExtensionPoint.</description> <schema bad-attribute="bad"> <element name="foo1"> <description> Identifies a foo that will be fnorded. </description> <attribute name="bar" required="true"/> <attribute name="biff"> <description>Optional pointer to the biff glob thingey.</description> </attribute> <rules> <create-object class="package.Foo1"/> <read-attribute property="bazomatic" attribute="bar"/> <read-content property="description"/> <invoke-parent method="addElement"/> </rules> </element> <element name="foo2"> <description> The glomp that will be used during the fnord. </description> <attribute name="zip"/> <attribute name="fred"/> <rules> <create-object class="package.Foo2"/> <read-attribute property="zipId" attribute="zip"/> <read-attribute property="fred" attribute="fred"/> <set-parent property="container"/> <invoke-parent method="addChild"/> </rules> <element name="foo3"> <description> Optional element used to identify a glup that will be involed in the fnordification. </description> <attribute name="gnip"/> <rules> <create-object class="package.Foo3"/> <read-attribute property="gnipId" attribute="gnip"/> <invoke-parent method="addGnipHolder"/> </rules> </element> </element> </schema> </extension-point> <extension point-id="MyExtensionPoint"> <foo1 bar="baz"> foo1 content </foo1> <foo2 zip="zap" fred="barney"> <foo3 gnip="gnop"/> </foo2> </extension> <service id="MyService1" interface="package.MyService"> <description> Description of MyService1. </description> <create-instance class="package.impl.MyServiceImpl"/> <interceptor service-id="MyInterceptor" order="1000"/> <interceptor service-id="OtherInterceptor"/> </service> <extend-service service-id="othermodule.OtherService"> <interceptor service-id="MyInterceptor"/> </extend-service> <service id="MyServiceFactory" interface="org.apache.commons.hivemind.ServiceImplementationFactory"> <parameters-schema> <element name="myParameter"> <rules> <create-object class="package.impl.MyParameterHolder"/> <read-content property="parameterValue"/> <invoke-parent method="addElement"/> </rules> </element> </parameters-schema> </service> </module> 1.22 +2 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java Index: DescriptorParser.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- DescriptorParser.java 5 Aug 2003 17:16:29 -0000 1.21 +++ DescriptorParser.java 6 Aug 2003 20:52:07 -0000 1.22 @@ -1087,7 +1087,7 @@ if (elementName.equals("element")) { - schema.addElementModel(enterStateElement("elementName")); + schema.addElementModel(enterStateElement(elementName)); return; } 1.12 +3 -1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java Index: HiveMindSuite.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/HiveMindSuite.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- HiveMindSuite.java 5 Aug 2003 00:50:36 -0000 1.11 +++ HiveMindSuite.java 6 Aug 2003 20:52:07 -0000 1.12 @@ -105,6 +105,8 @@ suite.addTestSuite(TestConstructRegistry.class); suite.addTestSuite(TestExtensionPointTranslator.class); + + suite.addTestSuite(TestInvokeParentRule.class); return suite; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]