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 2005/08/12 17:23:08 UTC
svn commit: r232310 [55/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestReplicationHelper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestReplicationHelper.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestReplicationHelper.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestReplicationHelper.java Fri Aug 12 08:12:28 2005
@@ -1,231 +1,231 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.tools.ant.Location;
-
-import org.apache.beehive.test.tools.tch.util.AntUtils;
-import org.apache.beehive.test.tools.tch.util.CollectionsUtil;
-
-/**
- * This is the infrastructure for classes that produce replication mechanisms
- * (command line, ant file ... )
- *
- */
-public class TestReplicationHelper
-{
- private boolean determinePropsForIndividualTests = true;
-
- private String buildfile = null;
-
- private Collection excludedProps = new HashSet();
-
- private Map tchProperties = new HashMap();
-
- private Map passedProperties = new HashMap();
- private Map testMap = new HashMap(1);
-
- private Collection processHandlers = null;
-
- public TestReplicationHelper(
- String buildfile,
- Map props,
- Collection inExcludedProps,
- Collection inProcessHandlers)
- {
- setBuildfile(buildfile);
- divideAndSetProperties(props);
- excludedProps = new HashSet(inExcludedProps);
- processHandlers = inProcessHandlers;
- }
-
- public TestReplicationHelper(
- Location location,
- Map propSnapshot,
- Map mostRecentProps,
- Collection inProcessHandlers)
- {
- init(propSnapshot, mostRecentProps);
- setBuildfile(location);
- processHandlers = inProcessHandlers;
- }
-
- private void init(Map propSnapshot, Map mostRecentProps)
- {
- Properties mostRecentPropsCopy = new Properties();
- mostRecentPropsCopy.putAll(mostRecentProps);
- updateProps(propSnapshot, mostRecentPropsCopy);
- divideAndSetProperties(propSnapshot);
- }
-
- public void addTest(String testName, Collection usedProps)
- {
- testMap.put(testName, usedProps);
- }
-
- public void addTestNames(Collection inTests)
- {
- for (Iterator iter = inTests.iterator(); iter.hasNext();)
- {
- addTest((String)iter.next(), new HashSet());
- }
- }
-
- public Collection getProcessHandlers()
- {
- return processHandlers;
- }
-
- private void setBuildfile(String s)
- {
- buildfile = s;
- }
-
- private void setBuildfile(Location location)
- {
- buildfile = AntUtils.getBuildfileName(location);
- }
-
- private void updateProps(Map props, Map mostRecentProps)
- {
- for (Iterator iter = mostRecentProps.entrySet().iterator();
- iter.hasNext();
- )
- {
- Map.Entry me = (Map.Entry)iter.next();
- String key = (String)me.getKey();
- String value = (String)me.getValue();
- if ((String)props.get(key) != null)
- if ((String)props.get(key) != value)
- props.put(key, value);
- }
- }
-
- private void divideAndSetProperties(Map props)
- {
- org.apache.beehive.test.tools.tch.util.DebugLogger.log(
- "**********Here are the props available: " + props);
- for (Iterator iter = props.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry me = (Map.Entry)iter.next();
- String key = (String)me.getKey();
- String value = (String)me.getValue();
- if (key.startsWith(CmdlineParams.SPECIAL_TCH_PROPERTY_PREFIX))
- {
- // only take it if it is not a property for which we want tight
- // control over its value (is forced)
- // and if the value does not match the declared default value
- if (!AntProperties.isForcedProp(key) && !AntProperties.isDefault(key, value))
- {
- tchProperties.put(key, value);
- }
- }
- else
- {
- passedProperties.put(key, value);
- }
- }
- }
-
- public void setDeterminePropsForIndividualTests(boolean b)
- {
- determinePropsForIndividualTests = b;
- }
-
- public Map resolveProperties()
- {
- Map propsToSet = new HashMap();
-
- // first add the props we always want set
- propsToSet.putAll(AntProperties.getNondefaultForcedValueProps());
-
- // if testMap is empty, means we are running all tests, so just return passedProperties
- if (testMap.isEmpty() || !determinePropsForIndividualTests)
- {
- propsToSet.putAll(passedProperties);
- }
- else
- {
- //Do the matching to only get the subset of properties needed
- for (Iterator iter = testMap.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry me = (Map.Entry)iter.next();
- for (Iterator iter2 = ((Collection)me.getValue()).iterator();
- iter2.hasNext();
- )
- {
- String propName = (String)iter2.next();
- if (!propsToSet.containsKey(propName))
- //if we didn't get to this property already in another test
- // or from the hardcoded props
- {
- if (passedProperties.containsKey(propName))
- //This means that the value *was* passed in
- {
- propsToSet.put(propName, passedProperties.get(propName));
- }
- }
- }
- }
- }
- return propsToSet;
- }
-
- public String getTestNamesValue()
- {
- StringBuffer sb = new StringBuffer();
- for (Iterator iter = testMap.keySet().iterator(); iter.hasNext();)
- {
- sb.append((String)iter.next());
- if (iter.hasNext())
- sb.append(CmdlineParams.TEST_NAMES_DELIMITER);
- }
- return sb.toString();
- }
-
- public Map getAllProperties()
- {
- Map props = resolveProperties();
- props.putAll(
- AntProperties.filterTchInternalProperties(tchProperties));
- props = AntProperties.sortProperties(props);
- return props;
- }
-
- public Map getAllProperties(Map specialProperties, Collection exclusions)
- {
- Collection allExcludedProps = new HashSet(excludedProps);
- allExcludedProps.addAll(exclusions);
- Map props = resolveProperties();
- props.putAll(
- AntProperties.filterTchInternalProperties(tchProperties));
- Map ret = new HashMap();
-
- CollectionsUtil.filterMapOnKey(props, allExcludedProps, ret, true);
- ret.putAll(specialProperties);
- ret = AntProperties.sortProperties(ret);
-
- return ret;
- }
-
- public void addAllProperties(
- StringBuffer sb,
- Map specialProperties,
- Collection exclusions)
- {
- AntUtils.appendProperties(
- sb,
- getAllProperties(specialProperties, exclusions));
- }
-
- public String getBuildfile()
- {
- return buildfile;
- }
-
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.tools.ant.Location;
+
+import org.apache.beehive.test.tools.tch.util.AntUtils;
+import org.apache.beehive.test.tools.tch.util.CollectionsUtil;
+
+/**
+ * This is the infrastructure for classes that produce replication mechanisms
+ * (command line, ant file ... )
+ *
+ */
+public class TestReplicationHelper
+{
+ private boolean determinePropsForIndividualTests = true;
+
+ private String buildfile = null;
+
+ private Collection excludedProps = new HashSet();
+
+ private Map tchProperties = new HashMap();
+
+ private Map passedProperties = new HashMap();
+ private Map testMap = new HashMap(1);
+
+ private Collection processHandlers = null;
+
+ public TestReplicationHelper(
+ String buildfile,
+ Map props,
+ Collection inExcludedProps,
+ Collection inProcessHandlers)
+ {
+ setBuildfile(buildfile);
+ divideAndSetProperties(props);
+ excludedProps = new HashSet(inExcludedProps);
+ processHandlers = inProcessHandlers;
+ }
+
+ public TestReplicationHelper(
+ Location location,
+ Map propSnapshot,
+ Map mostRecentProps,
+ Collection inProcessHandlers)
+ {
+ init(propSnapshot, mostRecentProps);
+ setBuildfile(location);
+ processHandlers = inProcessHandlers;
+ }
+
+ private void init(Map propSnapshot, Map mostRecentProps)
+ {
+ Properties mostRecentPropsCopy = new Properties();
+ mostRecentPropsCopy.putAll(mostRecentProps);
+ updateProps(propSnapshot, mostRecentPropsCopy);
+ divideAndSetProperties(propSnapshot);
+ }
+
+ public void addTest(String testName, Collection usedProps)
+ {
+ testMap.put(testName, usedProps);
+ }
+
+ public void addTestNames(Collection inTests)
+ {
+ for (Iterator iter = inTests.iterator(); iter.hasNext();)
+ {
+ addTest((String)iter.next(), new HashSet());
+ }
+ }
+
+ public Collection getProcessHandlers()
+ {
+ return processHandlers;
+ }
+
+ private void setBuildfile(String s)
+ {
+ buildfile = s;
+ }
+
+ private void setBuildfile(Location location)
+ {
+ buildfile = AntUtils.getBuildfileName(location);
+ }
+
+ private void updateProps(Map props, Map mostRecentProps)
+ {
+ for (Iterator iter = mostRecentProps.entrySet().iterator();
+ iter.hasNext();
+ )
+ {
+ Map.Entry me = (Map.Entry)iter.next();
+ String key = (String)me.getKey();
+ String value = (String)me.getValue();
+ if ((String)props.get(key) != null)
+ if ((String)props.get(key) != value)
+ props.put(key, value);
+ }
+ }
+
+ private void divideAndSetProperties(Map props)
+ {
+ org.apache.beehive.test.tools.tch.util.DebugLogger.log(
+ "**********Here are the props available: " + props);
+ for (Iterator iter = props.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry me = (Map.Entry)iter.next();
+ String key = (String)me.getKey();
+ String value = (String)me.getValue();
+ if (key.startsWith(CmdlineParams.SPECIAL_TCH_PROPERTY_PREFIX))
+ {
+ // only take it if it is not a property for which we want tight
+ // control over its value (is forced)
+ // and if the value does not match the declared default value
+ if (!AntProperties.isForcedProp(key) && !AntProperties.isDefault(key, value))
+ {
+ tchProperties.put(key, value);
+ }
+ }
+ else
+ {
+ passedProperties.put(key, value);
+ }
+ }
+ }
+
+ public void setDeterminePropsForIndividualTests(boolean b)
+ {
+ determinePropsForIndividualTests = b;
+ }
+
+ public Map resolveProperties()
+ {
+ Map propsToSet = new HashMap();
+
+ // first add the props we always want set
+ propsToSet.putAll(AntProperties.getNondefaultForcedValueProps());
+
+ // if testMap is empty, means we are running all tests, so just return passedProperties
+ if (testMap.isEmpty() || !determinePropsForIndividualTests)
+ {
+ propsToSet.putAll(passedProperties);
+ }
+ else
+ {
+ //Do the matching to only get the subset of properties needed
+ for (Iterator iter = testMap.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry me = (Map.Entry)iter.next();
+ for (Iterator iter2 = ((Collection)me.getValue()).iterator();
+ iter2.hasNext();
+ )
+ {
+ String propName = (String)iter2.next();
+ if (!propsToSet.containsKey(propName))
+ //if we didn't get to this property already in another test
+ // or from the hardcoded props
+ {
+ if (passedProperties.containsKey(propName))
+ //This means that the value *was* passed in
+ {
+ propsToSet.put(propName, passedProperties.get(propName));
+ }
+ }
+ }
+ }
+ }
+ return propsToSet;
+ }
+
+ public String getTestNamesValue()
+ {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator iter = testMap.keySet().iterator(); iter.hasNext();)
+ {
+ sb.append((String)iter.next());
+ if (iter.hasNext())
+ sb.append(CmdlineParams.TEST_NAMES_DELIMITER);
+ }
+ return sb.toString();
+ }
+
+ public Map getAllProperties()
+ {
+ Map props = resolveProperties();
+ props.putAll(
+ AntProperties.filterTchInternalProperties(tchProperties));
+ props = AntProperties.sortProperties(props);
+ return props;
+ }
+
+ public Map getAllProperties(Map specialProperties, Collection exclusions)
+ {
+ Collection allExcludedProps = new HashSet(excludedProps);
+ allExcludedProps.addAll(exclusions);
+ Map props = resolveProperties();
+ props.putAll(
+ AntProperties.filterTchInternalProperties(tchProperties));
+ Map ret = new HashMap();
+
+ CollectionsUtil.filterMapOnKey(props, allExcludedProps, ret, true);
+ ret.putAll(specialProperties);
+ ret = AntProperties.sortProperties(ret);
+
+ return ret;
+ }
+
+ public void addAllProperties(
+ StringBuffer sb,
+ Map specialProperties,
+ Collection exclusions)
+ {
+ AntUtils.appendProperties(
+ sb,
+ getAllProperties(specialProperties, exclusions));
+ }
+
+ public String getBuildfile()
+ {
+ return buildfile;
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestReplicationHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestRunner.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestRunner.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestRunner.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestRunner.java Fri Aug 12 08:12:28 2005
@@ -1,174 +1,174 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.tools.ant.Task;
-
-import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationAggregate;
-import org.apache.beehive.test.tools.tch.core.test.TestNameResolutionException;
-import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-
-/*
- * Run subset of tests. Only used when tch.test-names is set.
- */
-public class TestRunner extends BaseTwoPassTask
-{
- private NonfatalValidationAggregate nva = new NonfatalValidationAggregate();
-
- private static TestRegistry testRegistry = TestRegistry.getRegistry();
-
- public boolean initialize()
- {
- if (AntProperties.isIndividualTestModeOn() && super.initialize())
- {
- Properties props = new Properties();
- //For now copy all the props, will check memory
- props.putAll(getProject().getProperties());
- Snapshot.snap(props); //FIXME: Awkward PerThreadCache storage
- // ugly
- DirtyClass.setTestsToRun();
- DirtyClass.setRunSubsetPass(true);
-
- Collection unknownTests = getUnknownTests();
- addInvalidations(unknownTests);
- return true;
- }
- return false;
- }
-
- public boolean run()
- {
- if (AntProperties.isIndividualTestModeOn() && super.run())
- {
- EntryPoint lastTest = null;
- EntryPoint currTest = null;
- EntryPoint nextTest = null;
-
- Collection testEntries =
- testRegistry.getAllLogicalTestEntriesThatWillRun();
- if (AntProperties.isVerboseOn())
- writeInfo(testEntries);
-
- Collection entryPoints = testRegistry.getAllTestEntryPointsThatWillRun();
-
- for (Iterator iter = entryPoints.iterator();
- iter.hasNext() || nextTest != null;
- )
- {
- if (currTest == null) //first time only
- currTest = (EntryPoint)iter.next();
- else
- {
- lastTest = currTest;
- currTest = nextTest;
- nextTest = null;
- }
-
- if (!TchUtils.sameSuite(currTest, lastTest)
- && getInitHookTask(currTest) != null)
- getInitHookTask(currTest).perform();
-
- currTest.perform();
-
- if (iter.hasNext())
- nextTest = (EntryPoint)iter.next();
-
- if (!TchUtils.sameSuite(currTest, nextTest)
- && getCleanupHookTask(currTest) != null)
- getCleanupHookTask(currTest).perform();
- }
- DirtyClass.setRunSubsetPass(false);
- Snapshot.unsnap(); //Take stuff out of PerThreadCache
- return true;
- }
- return false;
- }
-
- private Task getInitHookTask(EntryPoint test)
- {
- if (test instanceof TestSuiteChild)
- return ((TestSuiteChild)test).getTestSuiteTask().getInitHookTask();
- else
- return null;
- }
-
- private Task getCleanupHookTask(EntryPoint test)
- {
- if (test instanceof TestSuiteChild)
- return ((TestSuiteChild)test).getTestSuiteTask().getCleanupHookTask();
- else
- return null;
- }
-
- /**
- * Internal method to determine all tests which are specified in tch.test-names,
- * but which do not exist in the test registry. These are errors.
- *
- * @return Collection of test names which are not in the test registry
- */
- private Collection getUnknownTests()
- {
- Collection ret = new ArrayList();
- Collection testNames = AntProperties.getIndividualTestNames();
- Collection unknownTests = new HashSet();
- Collection invalidTestNames = new HashSet();
- testRegistry.getTestEntryPointsThatExistByName(
- testNames,
- unknownTests,
- invalidTestNames);
- ret.addAll(unknownTests);
- ret.addAll(invalidTestNames);
- return ret;
- }
-
- /**
- * Private method to log an invalidation against each test in the Collection passed in.
- * This Collection should contain a list of tests which are unknown (do not exist in the
- * registry).
- *
- * @param unknownTests Collection of unknown tests
- */
- private void addInvalidations(Collection unknownTests)
- {
- for (Iterator iter = unknownTests.iterator(); iter.hasNext();)
- {
- String testName = (String)iter.next();
- // Ideally, if the current testname specifies a
- // subtest, we also want to check for exceptions without the subtest name
- // since the exception in the containing test could account for the current problem.
- // However, this seems difficult at the moment, so will just ensure that the
- // error message points out this fact
- NonExistentLogicalTest t = new NonExistentLogicalTest(testName);
- try
- {
- // only adding this to test reg so we get a validation error
- testRegistry.addLogicalTest(testName, t);
- }
- catch (TestNameResolutionException ex)
- {
- // ok to ignore, there is not point in registering a bogus test twice
- }
- }
- }
-
- private void writeInfo(Collection testEntries)
- {
- System.out.println("\nWill run subset of tests: ");
- for (Iterator iter = testEntries.iterator(); iter.hasNext();)
- {
- TestRegistry.Entry entry = (TestRegistry.Entry)iter.next();
- String name = entry.getLogicalTest().getName();
- if (entry.getLogicalTest().getSubtestsConfiguredToRun() != null)
- {
- name += " " + entry.getLogicalTest().getSubtestsConfiguredToRun();
- }
- System.out.println(name + "\n\n");
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.tools.ant.Task;
+
+import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationAggregate;
+import org.apache.beehive.test.tools.tch.core.test.TestNameResolutionException;
+import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+
+/*
+ * Run subset of tests. Only used when tch.test-names is set.
+ */
+public class TestRunner extends BaseTwoPassTask
+{
+ private NonfatalValidationAggregate nva = new NonfatalValidationAggregate();
+
+ private static TestRegistry testRegistry = TestRegistry.getRegistry();
+
+ public boolean initialize()
+ {
+ if (AntProperties.isIndividualTestModeOn() && super.initialize())
+ {
+ Properties props = new Properties();
+ //For now copy all the props, will check memory
+ props.putAll(getProject().getProperties());
+ Snapshot.snap(props); //FIXME: Awkward PerThreadCache storage
+ // ugly
+ DirtyClass.setTestsToRun();
+ DirtyClass.setRunSubsetPass(true);
+
+ Collection unknownTests = getUnknownTests();
+ addInvalidations(unknownTests);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean run()
+ {
+ if (AntProperties.isIndividualTestModeOn() && super.run())
+ {
+ EntryPoint lastTest = null;
+ EntryPoint currTest = null;
+ EntryPoint nextTest = null;
+
+ Collection testEntries =
+ testRegistry.getAllLogicalTestEntriesThatWillRun();
+ if (AntProperties.isVerboseOn())
+ writeInfo(testEntries);
+
+ Collection entryPoints = testRegistry.getAllTestEntryPointsThatWillRun();
+
+ for (Iterator iter = entryPoints.iterator();
+ iter.hasNext() || nextTest != null;
+ )
+ {
+ if (currTest == null) //first time only
+ currTest = (EntryPoint)iter.next();
+ else
+ {
+ lastTest = currTest;
+ currTest = nextTest;
+ nextTest = null;
+ }
+
+ if (!TchUtils.sameSuite(currTest, lastTest)
+ && getInitHookTask(currTest) != null)
+ getInitHookTask(currTest).perform();
+
+ currTest.perform();
+
+ if (iter.hasNext())
+ nextTest = (EntryPoint)iter.next();
+
+ if (!TchUtils.sameSuite(currTest, nextTest)
+ && getCleanupHookTask(currTest) != null)
+ getCleanupHookTask(currTest).perform();
+ }
+ DirtyClass.setRunSubsetPass(false);
+ Snapshot.unsnap(); //Take stuff out of PerThreadCache
+ return true;
+ }
+ return false;
+ }
+
+ private Task getInitHookTask(EntryPoint test)
+ {
+ if (test instanceof TestSuiteChild)
+ return ((TestSuiteChild)test).getTestSuiteTask().getInitHookTask();
+ else
+ return null;
+ }
+
+ private Task getCleanupHookTask(EntryPoint test)
+ {
+ if (test instanceof TestSuiteChild)
+ return ((TestSuiteChild)test).getTestSuiteTask().getCleanupHookTask();
+ else
+ return null;
+ }
+
+ /**
+ * Internal method to determine all tests which are specified in tch.test-names,
+ * but which do not exist in the test registry. These are errors.
+ *
+ * @return Collection of test names which are not in the test registry
+ */
+ private Collection getUnknownTests()
+ {
+ Collection ret = new ArrayList();
+ Collection testNames = AntProperties.getIndividualTestNames();
+ Collection unknownTests = new HashSet();
+ Collection invalidTestNames = new HashSet();
+ testRegistry.getTestEntryPointsThatExistByName(
+ testNames,
+ unknownTests,
+ invalidTestNames);
+ ret.addAll(unknownTests);
+ ret.addAll(invalidTestNames);
+ return ret;
+ }
+
+ /**
+ * Private method to log an invalidation against each test in the Collection passed in.
+ * This Collection should contain a list of tests which are unknown (do not exist in the
+ * registry).
+ *
+ * @param unknownTests Collection of unknown tests
+ */
+ private void addInvalidations(Collection unknownTests)
+ {
+ for (Iterator iter = unknownTests.iterator(); iter.hasNext();)
+ {
+ String testName = (String)iter.next();
+ // Ideally, if the current testname specifies a
+ // subtest, we also want to check for exceptions without the subtest name
+ // since the exception in the containing test could account for the current problem.
+ // However, this seems difficult at the moment, so will just ensure that the
+ // error message points out this fact
+ NonExistentLogicalTest t = new NonExistentLogicalTest(testName);
+ try
+ {
+ // only adding this to test reg so we get a validation error
+ testRegistry.addLogicalTest(testName, t);
+ }
+ catch (TestNameResolutionException ex)
+ {
+ // ok to ignore, there is not point in registering a bogus test twice
+ }
+ }
+ }
+
+ private void writeInfo(Collection testEntries)
+ {
+ System.out.println("\nWill run subset of tests: ");
+ for (Iterator iter = testEntries.iterator(); iter.hasNext();)
+ {
+ TestRegistry.Entry entry = (TestRegistry.Entry)iter.next();
+ String name = entry.getLogicalTest().getName();
+ if (entry.getLogicalTest().getSubtestsConfiguredToRun() != null)
+ {
+ name += " " + entry.getLogicalTest().getSubtestsConfiguredToRun();
+ }
+ System.out.println(name + "\n\n");
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSequentialTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSequentialTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSequentialTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSequentialTask.java Fri Aug 12 08:12:28 2005
@@ -1,94 +1,94 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.UnknownElement;
-import org.apache.tools.ant.taskdefs.Sequential;
-
-/**
- * This class is just a dummy class so that we can
- * label it as a known task
- */
-
-public class TestSequentialTask
- extends Sequential
- implements TwoPassTask, ChildTask, TestSuiteChild
-{
- private Task parentTask = null;
- private TestSuiteTask testSuiteTask = null;
-
- // just used for supporting Ant 1.6. We need to keep track of all subtasks
- // so we can recurse over them later
- private Collection allTasks = new ArrayList();
-
- public Collection getAllTasks()
- {
- return allTasks;
- }
-
- public Task getParentTask()
- {
- return parentTask;
- }
-
- public final void addTask(Task task)
- {
- boolean in_is_unknown = false;
- /*
- * Similar behavior to BaseTaskContainer's addTask. We need special handling
- * for Ant 1.6. Just keep call maybeConfigure() and store all subtasks. We end
- * up recursing through the tasks starting from the test-suite. The recursion
- * code is in BaseTaskContainer.
- */
- if (task instanceof UnknownElement)
- {
- in_is_unknown = true;
- ((UnknownElement)task).maybeConfigure();
- task = ((UnknownElement)task).getTask();
- allTasks.add(task);
- super.addTask(task);
- }
-
- if (!in_is_unknown)
- {
- super.addTask(task);
- if (parentTask instanceof BaseTaskContainer)
- ((BaseTaskContainer)parentTask).handleTask(task);
- }
- }
-
- // TestSuiteChild Impl
-
- /* (non-Javadoc)
- * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#getTestSuiteCall()
- */
- public TestSuiteCallTask getTestSuiteCall()
- {
- return testSuiteTask.getTestSuiteCall();
- }
-
- /* (non-Javadoc)
- * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#getTestSuiteTask()
- */
- public TestSuiteTask getTestSuiteTask()
- {
- return testSuiteTask;
- }
-
- /* (non-Javadoc)
- * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#setTestSuiteTask(org.apache.beehive.test.tools.tch.core.TestSuiteTask)
- */
- public void setTestSuiteTask(TestSuiteTask in)
- {
- testSuiteTask = in;
- }
-
- //ChildTask implementation.
-
- public void setParentTask(Task in)
- {
- parentTask = in;
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.UnknownElement;
+import org.apache.tools.ant.taskdefs.Sequential;
+
+/**
+ * This class is just a dummy class so that we can
+ * label it as a known task
+ */
+
+public class TestSequentialTask
+ extends Sequential
+ implements TwoPassTask, ChildTask, TestSuiteChild
+{
+ private Task parentTask = null;
+ private TestSuiteTask testSuiteTask = null;
+
+ // just used for supporting Ant 1.6. We need to keep track of all subtasks
+ // so we can recurse over them later
+ private Collection allTasks = new ArrayList();
+
+ public Collection getAllTasks()
+ {
+ return allTasks;
+ }
+
+ public Task getParentTask()
+ {
+ return parentTask;
+ }
+
+ public final void addTask(Task task)
+ {
+ boolean in_is_unknown = false;
+ /*
+ * Similar behavior to BaseTaskContainer's addTask. We need special handling
+ * for Ant 1.6. Just keep call maybeConfigure() and store all subtasks. We end
+ * up recursing through the tasks starting from the test-suite. The recursion
+ * code is in BaseTaskContainer.
+ */
+ if (task instanceof UnknownElement)
+ {
+ in_is_unknown = true;
+ ((UnknownElement)task).maybeConfigure();
+ task = ((UnknownElement)task).getTask();
+ allTasks.add(task);
+ super.addTask(task);
+ }
+
+ if (!in_is_unknown)
+ {
+ super.addTask(task);
+ if (parentTask instanceof BaseTaskContainer)
+ ((BaseTaskContainer)parentTask).handleTask(task);
+ }
+ }
+
+ // TestSuiteChild Impl
+
+ /* (non-Javadoc)
+ * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#getTestSuiteCall()
+ */
+ public TestSuiteCallTask getTestSuiteCall()
+ {
+ return testSuiteTask.getTestSuiteCall();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#getTestSuiteTask()
+ */
+ public TestSuiteTask getTestSuiteTask()
+ {
+ return testSuiteTask;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.beehive.test.tools.tch.core.TestSuiteChild#setTestSuiteTask(org.apache.beehive.test.tools.tch.core.TestSuiteTask)
+ */
+ public void setTestSuiteTask(TestSuiteTask in)
+ {
+ testSuiteTask = in;
+ }
+
+ //ChildTask implementation.
+
+ public void setParentTask(Task in)
+ {
+ parentTask = in;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSequentialTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTask.java Fri Aug 12 08:12:28 2005
@@ -1,588 +1,588 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.Ant;
-import org.apache.tools.ant.taskdefs.Property;
-
-import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationAggregate;
-import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
-import org.apache.beehive.test.tools.tch.util.AntUtils;
-import org.apache.beehive.test.tools.tch.util.TchConstants;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.DebugLogger;
-import org.apache.beehive.test.tools.tch.util.PerThreadCache;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * The purpose of this class is to do two things:
- *
- * 1. Label the ant execution call to another testfile
- * as a known task, so that it will be called in both modes
- *
- * 2. To take property snapshots before doing this, for the purpose
- * of deriving the proper, optimal, single test / single suite
- * command line. It will remove the snapshot after the call as well.
- */
-
-public class TestSuiteCallTask extends AbstractMinimalTestNodeTask
-{
- private final static int TEST_UNIT_MOD_TYPE = 1;
- private final static int TEST_NAME_MOD_TYPE = 2;
-
- private PerThreadCache perThreadCache = PerThreadCache.getInstance();
-
- private Ant antTask = new Ant();
-
- private boolean dirSet = false;
-
- private boolean topLevel = false;
- //almost always this way ... except in tch-root.xml
-
- private String fullFilePath = null;
- private String filename = "test.xml"; //new default
- private File dir = null;
-
- private boolean valid = true;
- private NonfatalValidationException validationException = null;
-
- private boolean firstCall = true;
-
- // modifier/override stuff
- private TestUnitOverrideTask tuOverrideTask = null;
- private TestUnitModifierTask tuModTask = null;
- private AppendModifierToTestUnitTask appendToTUTask = null;
- private TestNameModifierTask testNameModTask = null;
- private AppendModifierToTestNameTask appendToTestNameTask = null;
-
- // the calling chain, including the file this test-suite-call
- // is calling
- private CallingChain callingChain = null;
-
- private static TestSuiteCallRegistry registry = new TestSuiteCallRegistry();
-
- private Properties props = new Properties();
-
- //this is the global schema file, so hardcoding it is ok.
- private static final String SCHEMA_NAME = "schema/everything-suite.xsd";
-
- public Task handleTask(Task task)
- {
- task = super.handleTask(task);
- if (task instanceof TestUnitOverrideTask)
- {
- tuOverrideTask = (TestUnitOverrideTask)task;
- }
- else if (task instanceof TestUnitModifierTask)
- {
- tuModTask = (TestUnitModifierTask)task;
- }
- else if (task instanceof TestNameModifierTask)
- {
- testNameModTask = (TestNameModifierTask)task;
- }
- else if (task instanceof AppendModifierToTestUnitTask)
- {
- appendToTUTask = (AppendModifierToTestUnitTask)task;
- }
- else if (task instanceof AppendModifierToTestNameTask)
- {
- appendToTestNameTask = (AppendModifierToTestNameTask)task;
- }
-
- return task;
- }
-
- public void setAntfile(String inFilename)
- {
- //We need to grab this filename
- filename = inFilename.trim();
- }
-
- public void setTestfile(String inFilename)
- {
- setAntfile(inFilename);
- }
-
- public void setTarget(String inTarget)
- {
- antTask.setTarget(inTarget);
- }
-
- public void setDir(File f)
- {
- dirSet = true;
- dir = f;
- }
-
- private File getDir()
- {
- //Need to get the right dir out from the cache
- StringBuffer sb = new StringBuffer();
- for (Iterator iter =
- perThreadCache.getAll(Snapshot.RELATIVE_PATH).iterator();
- iter.hasNext();
- )
- {
- for (Iterator iter2 = ((List)iter.next()).iterator(); iter2.hasNext();)
- {
- sb.append((String)iter2.next());
- }
- }
- if (sb.toString().trim().length() == 0)
- return TchUtils.getCanonicalFile(new File("."));
- else
- return TchUtils.getCanonicalFile(new File(sb.toString()));
- }
-
- public void setTopLevel(boolean in)
- {
- topLevel = in;
- }
-
- private String getFullFilePath()
- {
- return fullFilePath;
- }
-
- public File getAbsolutePath()
- {
- return new File(fullFilePath).getParentFile();
- }
-
- public boolean isValid()
- {
- return valid;
- }
-
- public NonfatalValidationException getValidationException()
- {
- return validationException;
- }
-
- public String getName()
- {
- return "Test-suite-call to " + getFullFilePath();
- }
-
- public boolean isTopLevel()
- {
- return topLevel;
- }
-
- public boolean isTestNode()
- {
- return topLevel;
- }
-
- public boolean alwaysDo()
- {
- initAntTask();
- initDirs();
-
- if (DirtyClass.isFirstPass())
- {
- validateFileWithSchema(fullFilePath);
- registry.addTestSuiteCall(this);
- }
- else //run time
- {
- TestSuiteCallTask initTask = (TestSuiteCallTask)getInitTimeTask();
- if (!initTask.isValid())
- {
- //write the validation error to the logfile
- TestMultiLevelHelper.logInvalidationBatch(
- "Testfile at " + getFullFilePath(),
- initTask.getValidationException().getMessage());
- valid = false; //so we won't execute
- }
- }
-
- executeAntCall();
-
- return true;
- }
-
- private void initDirs()
- {
- //Find out what the relative directory is to the next file, store
- //to help compute baseDir for next file
-
- // if filename is abs, use that
- if (TchUtils.isAbsolutePath(filename))
- {
- File f = TchUtils.getCanonicalFile(new File(filename));
- setFilesAndPaths(f.getParentFile(), f.getAbsolutePath());
- }
- else
- {
- File d = dir;
- if (!dirSet)
- d = getDir();
- setFilesAndPaths(d, filename);
- }
- }
-
- private void setFilesAndPaths(File inDir, String inFilename)
- {
- // if dir has "..", need to resolve since ant doesn
- setDir(inDir);
- setAntfile(inFilename);
-
- if (TchUtils.isAbsolutePath(inFilename))
- fullFilePath = filename;
- else
- fullFilePath = TchUtils.getCanonicalPath(new File(dir, filename));
-
- antTask.setAntfile(filename);
- antTask.setDir(dir);
- }
-
- private void executeAntCall()
- {
- if (isValid())
- {
- String nextDir = TchUtils.getDirectoryPath(filename);
- //PerThreadCache storage
- //For now copy all the props, will check memory
- props.putAll(getProject().getProperties());
- Snapshot.snap(
- nextDir,
- props,
- new File(fullFilePath),
- getLocation(),
- this);
-
- // storing calling chain here, don't need
- // PerThreadCache for that anymore
- callingChain =
- new CallingChain(perThreadCache.getParentList(Snapshot.LOCATION));
-
- org.apache.beehive.test.tools.tch.util.DebugLogger.log(
- "TestSuiteCallTask: nextDir: " + nextDir);
-
- try
- {
- antTask.execute(); //now call the new testfile
- }
- catch (Exception ex)
- {
- if (AntProperties.isVerboseOn())
- {
- // For debugging
- ex.printStackTrace();
- }
- Throwable t = AntUtils.unwrapBuildExceptions(ex);
- if (t instanceof Exception)
- {
- Map params = new HashMap(1);
- params.put(ErrorMessageConstants.FILENAME, fullFilePath);
- validationException =
- new NonfatalValidationException(
- (Exception)t,
- ErrorMessageConstants.INVALID_TEST_SUITE_CALL_ERROR_CODE,
- params);
- // we need to log something better here since this masks out all sorts of stuff
- NonfatalValidationAggregate.addException(validationException);
- valid = false;
- }
- }
-
- Snapshot.unsnap(); //Take stuff out of PerThreadCache
- }
- }
-
- /**
- * Top level result callback method which will actually log the result
- * in the TestMultiLevelHelper
- */
- protected void notifyOnResultHook(TestResultBean tr)
- {
- super.notifyOnResultHook(tr);
- if (isTopLevel())
- {
- TestMultiLevelHelper.logResult(tr);
- if (!BuildStatus.isFailed() && tr.isProblem())
- {
- BuildStatus.setFailed();
- }
- }
- }
-
- protected AbstractMinimalTestNodeTask getInitTimeTask()
- {
- return registry.getTestSuiteCall(fullFilePath);
- }
-
- private void validateFileWithSchema(String file) throws BuildException
- {
- //toggle validation true / false
- if (AntProperties.isSchemaValidationOn())
- {
- SchemaValidate schemaValidate = new SchemaValidate();
- String filePath = AntProperties.getHomeDir();
- String schemaName =
- (String) (new File(filePath, SCHEMA_NAME)).getAbsolutePath();
- DebugLogger.log(
- "Validating testfile " + file + " using schema " + schemaName);
- try
- {
- schemaValidate.setSchemaName(schemaName);
- schemaValidate.validatingParse(file);
- }
- catch (Exception e)
- {
- //FIXME: We need to throw the right kind of exception to this point.
- Throwable t = AntUtils.unwrapBuildExceptions(e);
- if (t instanceof Exception)
- {
- Map params = new HashMap(2);
- params.put(ErrorMessageConstants.FILENAME, file);
- params.put(ErrorMessageConstants.MESSAGE, t.getMessage());
- validationException =
- new NonfatalValidationException(
- (Exception)t,
- ErrorMessageConstants.INVALID_TESTFILE_ERROR_CODE,
- params);
- NonfatalValidationAggregate.addException(validationException);
- valid = false;
- }
- else
- throw new BuildException(
- "Invalid testfile at " + file,
- t,
- getLocation());
- }
- }
- else
- {
- log("WARNING: validation of testfile " + file + " not enabled");
- }
- }
-
- public void addConfiguredProperty(Property outerProp)
- {
- initAntTask();
- Property innerProp = antTask.createProperty();
- //These are the 4 attributes currently supported, and known by the schema
- innerProp.setName(outerProp.getName());
- innerProp.setValue(outerProp.getValue());
- innerProp.setFile(outerProp.getFile());
- innerProp.setEnvironment(outerProp.getEnvironment());
-
- // add to props for snapshot
- props.setProperty(outerProp.getName(), outerProp.getValue());
- }
-
- /**
- * We need this method to support the case of when a TUMT *wraps* a TSCT (old way of doing it)
- */
- protected void setTestUnitModiferTask(TestUnitModifierTask in)
- {
- tuModTask = in;
- }
-
- // public String applyTestUnitModifier(String testunitName)
- // {
- // return applyTestUnitModifier(testunitName, new TestSuiteCallTaskProvider.GetFromSuite());
- // }
-
- public String applyTestUnitModifier(
- String testunitName,
- TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- if (appendToTUTask != null)
- {
- return applyModifier(
- testunitName,
- appendToTUTask,
- TEST_UNIT_MOD_TYPE,
- true,
- testSuiteCallTaskProvider);
- }
- else
- {
- return applyModifier(
- testunitName,
- tuModTask,
- TEST_UNIT_MOD_TYPE,
- false,
- testSuiteCallTaskProvider);
- }
- }
-
- public String applyTestNameModifier(String testName)
- {
- return applyTestNameModifier(
- testName,
- new TestSuiteCallTaskProvider.GetFromSuite());
- }
-
- public String applyTestNameModifier(
- String testName,
- TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- if (appendToTestNameTask != null)
- {
- return applyModifier(
- testName,
- appendToTestNameTask,
- TEST_NAME_MOD_TYPE,
- true,
- testSuiteCallTaskProvider);
- }
- else
- {
- return applyModifier(
- testName,
- testNameModTask,
- TEST_NAME_MOD_TYPE,
- false,
- testSuiteCallTaskProvider);
- }
- }
-
- public boolean hasTestUnitOverride(TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- boolean rtn = tuOverrideTask != null;
- TestSuiteCallTask call =
- testSuiteCallTaskProvider.getTestSuiteCallTask(this);
- if (call != null)
- rtn = rtn || call.hasTestUnitOverride(testSuiteCallTaskProvider);
- return rtn;
- }
-
- public String getTestUnitOverride()
- {
- if (tuOverrideTask != null)
- return tuOverrideTask.getValue();
- else if (isTopLevel())
- return null;
- else
- return getTestSuiteCall().getTestUnitOverride();
- }
-
- public CallingChain getCallingChain()
- {
- return callingChain;
- }
-
- public String toString()
- {
- return fullFilePath;
- }
-
- private String applyModifier(
- String entityName,
- int modType,
- TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- if (modType == TEST_UNIT_MOD_TYPE)
- {
- return applyTestUnitModifier(entityName, testSuiteCallTaskProvider);
- }
- else if (modType == TEST_NAME_MOD_TYPE)
- {
- return applyTestNameModifier(entityName, testSuiteCallTaskProvider);
- }
- else
- {
- throw new RuntimeException("Unknown MOD_TYPE");
- }
- }
-
- private String applyModifier(
- String entityName,
- TestEntityModifier mod,
- int modType,
- boolean appendModifier,
- TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- String rtn = entityName;
-
- TestSuiteCallTask parentCall =
- testSuiteCallTaskProvider.getTestSuiteCallTask(this);
-
- if (appendModifier && parentCall != null)
- rtn = parentCall.applyModifier(rtn, modType, testSuiteCallTaskProvider);
-
- if (mod != null)
- {
- if (rtn != null)
- {
- if (appendModifier)
- {
- rtn =
- rtn
- + TchConstants.FULLY_QUALIFIED_LOGICAL_NAME_SEP
- + mod.getValue();
- }
- else
- {
- rtn =
- mod.getValue()
- + TchConstants.FULLY_QUALIFIED_LOGICAL_NAME_SEP
- + rtn;
- }
- }
- else
- {
- rtn = mod.getValue();
- }
- }
- if (!appendModifier && parentCall != null)
- {
- rtn = parentCall.applyModifier(rtn, modType, testSuiteCallTaskProvider);
- }
- return rtn;
- }
-
- private void initAntTask()
- {
- if (firstCall)
- {
- AntUtils.cloneTaskData(this, antTask);
- antTask.setTaskName("ant");
- firstCall = false;
- }
- }
-
- private static class TestSuiteCallRegistry
- {
- private Map map = new HashMap();
-
- public synchronized void addTestSuiteCall(TestSuiteCallTask task)
- {
- map.put(task.getFullFilePath(), task);
- }
-
- public TestSuiteCallTask getTestSuiteCall(String fullFilePath)
- {
- return (TestSuiteCallTask)map.get(fullFilePath);
- }
-
- public String toString()
- {
- return map.toString();
- }
- }
-
- protected boolean shouldRecurse(Task in)
- {
- if (in instanceof Property)
- {
- return false;
- }
- else
- return super.shouldRecurse(in);
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Ant;
+import org.apache.tools.ant.taskdefs.Property;
+
+import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationAggregate;
+import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
+import org.apache.beehive.test.tools.tch.util.AntUtils;
+import org.apache.beehive.test.tools.tch.util.TchConstants;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.DebugLogger;
+import org.apache.beehive.test.tools.tch.util.PerThreadCache;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * The purpose of this class is to do two things:
+ *
+ * 1. Label the ant execution call to another testfile
+ * as a known task, so that it will be called in both modes
+ *
+ * 2. To take property snapshots before doing this, for the purpose
+ * of deriving the proper, optimal, single test / single suite
+ * command line. It will remove the snapshot after the call as well.
+ */
+
+public class TestSuiteCallTask extends AbstractMinimalTestNodeTask
+{
+ private final static int TEST_UNIT_MOD_TYPE = 1;
+ private final static int TEST_NAME_MOD_TYPE = 2;
+
+ private PerThreadCache perThreadCache = PerThreadCache.getInstance();
+
+ private Ant antTask = new Ant();
+
+ private boolean dirSet = false;
+
+ private boolean topLevel = false;
+ //almost always this way ... except in tch-root.xml
+
+ private String fullFilePath = null;
+ private String filename = "test.xml"; //new default
+ private File dir = null;
+
+ private boolean valid = true;
+ private NonfatalValidationException validationException = null;
+
+ private boolean firstCall = true;
+
+ // modifier/override stuff
+ private TestUnitOverrideTask tuOverrideTask = null;
+ private TestUnitModifierTask tuModTask = null;
+ private AppendModifierToTestUnitTask appendToTUTask = null;
+ private TestNameModifierTask testNameModTask = null;
+ private AppendModifierToTestNameTask appendToTestNameTask = null;
+
+ // the calling chain, including the file this test-suite-call
+ // is calling
+ private CallingChain callingChain = null;
+
+ private static TestSuiteCallRegistry registry = new TestSuiteCallRegistry();
+
+ private Properties props = new Properties();
+
+ //this is the global schema file, so hardcoding it is ok.
+ private static final String SCHEMA_NAME = "schema/everything-suite.xsd";
+
+ public Task handleTask(Task task)
+ {
+ task = super.handleTask(task);
+ if (task instanceof TestUnitOverrideTask)
+ {
+ tuOverrideTask = (TestUnitOverrideTask)task;
+ }
+ else if (task instanceof TestUnitModifierTask)
+ {
+ tuModTask = (TestUnitModifierTask)task;
+ }
+ else if (task instanceof TestNameModifierTask)
+ {
+ testNameModTask = (TestNameModifierTask)task;
+ }
+ else if (task instanceof AppendModifierToTestUnitTask)
+ {
+ appendToTUTask = (AppendModifierToTestUnitTask)task;
+ }
+ else if (task instanceof AppendModifierToTestNameTask)
+ {
+ appendToTestNameTask = (AppendModifierToTestNameTask)task;
+ }
+
+ return task;
+ }
+
+ public void setAntfile(String inFilename)
+ {
+ //We need to grab this filename
+ filename = inFilename.trim();
+ }
+
+ public void setTestfile(String inFilename)
+ {
+ setAntfile(inFilename);
+ }
+
+ public void setTarget(String inTarget)
+ {
+ antTask.setTarget(inTarget);
+ }
+
+ public void setDir(File f)
+ {
+ dirSet = true;
+ dir = f;
+ }
+
+ private File getDir()
+ {
+ //Need to get the right dir out from the cache
+ StringBuffer sb = new StringBuffer();
+ for (Iterator iter =
+ perThreadCache.getAll(Snapshot.RELATIVE_PATH).iterator();
+ iter.hasNext();
+ )
+ {
+ for (Iterator iter2 = ((List)iter.next()).iterator(); iter2.hasNext();)
+ {
+ sb.append((String)iter2.next());
+ }
+ }
+ if (sb.toString().trim().length() == 0)
+ return TchUtils.getCanonicalFile(new File("."));
+ else
+ return TchUtils.getCanonicalFile(new File(sb.toString()));
+ }
+
+ public void setTopLevel(boolean in)
+ {
+ topLevel = in;
+ }
+
+ private String getFullFilePath()
+ {
+ return fullFilePath;
+ }
+
+ public File getAbsolutePath()
+ {
+ return new File(fullFilePath).getParentFile();
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public NonfatalValidationException getValidationException()
+ {
+ return validationException;
+ }
+
+ public String getName()
+ {
+ return "Test-suite-call to " + getFullFilePath();
+ }
+
+ public boolean isTopLevel()
+ {
+ return topLevel;
+ }
+
+ public boolean isTestNode()
+ {
+ return topLevel;
+ }
+
+ public boolean alwaysDo()
+ {
+ initAntTask();
+ initDirs();
+
+ if (DirtyClass.isFirstPass())
+ {
+ validateFileWithSchema(fullFilePath);
+ registry.addTestSuiteCall(this);
+ }
+ else //run time
+ {
+ TestSuiteCallTask initTask = (TestSuiteCallTask)getInitTimeTask();
+ if (!initTask.isValid())
+ {
+ //write the validation error to the logfile
+ TestMultiLevelHelper.logInvalidationBatch(
+ "Testfile at " + getFullFilePath(),
+ initTask.getValidationException().getMessage());
+ valid = false; //so we won't execute
+ }
+ }
+
+ executeAntCall();
+
+ return true;
+ }
+
+ private void initDirs()
+ {
+ //Find out what the relative directory is to the next file, store
+ //to help compute baseDir for next file
+
+ // if filename is abs, use that
+ if (TchUtils.isAbsolutePath(filename))
+ {
+ File f = TchUtils.getCanonicalFile(new File(filename));
+ setFilesAndPaths(f.getParentFile(), f.getAbsolutePath());
+ }
+ else
+ {
+ File d = dir;
+ if (!dirSet)
+ d = getDir();
+ setFilesAndPaths(d, filename);
+ }
+ }
+
+ private void setFilesAndPaths(File inDir, String inFilename)
+ {
+ // if dir has "..", need to resolve since ant doesn
+ setDir(inDir);
+ setAntfile(inFilename);
+
+ if (TchUtils.isAbsolutePath(inFilename))
+ fullFilePath = filename;
+ else
+ fullFilePath = TchUtils.getCanonicalPath(new File(dir, filename));
+
+ antTask.setAntfile(filename);
+ antTask.setDir(dir);
+ }
+
+ private void executeAntCall()
+ {
+ if (isValid())
+ {
+ String nextDir = TchUtils.getDirectoryPath(filename);
+ //PerThreadCache storage
+ //For now copy all the props, will check memory
+ props.putAll(getProject().getProperties());
+ Snapshot.snap(
+ nextDir,
+ props,
+ new File(fullFilePath),
+ getLocation(),
+ this);
+
+ // storing calling chain here, don't need
+ // PerThreadCache for that anymore
+ callingChain =
+ new CallingChain(perThreadCache.getParentList(Snapshot.LOCATION));
+
+ org.apache.beehive.test.tools.tch.util.DebugLogger.log(
+ "TestSuiteCallTask: nextDir: " + nextDir);
+
+ try
+ {
+ antTask.execute(); //now call the new testfile
+ }
+ catch (Exception ex)
+ {
+ if (AntProperties.isVerboseOn())
+ {
+ // For debugging
+ ex.printStackTrace();
+ }
+ Throwable t = AntUtils.unwrapBuildExceptions(ex);
+ if (t instanceof Exception)
+ {
+ Map params = new HashMap(1);
+ params.put(ErrorMessageConstants.FILENAME, fullFilePath);
+ validationException =
+ new NonfatalValidationException(
+ (Exception)t,
+ ErrorMessageConstants.INVALID_TEST_SUITE_CALL_ERROR_CODE,
+ params);
+ // we need to log something better here since this masks out all sorts of stuff
+ NonfatalValidationAggregate.addException(validationException);
+ valid = false;
+ }
+ }
+
+ Snapshot.unsnap(); //Take stuff out of PerThreadCache
+ }
+ }
+
+ /**
+ * Top level result callback method which will actually log the result
+ * in the TestMultiLevelHelper
+ */
+ protected void notifyOnResultHook(TestResultBean tr)
+ {
+ super.notifyOnResultHook(tr);
+ if (isTopLevel())
+ {
+ TestMultiLevelHelper.logResult(tr);
+ if (!BuildStatus.isFailed() && tr.isProblem())
+ {
+ BuildStatus.setFailed();
+ }
+ }
+ }
+
+ protected AbstractMinimalTestNodeTask getInitTimeTask()
+ {
+ return registry.getTestSuiteCall(fullFilePath);
+ }
+
+ private void validateFileWithSchema(String file) throws BuildException
+ {
+ //toggle validation true / false
+ if (AntProperties.isSchemaValidationOn())
+ {
+ SchemaValidate schemaValidate = new SchemaValidate();
+ String filePath = AntProperties.getHomeDir();
+ String schemaName =
+ (String) (new File(filePath, SCHEMA_NAME)).getAbsolutePath();
+ DebugLogger.log(
+ "Validating testfile " + file + " using schema " + schemaName);
+ try
+ {
+ schemaValidate.setSchemaName(schemaName);
+ schemaValidate.validatingParse(file);
+ }
+ catch (Exception e)
+ {
+ //FIXME: We need to throw the right kind of exception to this point.
+ Throwable t = AntUtils.unwrapBuildExceptions(e);
+ if (t instanceof Exception)
+ {
+ Map params = new HashMap(2);
+ params.put(ErrorMessageConstants.FILENAME, file);
+ params.put(ErrorMessageConstants.MESSAGE, t.getMessage());
+ validationException =
+ new NonfatalValidationException(
+ (Exception)t,
+ ErrorMessageConstants.INVALID_TESTFILE_ERROR_CODE,
+ params);
+ NonfatalValidationAggregate.addException(validationException);
+ valid = false;
+ }
+ else
+ throw new BuildException(
+ "Invalid testfile at " + file,
+ t,
+ getLocation());
+ }
+ }
+ else
+ {
+ log("WARNING: validation of testfile " + file + " not enabled");
+ }
+ }
+
+ public void addConfiguredProperty(Property outerProp)
+ {
+ initAntTask();
+ Property innerProp = antTask.createProperty();
+ //These are the 4 attributes currently supported, and known by the schema
+ innerProp.setName(outerProp.getName());
+ innerProp.setValue(outerProp.getValue());
+ innerProp.setFile(outerProp.getFile());
+ innerProp.setEnvironment(outerProp.getEnvironment());
+
+ // add to props for snapshot
+ props.setProperty(outerProp.getName(), outerProp.getValue());
+ }
+
+ /**
+ * We need this method to support the case of when a TUMT *wraps* a TSCT (old way of doing it)
+ */
+ protected void setTestUnitModiferTask(TestUnitModifierTask in)
+ {
+ tuModTask = in;
+ }
+
+ // public String applyTestUnitModifier(String testunitName)
+ // {
+ // return applyTestUnitModifier(testunitName, new TestSuiteCallTaskProvider.GetFromSuite());
+ // }
+
+ public String applyTestUnitModifier(
+ String testunitName,
+ TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ if (appendToTUTask != null)
+ {
+ return applyModifier(
+ testunitName,
+ appendToTUTask,
+ TEST_UNIT_MOD_TYPE,
+ true,
+ testSuiteCallTaskProvider);
+ }
+ else
+ {
+ return applyModifier(
+ testunitName,
+ tuModTask,
+ TEST_UNIT_MOD_TYPE,
+ false,
+ testSuiteCallTaskProvider);
+ }
+ }
+
+ public String applyTestNameModifier(String testName)
+ {
+ return applyTestNameModifier(
+ testName,
+ new TestSuiteCallTaskProvider.GetFromSuite());
+ }
+
+ public String applyTestNameModifier(
+ String testName,
+ TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ if (appendToTestNameTask != null)
+ {
+ return applyModifier(
+ testName,
+ appendToTestNameTask,
+ TEST_NAME_MOD_TYPE,
+ true,
+ testSuiteCallTaskProvider);
+ }
+ else
+ {
+ return applyModifier(
+ testName,
+ testNameModTask,
+ TEST_NAME_MOD_TYPE,
+ false,
+ testSuiteCallTaskProvider);
+ }
+ }
+
+ public boolean hasTestUnitOverride(TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ boolean rtn = tuOverrideTask != null;
+ TestSuiteCallTask call =
+ testSuiteCallTaskProvider.getTestSuiteCallTask(this);
+ if (call != null)
+ rtn = rtn || call.hasTestUnitOverride(testSuiteCallTaskProvider);
+ return rtn;
+ }
+
+ public String getTestUnitOverride()
+ {
+ if (tuOverrideTask != null)
+ return tuOverrideTask.getValue();
+ else if (isTopLevel())
+ return null;
+ else
+ return getTestSuiteCall().getTestUnitOverride();
+ }
+
+ public CallingChain getCallingChain()
+ {
+ return callingChain;
+ }
+
+ public String toString()
+ {
+ return fullFilePath;
+ }
+
+ private String applyModifier(
+ String entityName,
+ int modType,
+ TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ if (modType == TEST_UNIT_MOD_TYPE)
+ {
+ return applyTestUnitModifier(entityName, testSuiteCallTaskProvider);
+ }
+ else if (modType == TEST_NAME_MOD_TYPE)
+ {
+ return applyTestNameModifier(entityName, testSuiteCallTaskProvider);
+ }
+ else
+ {
+ throw new RuntimeException("Unknown MOD_TYPE");
+ }
+ }
+
+ private String applyModifier(
+ String entityName,
+ TestEntityModifier mod,
+ int modType,
+ boolean appendModifier,
+ TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ String rtn = entityName;
+
+ TestSuiteCallTask parentCall =
+ testSuiteCallTaskProvider.getTestSuiteCallTask(this);
+
+ if (appendModifier && parentCall != null)
+ rtn = parentCall.applyModifier(rtn, modType, testSuiteCallTaskProvider);
+
+ if (mod != null)
+ {
+ if (rtn != null)
+ {
+ if (appendModifier)
+ {
+ rtn =
+ rtn
+ + TchConstants.FULLY_QUALIFIED_LOGICAL_NAME_SEP
+ + mod.getValue();
+ }
+ else
+ {
+ rtn =
+ mod.getValue()
+ + TchConstants.FULLY_QUALIFIED_LOGICAL_NAME_SEP
+ + rtn;
+ }
+ }
+ else
+ {
+ rtn = mod.getValue();
+ }
+ }
+ if (!appendModifier && parentCall != null)
+ {
+ rtn = parentCall.applyModifier(rtn, modType, testSuiteCallTaskProvider);
+ }
+ return rtn;
+ }
+
+ private void initAntTask()
+ {
+ if (firstCall)
+ {
+ AntUtils.cloneTaskData(this, antTask);
+ antTask.setTaskName("ant");
+ firstCall = false;
+ }
+ }
+
+ private static class TestSuiteCallRegistry
+ {
+ private Map map = new HashMap();
+
+ public synchronized void addTestSuiteCall(TestSuiteCallTask task)
+ {
+ map.put(task.getFullFilePath(), task);
+ }
+
+ public TestSuiteCallTask getTestSuiteCall(String fullFilePath)
+ {
+ return (TestSuiteCallTask)map.get(fullFilePath);
+ }
+
+ public String toString()
+ {
+ return map.toString();
+ }
+ }
+
+ protected boolean shouldRecurse(Task in)
+ {
+ if (in instanceof Property)
+ {
+ return false;
+ }
+ else
+ return super.shouldRecurse(in);
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTaskProvider.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTaskProvider.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTaskProvider.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTaskProvider.java Fri Aug 12 08:12:28 2005
@@ -1,27 +1,27 @@
-package org.apache.beehive.test.tools.tch.core;
-
-/**
- */
-interface TestSuiteCallTaskProvider
-{
- public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task);
-
- class GetFromSuite implements TestSuiteCallTaskProvider
- {
- public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task)
- {
- if (!task.isTopLevel())
- return task.getTestSuiteCall();
- else
- return null;
- }
- }
-
- class GetTillEntryPoint implements TestSuiteCallTaskProvider
- {
- public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task)
- {
- return task.getParentCallIfNoEntryPoint();
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+/**
+ */
+interface TestSuiteCallTaskProvider
+{
+ public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task);
+
+ class GetFromSuite implements TestSuiteCallTaskProvider
+ {
+ public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task)
+ {
+ if (!task.isTopLevel())
+ return task.getTestSuiteCall();
+ else
+ return null;
+ }
+ }
+
+ class GetTillEntryPoint implements TestSuiteCallTaskProvider
+ {
+ public TestSuiteCallTask getTestSuiteCallTask(AbstractMinimalTestNodeTask task)
+ {
+ return task.getParentCallIfNoEntryPoint();
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteCallTaskProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteChild.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteChild.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteChild.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteChild.java Fri Aug 12 08:12:28 2005
@@ -1,22 +1,22 @@
-package org.apache.beehive.test.tools.tch.core;
-
-/**
- * Any task nested inside a TestSuite has a reference to that TestSuite.
- */
-public interface TestSuiteChild
-{
- /**
- * Sets the parent TestSuiteTask which the current task is nested in.
- *
- * @param in the top level TestSuiteTask
- */
- public void setTestSuiteTask(TestSuiteTask in);
-
- /**
- * Gets the parent TestSuiteTask which the current task is nested in.
- *
- * @return parent TestSuiteTask
- */
- public TestSuiteTask getTestSuiteTask();
- public TestSuiteCallTask getTestSuiteCall();
-}
+package org.apache.beehive.test.tools.tch.core;
+
+/**
+ * Any task nested inside a TestSuite has a reference to that TestSuite.
+ */
+public interface TestSuiteChild
+{
+ /**
+ * Sets the parent TestSuiteTask which the current task is nested in.
+ *
+ * @param in the top level TestSuiteTask
+ */
+ public void setTestSuiteTask(TestSuiteTask in);
+
+ /**
+ * Gets the parent TestSuiteTask which the current task is nested in.
+ *
+ * @return parent TestSuiteTask
+ */
+ public TestSuiteTask getTestSuiteTask();
+ public TestSuiteCallTask getTestSuiteCall();
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteChild.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteTask.java Fri Aug 12 08:12:28 2005
@@ -1,235 +1,235 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.tools.ant.Task;
-
-import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
-import org.apache.beehive.test.tools.tch.core.process.ProcessOverride;
-import org.apache.beehive.test.tools.tch.core.test.TestSuiteRegistry;
-import org.apache.beehive.test.tools.tch.util.PerThreadCache;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-public class TestSuiteTask extends AbstractTestNodeTask implements TestParent
-{
- private InitHookTask initHookTask = null;
- private CleanupHookTask cleanupHookTask = null;
- // indicates whether an init-hook was started. This is used to insure that the
- // cleanup-hook is always run if the init-hook has run
- private boolean initHookStarted = false;
-
- private Object regKey = null;
-
- public TestSuiteTask()
- {
- super();
- getTestSuiteCallTask();
- setTestSuiteTask(this);
- }
-
- public Task handleTask(Task task)
- {
- task = super.handleTask(task); //Remember to call super!!!
-
- //Just holding onto these to call in case of test-names execution of a test in this suite
-
- if (task instanceof InitHookTask)
- {
- initHookTask = (InitHookTask)task;
- }
- if (task instanceof CleanupHookTask)
- {
- cleanupHookTask = (CleanupHookTask)task;
- }
- return task;
- }
-
- public InitHookTask getInitHookTask()
- {
- return initHookTask;
- }
-
- public CleanupHookTask getCleanupHookTask()
- {
- return cleanupHookTask;
- }
-
- public boolean getInitHookStarted()
- {
- return initHookStarted;
- }
-
- public void setInitHookStarted(boolean flag)
- {
- initHookStarted = flag;
- }
-
- public AbstractMinimalTestNodeTask getTestNode()
- {
- return this;
- }
-
- public CallingChain getCallingChain()
- {
- return getTestSuiteCall().getCallingChain();
- }
-
- public String getName()
- {
- return "Test suite in " + getRegistryKey();
- }
-
- public boolean isTestNode()
- {
- return true; //For now
- }
-
- protected boolean hasTestParentInTestFile()
- {
- return false;
- //even if there is a test parent, this is the highest we can go in the testfile
- }
-
- public String toString()
- {
- return "A TestSuite with testunit=" + getTestUnit();
- }
-
- protected AbstractMinimalTestNodeTask getInitTimeTask()
- {
- TestSuiteRegistry.Entry entry =
- TestSuiteRegistry.getRegistry().getEntry(getRegistryKey());
- return entry.getInitTimeTaskInstance();
- }
-
- protected void handleOutcomeResult(TestResultBean tr)
- {
- //Nothing for now
- }
-
- protected boolean preInitialize()
- {
- return super.preInitialize();
- }
-
- protected boolean initialize()
- {
- if (super.initialize())
- {
- TestSuiteRegistry.getRegistry().addEntry(getRegistryKey(), this);
-
- return true;
- }
- return false;
- }
-
- protected boolean preRun()
- {
- if (super.preRun())
- {
- getTestSuiteCallTask();
-
- Map currentOverrideMap = getCurrentProcessOverrides();
- for (Iterator iter = currentOverrideMap.entrySet().iterator();
- iter.hasNext();
- )
- {
- Map.Entry entry = (Map.Entry)iter.next();
- // Using getName() instead of getTestUnit() since getName() is currently the
- // testName in the process engine for a test suite
- getProcessRegistry().addProcessOverride(
- (String)entry.getKey(),
- getName(),
- (ProcessOverride)entry.getValue());
- }
- writeProcessOverrideCmdFiles(currentOverrideMap, getTestUnit());
-
- if (isValidationSkippedAtRunTime())
- {
- //Don't try to run required tests
- TestMultiLevelHelper.logInvalidationBatch(
- "Test-Suite level",
- getValidationSkipMessage(false));
- }
- return true;
- }
- else
- return false;
- }
-
- protected boolean postRun()
- {
- if (super.postRun())
- {
- // Need to shut down all process overrides that are falling out of scope
- Map overridemap = getCurrentProcessOverrides();
- for (Iterator iter = overridemap.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iter.next();
- // assume that the process engine already has the overridden process handler.
- // this might be error-prone
- ProcessHandler ph =
- getProcessEngine().getProcessHandler((String)entry.getKey());
- log("Shutting down test-unit overridden process: " + ph.getName());
- try
- {
- ph.shutdown();
- }
- catch (Exception ex)
- {
- log("Exception thrown during shutdown: " + ex.getMessage());
- }
- }
- return true;
- }
- else
- return false;
- }
-
- private Object getRegistryKey()
- {
- if (regKey == null)
- regKey =
- ((CallingChainLink)PerThreadCache
- .getInstance()
- .getLast(Snapshot.LOCATION))
- .getFile();
- return regKey;
- }
-
- private void getTestSuiteCallTask()
- {
- setParentTask(
- (TestSuiteCallTask)PerThreadCache.getInstance().get(
- Snapshot.TEST_SUITE_CALL_TASK));
- }
-
- /**
- * Returns all process names which are mapped in the
- * init-hook. This will actually call a gettor on each
- * task nested in the init-hook, to try to be as
- * concise as possible
- * @return All process names which are mapped in the init-hook
- */
- public Collection getInitHookMappedProcesses()
- {
- Collection processes = new HashSet();
- InitHookTask iht = getInitHookTask();
- if (iht != null)
- {
- Collection nestedtasks = (Collection)iht.getForeignTasks();
- for (Iterator nestediter = nestedtasks.iterator(); nestediter.hasNext();)
- {
- Task anttask = (Task)nestediter.next();
- if (anttask instanceof AnythingTask)
- {
- processes.addAll(((AnythingTask)anttask).getMappedProcessNames());
- }
- }
- }
- return processes;
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tools.ant.Task;
+
+import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
+import org.apache.beehive.test.tools.tch.core.process.ProcessOverride;
+import org.apache.beehive.test.tools.tch.core.test.TestSuiteRegistry;
+import org.apache.beehive.test.tools.tch.util.PerThreadCache;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+public class TestSuiteTask extends AbstractTestNodeTask implements TestParent
+{
+ private InitHookTask initHookTask = null;
+ private CleanupHookTask cleanupHookTask = null;
+ // indicates whether an init-hook was started. This is used to insure that the
+ // cleanup-hook is always run if the init-hook has run
+ private boolean initHookStarted = false;
+
+ private Object regKey = null;
+
+ public TestSuiteTask()
+ {
+ super();
+ getTestSuiteCallTask();
+ setTestSuiteTask(this);
+ }
+
+ public Task handleTask(Task task)
+ {
+ task = super.handleTask(task); //Remember to call super!!!
+
+ //Just holding onto these to call in case of test-names execution of a test in this suite
+
+ if (task instanceof InitHookTask)
+ {
+ initHookTask = (InitHookTask)task;
+ }
+ if (task instanceof CleanupHookTask)
+ {
+ cleanupHookTask = (CleanupHookTask)task;
+ }
+ return task;
+ }
+
+ public InitHookTask getInitHookTask()
+ {
+ return initHookTask;
+ }
+
+ public CleanupHookTask getCleanupHookTask()
+ {
+ return cleanupHookTask;
+ }
+
+ public boolean getInitHookStarted()
+ {
+ return initHookStarted;
+ }
+
+ public void setInitHookStarted(boolean flag)
+ {
+ initHookStarted = flag;
+ }
+
+ public AbstractMinimalTestNodeTask getTestNode()
+ {
+ return this;
+ }
+
+ public CallingChain getCallingChain()
+ {
+ return getTestSuiteCall().getCallingChain();
+ }
+
+ public String getName()
+ {
+ return "Test suite in " + getRegistryKey();
+ }
+
+ public boolean isTestNode()
+ {
+ return true; //For now
+ }
+
+ protected boolean hasTestParentInTestFile()
+ {
+ return false;
+ //even if there is a test parent, this is the highest we can go in the testfile
+ }
+
+ public String toString()
+ {
+ return "A TestSuite with testunit=" + getTestUnit();
+ }
+
+ protected AbstractMinimalTestNodeTask getInitTimeTask()
+ {
+ TestSuiteRegistry.Entry entry =
+ TestSuiteRegistry.getRegistry().getEntry(getRegistryKey());
+ return entry.getInitTimeTaskInstance();
+ }
+
+ protected void handleOutcomeResult(TestResultBean tr)
+ {
+ //Nothing for now
+ }
+
+ protected boolean preInitialize()
+ {
+ return super.preInitialize();
+ }
+
+ protected boolean initialize()
+ {
+ if (super.initialize())
+ {
+ TestSuiteRegistry.getRegistry().addEntry(getRegistryKey(), this);
+
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean preRun()
+ {
+ if (super.preRun())
+ {
+ getTestSuiteCallTask();
+
+ Map currentOverrideMap = getCurrentProcessOverrides();
+ for (Iterator iter = currentOverrideMap.entrySet().iterator();
+ iter.hasNext();
+ )
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ // Using getName() instead of getTestUnit() since getName() is currently the
+ // testName in the process engine for a test suite
+ getProcessRegistry().addProcessOverride(
+ (String)entry.getKey(),
+ getName(),
+ (ProcessOverride)entry.getValue());
+ }
+ writeProcessOverrideCmdFiles(currentOverrideMap, getTestUnit());
+
+ if (isValidationSkippedAtRunTime())
+ {
+ //Don't try to run required tests
+ TestMultiLevelHelper.logInvalidationBatch(
+ "Test-Suite level",
+ getValidationSkipMessage(false));
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ protected boolean postRun()
+ {
+ if (super.postRun())
+ {
+ // Need to shut down all process overrides that are falling out of scope
+ Map overridemap = getCurrentProcessOverrides();
+ for (Iterator iter = overridemap.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ // assume that the process engine already has the overridden process handler.
+ // this might be error-prone
+ ProcessHandler ph =
+ getProcessEngine().getProcessHandler((String)entry.getKey());
+ log("Shutting down test-unit overridden process: " + ph.getName());
+ try
+ {
+ ph.shutdown();
+ }
+ catch (Exception ex)
+ {
+ log("Exception thrown during shutdown: " + ex.getMessage());
+ }
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ private Object getRegistryKey()
+ {
+ if (regKey == null)
+ regKey =
+ ((CallingChainLink)PerThreadCache
+ .getInstance()
+ .getLast(Snapshot.LOCATION))
+ .getFile();
+ return regKey;
+ }
+
+ private void getTestSuiteCallTask()
+ {
+ setParentTask(
+ (TestSuiteCallTask)PerThreadCache.getInstance().get(
+ Snapshot.TEST_SUITE_CALL_TASK));
+ }
+
+ /**
+ * Returns all process names which are mapped in the
+ * init-hook. This will actually call a gettor on each
+ * task nested in the init-hook, to try to be as
+ * concise as possible
+ * @return All process names which are mapped in the init-hook
+ */
+ public Collection getInitHookMappedProcesses()
+ {
+ Collection processes = new HashSet();
+ InitHookTask iht = getInitHookTask();
+ if (iht != null)
+ {
+ Collection nestedtasks = (Collection)iht.getForeignTasks();
+ for (Iterator nestediter = nestedtasks.iterator(); nestediter.hasNext();)
+ {
+ Task anttask = (Task)nestediter.next();
+ if (anttask instanceof AnythingTask)
+ {
+ processes.addAll(((AnythingTask)anttask).getMappedProcessNames());
+ }
+ }
+ }
+ return processes;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/TestSuiteTask.java
------------------------------------------------------------------------------
svn:eol-style = native