I'm still not really satisfied, since the only thing thats different between XmlConfigParserTestCase and XmlConfigParser2TestCase is the config location… I'm thinking about using a parameterized test. This will work as long the two config define exactly the same catalogs.
WDYT? Benedikt Am 13.06.2013 um 21:50 schrieb brit...@apache.org: > Author: britter > Date: Thu Jun 13 19:50:01 2013 > New Revision: 1492833 > > URL: http://svn.apache.org/r1492833 > Log: > Pull up common methods in abstract base class > > Added: > > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/AbstractXmlParserTest.java > Modified: > > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParser2TestCase.java > > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParserTestCase.java > > commons/proper/chain/trunk/configuration/xml/src/test/resources/org/apache/commons/chain2/config/xml/test-config.xml > > Added: > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/AbstractXmlParserTest.java > URL: > http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/AbstractXmlParserTest.java?rev=1492833&view=auto > ============================================================================== > --- > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/AbstractXmlParserTest.java > (added) > +++ > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/AbstractXmlParserTest.java > Thu Jun 13 19:50:01 2013 > @@ -0,0 +1,119 @@ > +/* > + * Licensed to the Apache Software Foundation (ASF) under one or more > + * contributor license agreements. See the NOTICE file distributed with > + * this work for additional information regarding copyright ownership. > + * The ASF licenses this file to You 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.commons.chain2.config.xml; > + > +import static org.junit.Assert.assertEquals; > +import static org.junit.Assert.assertNotNull; > + > +import java.net.URL; > +import java.util.Iterator; > + > +import org.apache.commons.chain2.Catalog; > +import org.apache.commons.chain2.CatalogFactory; > +import org.apache.commons.chain2.Context; > +import org.apache.commons.chain2.impl.CatalogBase; > +import org.apache.commons.chain2.impl.CatalogFactoryBase; > +import org.apache.commons.chain2.impl.ContextBase; > +import org.junit.After; > +import org.junit.Before; > + > +public abstract class AbstractXmlParserTest { > + > + // ------------------------------------------------------ Instance > Variables > + > + /** > + * <p>The <code>Catalog</code> to contain our configured commands.</p> > + */ > + protected Catalog<String, Object, Context<String, Object>> catalog = > null; > + > + /** > + * <p>The <code>Context</code> to use for execution tests.</p> > + */ > + protected Context<String, Object> context = null; > + > + /** > + * <p>The <code>ConfigParser</code> instance under test.</p> > + */ > + protected XmlConfigParser parser = null; > + > + > + // ---------------------------------------------------- Overall Test > Methods > + > + > + /** > + * Set up instance variables required by this test case. > + */ > + @Before > + public void setUp() { > + CatalogFactory.clear(); > + catalog = new CatalogBase<String, Object, Context<String, Object>>(); > + context = new ContextBase(); > + parser = new XmlConfigParser(); > + } > + > + > + /** > + * Tear down instance variables required by this test case. > + */ > + @After > + public void tearDown() { > + parser = null; > + context = null; > + catalog = null; > + } > + > + > + // --------------------------------------------------------- Private > Methods > + > + > + // Verify the number of configured commands > + protected void checkCommandCount(int expected) { > + int n = 0; > + Iterator<String> names = catalog.getNames(); > + while (names.hasNext()) { > + String name = names.next(); > + n++; > + assertNotNull(name + " exists", catalog.getCommand(name)); > + } > + assertEquals("Correct command count", expected, n); > + } > + > + // Verify the contents of the execution log > + protected void checkExecuteLog(String expected) { > + StringBuilder log = (StringBuilder) context.get("log"); > + assertNotNull("Context returned log", log); > + assertEquals("Context returned correct log", > + expected, log.toString()); > + } > + > + // Load the specified catalog from the specified resource path > + protected void load(String path) throws Exception { > + URL url = getClass().getResource(path); > + > + if (url == null) { > + String msg = String.format("Can't find resource for path: %s", > path); > + throw new IllegalArgumentException(msg); > + } > + > + parser.parse(url); > + CatalogFactory<String, Object, Context<String, Object>> > catalogFactory > + = CatalogFactoryBase.getInstance(); > + catalog = catalogFactory.getCatalog("foo"); > + } > + > +} > > Modified: > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParser2TestCase.java > URL: > http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParser2TestCase.java?rev=1492833&r1=1492832&r2=1492833&view=diff > ============================================================================== > --- > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParser2TestCase.java > (original) > +++ > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParser2TestCase.java > Thu Jun 13 19:50:01 2013 > @@ -50,58 +50,13 @@ import org.junit.Test; > * for the commands and chains used in the test.</p> > */ > > -public class XmlConfigParser2TestCase { > +public class XmlConfigParser2TestCase extends AbstractXmlParserTest { > > > private static final String DEFAULT_XML = > "/org/apache/commons/chain2/config/xml/test-config-2.xml"; > > > - // ------------------------------------------------------ Instance > Variables > - > - > - /** > - * <p>The <code>Catalog</code> to contain our configured commands.</p> > - */ > - protected Catalog<String, Object, Context<String, Object>> catalog = > null; > - > - > - /** > - * <p>The <code>Context</code> to use for execution tests.</p> > - */ > - protected Context<String, Object> context = null; > - > - > - /** > - * <p>The <code>ConfigParser</code> instance under test.</p> > - */ > - protected XmlConfigParser parser = null; > - > - > - // ---------------------------------------------------- Overall Test > Methods > - > - > - /** > - * Set up instance variables required by this test case. > - */ > - @Before > - public void setUp() { > - catalog = new CatalogBase<String, Object, Context<String, Object>>(); > - context = new ContextBase(); > - parser = new XmlConfigParser(); > - } > - > - > - /** > - * Tear down instance variables required by this test case. > - */ > - @After > - public void tearDown() { > - parser = null; > - context = null; > - catalog = null; > - } > - > > // ------------------------------------------------ Individual Test > Methods > > @@ -313,38 +268,4 @@ public class XmlConfigParser2TestCase { > } > > > - // --------------------------------------------------------- Private > Methods > - > - > - // Verify the number of configured commands > - protected void checkCommandCount(int expected) { > - int n = 0; > - Iterator<String> names = catalog.getNames(); > - while (names.hasNext()) { > - String name = names.next(); > - n++; > - assertNotNull(name + " exists", catalog.getCommand(name)); > - } > - assertEquals("Correct command count", expected, n); > - } > - > - > - // Verify the contents of the execution log > - protected void checkExecuteLog(String expected) { > - StringBuilder log = (StringBuilder) context.get("log"); > - assertNotNull("Context returned log", log); > - assertEquals("Context returned correct log", > - expected, log.toString()); > - } > - > - > - // Load the specified catalog from the specified resource path > - protected void load(String path) throws Exception { > - parser.parse(getClass().getResource(path)); > - CatalogFactory<String, Object, Context<String, Object>> > catalogFactory > - = CatalogFactoryBase.getInstance(); > - catalog = catalogFactory.getCatalog("foo"); > - } > - > - > } > > Modified: > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParserTestCase.java > URL: > http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParserTestCase.java?rev=1492833&r1=1492832&r2=1492833&view=diff > ============================================================================== > --- > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParserTestCase.java > (original) > +++ > commons/proper/chain/trunk/configuration/xml/src/test/java/org/apache/commons/chain2/config/xml/XmlConfigParserTestCase.java > Thu Jun 13 19:50:01 2013 > @@ -49,60 +49,13 @@ import org.junit.Test; > * <p>Test Case for > <code>org.apache.commons.chain2.config.ConfigParser</code>.</p> > */ > > -public class XmlConfigParserTestCase { > +public class XmlConfigParserTestCase extends AbstractXmlParserTest { > > > private static final String DEFAULT_XML = > "/org/apache/commons/chain2/config/xml/test-config.xml"; > > > - // ------------------------------------------------------ Instance > Variables > - > - > - /** > - * <p>The <code>Catalog</code> to contain our configured commands.</p> > - */ > - protected Catalog<String, Object, Context<String, Object>> catalog = > null; > - > - > - /** > - * <p>The <code>Context</code> to use for execution tests.</p> > - */ > - protected Context<String, Object> context = null; > - > - > - /** > - * <p>The <code>ConfigParser</code> instance under test.</p> > - */ > - protected XmlConfigParser parser = null; > - > - > - // ---------------------------------------------------- Overall Test > Methods > - > - > - /** > - * Set up instance variables required by this test case. > - */ > - @Before > - public void setUp() { > - CatalogFactory.clear(); > - catalog = new CatalogBase<String, Object, Context<String, Object>>(); > - context = new ContextBase(); > - parser = new XmlConfigParser(); > - } > - > - > - /** > - * Tear down instance variables required by this test case. > - */ > - @After > - public void tearDown() { > - parser = null; > - context = null; > - catalog = null; > - } > - > - > // ------------------------------------------------ Individual Test > Methods > > > @@ -313,45 +266,4 @@ public class XmlConfigParserTestCase { > } > > > - // --------------------------------------------------------- Private > Methods > - > - > - // Verify the number of configured commands > - protected void checkCommandCount(int expected) { > - int n = 0; > - Iterator<String> names = catalog.getNames(); > - while (names.hasNext()) { > - String name = names.next(); > - n++; > - assertNotNull(name + " exists", catalog.getCommand(name)); > - } > - assertEquals("Correct command count", expected, n); > - } > - > - > - // Verify the contents of the execution log > - protected void checkExecuteLog(String expected) { > - StringBuilder log = (StringBuilder) context.get("log"); > - assertNotNull("Context returned log", log); > - assertEquals("Context returned correct log", > - expected, log.toString()); > - } > - > - > - // Load the specified catalog from the specified resource path > - protected void load(String path) throws Exception { > - URL url = getClass().getResource(path); > - > - if (url == null) { > - String msg = String.format("Can't find resource for path: %s", > path); > - throw new IllegalArgumentException(msg); > - } > - > - parser.parse(url); > - CatalogFactory<String, Object, Context<String, Object>> > catalogFactory > - = CatalogFactoryBase.getInstance(); > - catalog = catalogFactory.getCatalog(); > - } > - > - > } > > Modified: > commons/proper/chain/trunk/configuration/xml/src/test/resources/org/apache/commons/chain2/config/xml/test-config.xml > URL: > http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/xml/src/test/resources/org/apache/commons/chain2/config/xml/test-config.xml?rev=1492833&r1=1492832&r2=1492833&view=diff > ============================================================================== > --- > commons/proper/chain/trunk/configuration/xml/src/test/resources/org/apache/commons/chain2/config/xml/test-config.xml > (original) > +++ > commons/proper/chain/trunk/configuration/xml/src/test/resources/org/apache/commons/chain2/config/xml/test-config.xml > Thu Jun 13 19:50:01 2013 > @@ -14,7 +14,7 @@ > See the License for the specific language governing permissions and > limitations under the License. > --> > -<catalog> > +<catalog name="foo"> > > <!-- Single command "chains" from CatalogBaseTestCase --> > <command name="AddingCommand" > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org