You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2014/08/06 00:56:11 UTC
svn commit: r1616039 - in /myfaces/trinidad/trunk: ./
trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java
trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
Author: bsullivan
Date: Tue Aug 5 22:56:10 2014
New Revision: 1616039
URL: http://svn.apache.org/r1616039
Log:
Trinidad-2503 Extend testing improvements in 2501 and 2502 to RenderKit subclasses
Allow RenderKitTestCase subclasses to use the improvements in Trinidad-2501 and Trindiad-2502 by moving the utility functions from CoreRenderKitTest to RenderKitTestCase
Modified:
myfaces/trinidad/trunk/ (props changed)
myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java
myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
Propchange: myfaces/trinidad/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Aug 5 22:56:10 2014
@@ -24,3 +24,5 @@ relative mtr2 - jetty on demo.app
trin2493_2.1.diff
trinTrunk2.jws
trin-2501-2_1_1.patch
+trin-2502.patch
+Trin-2503.patch
Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java?rev=1616039&r1=1616038&r2=1616039&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/CoreRenderKitTest.java Tue Aug 5 22:56:10 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -40,57 +39,56 @@ import org.apache.myfaces.trinidad.compo
import org.apache.myfaces.trinidad.component.core.CoreForm;
import org.apache.myfaces.trinidad.component.html.HtmlHtml;
import org.apache.myfaces.trinidad.context.RequestContext;
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.render.RenderUtils;
-import org.apache.myfaces.trinidadinternal.renderkit.RenderKitTestCase.RendererTest;
-import org.apache.myfaces.trinidadinternal.renderkit.RenderKitTestCase.SuiteDefinition;
import org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit;
import org.xml.sax.SAXException;
-
public class CoreRenderKitTest extends RenderKitTestCase
{
public static Test suite() throws Throwable
{
+ Set<String> allowedDefinitionNames = Collections.emptySet();
+ Set<String> allowedTestNames = Collections.emptySet();
+
+ return suite(allowedDefinitionNames, allowedTestNames);
+ }
+
+ public static Test suite(
+ Set<String> allowedDefinitionNames, Set<String> allowedTestNames) throws Throwable
+ {
+ List<SuiteDefinition> suiteDefinitions = filterDefinitions(allowedDefinitionNames, _DEFINITIONS);
+
CoreRenderKitTest suite =
- new CoreRenderKitTest(CoreRenderKitTest.class.getName());
+ new CoreRenderKitTest(CoreRenderKitTest.class.getName(), suiteDefinitions, allowedTestNames);
return suite;
}
/**
* To limit the set of allowed SuiteDefinition variants that the tests are run against,
- * pass the parameter:<code>definitions=<i><comma-delimited list of defintions><i></code>, such
- * as <code>definitions=minimal,minimalScrRdr</code>
+ * pass the parameter:
+ * <code>definitions=<i><comma-delimited list of definitions><i></code>, such
+ * as <code>definitions=minimal,minimalScrRdr</code>
* To limit the set test scripts run, pass the parameter
- * <code>tests=<i><comma-delimited list of test script names without .xml extension><i></code>,
- * such as <code>tests=inputText,media</code>
+ * <code>tests=<i><comma-delimited list of test script names without .xml extension><i></code>,
+ * such as <code>tests=inputText,media</code>
* @param args
* @throws Throwable
*/
public static void main(String[] args) throws Throwable
{
- _parseAllowedDefinitions(args);
- _parseAllowedTests(args);
+ Set<String> allowedDefinitionNames = parseAllowedDefinitionNames(args);
+ Set<String> allowedTestNames = parseAllowedTestNames(args);
- junit.textui.TestRunner.run(suite());
- }
-
- public CoreRenderKitTest(String testName) throws IOException, SAXException
- {
- super(testName);
+ junit.textui.TestRunner.run(suite(allowedDefinitionNames, allowedTestNames));
}
- @Override
- protected List<SuiteDefinition> getSuiteDefinitions()
+ public CoreRenderKitTest(
+ String testName, List<SuiteDefinition> suiteDefinitions, Set<String> allowedTestNames)
+ throws IOException, SAXException
{
- if (_definitions == null)
- {
- _definitions = _filterDefinitions();
- }
-
- return _definitions;
+ super(testName, suiteDefinitions, allowedTestNames);
}
@Override
@@ -133,109 +131,10 @@ public class CoreRenderKitTest extends R
return form;
}
}
-
- /**
- * Override to filter which component tests to add
- * @param name
- * @param definition
- * @param lenient
- * @throws IOException
- * @throws SAXException
- */
- @Override
- protected void addRendererTest(
- String name,
- SuiteDefinition definition,
- boolean lenient) throws IOException, SAXException
- {
- if (_ALLOWED_TEST_NAMES.isEmpty() || _ALLOWED_TEST_NAMES.contains(name))
- {
- super.addRendererTest(name, definition, lenient);
- }
- else
- {
- _LOG.info("Suppress running RenderKitTest:" + name + " " + definition.getCategory());
- }
- }
- private static List<String> _parseListParameter(String[] args, String parameterPrefix)
- {
- for (String arg : args)
- {
- if (arg.startsWith(parameterPrefix))
- {
- String definitionsString = arg.substring(parameterPrefix.length());
- return Arrays.asList(definitionsString.split(","));
- }
- }
-
- return Collections.emptyList();
- }
-
- private static void _parseAllowedDefinitions(String[] args)
- {
- _ALLOWED_DEFINITIONS_CATEGORIES.addAll(_parseListParameter(args, "definitions="));
- }
-
- private static void _parseAllowedTests(String[] args)
- {
- _ALLOWED_TEST_NAMES.addAll(_parseListParameter(args, "tests="));
- }
-
- private static SuiteDefinition _getSuitedDefinitionByCategory(
- Iterable<SuiteDefinition> suitedDefinitions, String category)
- {
- for (SuiteDefinition def : suitedDefinitions)
- {
- if (category.equals(def.getCategory()))
- {
- return def;
- }
- }
-
- return null;
- }
-
- private static List<SuiteDefinition> _filterDefinitions()
- {
- if (_ALLOWED_DEFINITIONS_CATEGORIES.isEmpty())
- {
- return _DEFINITIONS;
- }
- else
- {
- ArrayList<SuiteDefinition> definitions = new ArrayList<SuiteDefinition>();
-
- for (String category : _ALLOWED_DEFINITIONS_CATEGORIES)
- {
- SuiteDefinition allowedDefinition = _getSuitedDefinitionByCategory(_DEFINITIONS, category);
-
- if (allowedDefinition != null)
- {
- definitions.add(allowedDefinition);
- }
- else
- {
- _LOG.warning("Unabled to find test category named:" + category);
- }
- }
-
- definitions.trimToSize();
- return Collections.unmodifiableList(definitions);
- }
- }
-
-
- private static final Set<String> _ALLOWED_TEST_NAMES = new HashSet<String>();
- private static final Set<String> _ALLOWED_DEFINITIONS_CATEGORIES = new HashSet<String>();
-
private static final List<SuiteDefinition> _DEFINITIONS;
private static final Set<String> _HTML_COMPONENTS;
-
- private static final Logger _LOG = Logger.getLogger(CoreRenderKitTest.class.getName());
- private List<SuiteDefinition> _definitions;
-
static
{
// Force the CoreRenderKit logger level to SEVERE, to bypass the
Modified: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java?rev=1616039&r1=1616038&r2=1616039&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/RenderKitTestCase.java Tue Aug 5 22:56:10 2014
@@ -26,6 +26,9 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -73,11 +76,14 @@ import org.xml.sax.SAXException;
abstract public class RenderKitTestCase extends TestSuite
{
-
- public RenderKitTestCase(String testName) throws IOException, SAXException
+ public RenderKitTestCase(
+ String testName, List<SuiteDefinition> suiteDefinitions, Set<String> allowedTestNames)
+ throws IOException, SAXException
{
super(testName);
+ Args.notNull(suiteDefinitions, "suiteDefinitions");
+
try
{
_initGlobal();
@@ -87,7 +93,98 @@ abstract public class RenderKitTestCase
e.printStackTrace();
}
- _initTests();
+ _initTests(suiteDefinitions, allowedTestNames);
+ }
+
+ /**
+ * Utility function for returning the subset of the availableDefinitions in availableDefinitions
+ * order, with categories named in the allowedDefinitionNames. If availableDefinitions is
+ * empty, no filtering is performed.
+ * @param allowedDefinitionNames
+ * @param availableDefinitions
+ * @return
+ */
+ protected static List<SuiteDefinition> filterDefinitions(
+ Set<String> allowedDefinitionNames, List<SuiteDefinition> availableDefinitions)
+ {
+ if (allowedDefinitionNames.isEmpty())
+ {
+ return availableDefinitions;
+ }
+ else
+ {
+ ArrayList<SuiteDefinition> definitions = new ArrayList<SuiteDefinition>();
+
+ for (String category : allowedDefinitionNames)
+ {
+ SuiteDefinition allowedDefinition = _getSuitedDefinitionByCategory(availableDefinitions, category);
+
+ if (allowedDefinition != null)
+ {
+ definitions.add(allowedDefinition);
+ }
+ else
+ {
+ _LOG.warning("Unabled to find test category named:" + category);
+ }
+ }
+
+ definitions.trimToSize();
+ return Collections.unmodifiableList(definitions);
+ }
+ }
+
+ private static SuiteDefinition _getSuitedDefinitionByCategory(
+ Iterable<SuiteDefinition> suitedDefinitions, String category)
+ {
+ for (SuiteDefinition def : suitedDefinitions)
+ {
+ if (category.equals(def.getCategory()))
+ {
+ return def;
+ }
+ }
+
+ return null;
+ }
+
+ protected static Set<String> parseAllowedDefinitionNames(String[] args)
+ {
+ List<String> allowedDefinitionNames = _parseListParameter(args, "definitions=");
+
+ return new HashSet<String>(allowedDefinitionNames);
+ }
+
+ protected static Set<String> parseAllowedTestNames(String[] args)
+ {
+ List<String> allowedTestNames = _parseListParameter(args, "tests=");
+
+ if (allowedTestNames.isEmpty())
+ {
+ // process the system property
+ String testNamesString = System.getProperty("trinidad.renderkit.script");
+
+ if (testNamesString != null)
+ {
+ allowedTestNames = Arrays.asList(testNamesString.split(","));
+ }
+ }
+
+ return new HashSet<String>(allowedTestNames);
+ }
+
+ private static List<String> _parseListParameter(String[] args, String parameterPrefix)
+ {
+ for (String arg : args)
+ {
+ if (arg.startsWith(parameterPrefix))
+ {
+ String definitionsString = arg.substring(parameterPrefix.length());
+ return Arrays.asList(definitionsString.split(","));
+ }
+ }
+
+ return Collections.emptyList();
}
protected void setUp() throws Exception
@@ -645,23 +742,11 @@ abstract public class RenderKitTestCase
_failureDir = new File(failures);
}
- private void _initTests() throws IOException, SAXException
+ private void _initTests(List<SuiteDefinition> suiteDefinitions, Set<String> allowedTestNames) throws IOException, SAXException
{
- String script = System.getProperty("trinidad.renderkit.script");
- Set<String> includedScripts = null;
- if (script != null)
- {
- String[] scripts = script.split(",");
- includedScripts = new HashSet<String>();
- for (int i = 0; i < scripts.length; i++)
- {
- _LOG.info("Including " + scripts[i]);
- includedScripts.add(scripts[i]);
- }
- }
-
// See if we want to run the full test suite (by default, no)
String fulltests = System.getProperty("trinidad.renderkit.fulltests");
+
// We can run the full test suite in two modes: strict, and lenient.
// We should go to "strict" all the time, but "lenient" simply
// diffs against the golden files
@@ -671,28 +756,42 @@ abstract public class RenderKitTestCase
for (int i = 0; i < scriptArray.length; i++)
{
String name = scriptArray[i];
- if ((includedScripts != null) && !includedScripts.contains(name))
- continue;
if (name.endsWith(".xml"))
{
- boolean first = true;
name = name.substring(0, name.length() - 4);
- for (SuiteDefinition definition : getSuiteDefinitions())
+
+ if (allowedTestNames.isEmpty() || allowedTestNames.contains(name))
{
- if (first)
- {
- addRendererTest(name, definition, false);
- first = false;
- }
- else
- {
- addRendererTest(name, definition, lenient);
- }
+ _addRendererTestsForSuites(suiteDefinitions, name, lenient);
+ }
+ else
+ {
+ _LOG.info("Suppress running RenderKitTest:" + name);
}
}
}
}
+
+ private void _addRendererTestsForSuites(
+ List<SuiteDefinition> suiteDefinitions, String name, boolean lenient)
+ throws IOException, SAXException
+ {
+ boolean first = true;
+
+ for (SuiteDefinition definition : suiteDefinitions)
+ {
+ boolean lenience = lenient;
+
+ if (first)
+ {
+ lenience = false;
+ first = false;
+ }
+
+ addRendererTest(name, definition, lenience);
+ }
+ }
protected void addRendererTest(
String name,
@@ -730,8 +829,6 @@ abstract public class RenderKitTestCase
UIViewRoot root,
TestScript script);
- protected abstract List<SuiteDefinition> getSuiteDefinitions();
-
protected abstract String getRenderKitId();
static public class SuiteDefinition