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 [46/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/AbstractMinimalTestNodeTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractMinimalTestNodeTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractMinimalTestNodeTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractMinimalTestNodeTask.java Fri Aug 12 08:12:28 2005
@@ -1,552 +1,552 @@
-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.List;
-
-import org.apache.tools.ant.Task;
-
-import org.apache.beehive.test.tools.tch.core.configuration.ProcessManagementConfigurationException;
-import org.apache.beehive.test.tools.tch.core.test.BasicInternalParameters;
-import org.apache.beehive.test.tools.tch.core.test.InternalParameters;
-import org.apache.beehive.test.tools.tch.core.test.TestEntryKey;
-import org.apache.beehive.test.tools.tch.util.AntUtils;
-import org.apache.beehive.test.tools.tch.util.TestResult;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * Abstract base class in the test inheritance chain which provides
- * the following functionality:
- * <li>access to test parameters
- * <li>access to a parent/child tasks
- * <li>ability to skip the test
- */
-public abstract class AbstractMinimalTestNodeTask
- extends BaseTaskContainer
- implements ChildTask, ParamContainer
-{
- public static String sep = System.getProperty("line.separator");
-
- private AbstractMinimalTestNodeTask testParent = null;
-
- private String skipMessage = null;
- private boolean skipped = false;
- private boolean shortCircuited = false;
-
- //populated by callbacks from ChildTasks
- private Collection childTestNodes = new ArrayList();
-
- /**
- * Hook called to set up the task.
- */
- public Task handleTask(Task task)
- {
- org.apache.beehive.test.tools.tch.util.DebugLogger.log(
- "AbstractMinimalTestNodeTask.handleTask()",
- getLocation());
- task = super.handleTask(task); //Remember to call super!!!
- if (task instanceof AnythingTask)
- {
- AnythingTask anythingTask = (AnythingTask)task;
- anythingTask.setParamContainer(this);
- anythingTask.setTestNode(getClosestAbstractTestNodeInFile(this));
- }
- return task;
- }
-
- /**
- * Either returns itself if not nested within a block, or
- * returns the outer-most block.
- *
- * @return The "outer-most" logical test, in the context of
- * test-blocks.
- */
- public LogicalTest getLogicalTest()
- {
- if (!isTestBlockAbove() && (this instanceof LogicalTest))
- return (LogicalTest)this;
- else
- return getTestParent().getLogicalTest();
- }
-
- public AbstractMinimalTestNodeTask getTestNode()
- {
- if (isTestNode())
- return this;
- else
- return getTestParent().getTestNode();
- }
-
- public abstract boolean isTestNode();
-
- /**
- * Check whether the current task is nested within a test-block
- *
- * @return true if this is in a test-block
- */
- public boolean isTestBlockAbove()
- {
- if (hasTestParent())
- return getTestParent() instanceof TestBlockTask
- || getTestParent().isTestBlockAbove();
- else
- return false;
- }
-
- /**
- * Get the closest AbstractTestNodeTask that the specified task is nested in.
- * Will also return the task itself if it is an AbstractTestNodeTask
- *
- * @param task task to check
- * @return closest AbstractTestNodeTask the specified task is nested in
- */
- private AbstractTestNodeTask getClosestAbstractTestNodeInFile(AbstractMinimalTestNodeTask task)
- {
- // this will never recurse out of the suite. either we reach the <test>, or the <test-suite>
- // which will cause the recursion to stop. or parent is null, if outside of <test-suite>,
- // in which case we'll stop also
- if (task == null)
- return null;
- else if (task instanceof AbstractTestNodeTask)
- return (AbstractTestNodeTask)task;
- else
- return getClosestAbstractTestNodeInFile(task.getTestParent());
- }
-
- private boolean isEntryPointAbove()
- {
- if (hasTestParent())
- return getTestParent() instanceof EntryPoint
- || getTestParent().isEntryPointAbove();
- else
- return false;
- }
-
- public boolean isEntryPoint()
- {
- return !isEntryPointAbove();
- }
-
- public EntryPoint getEntryPoint()
- {
- if (isEntryPointAbove())
- return getTestParent().getEntryPoint();
- else if (this instanceof EntryPoint)
- return (EntryPoint)this;
- return null;
-
- }
-
- public boolean isTopLevel()
- {
- return false;
- }
-
- public void addChild(AbstractMinimalTestNodeTask in)
- {
- childTestNodes.add(in);
- }
-
- public Collection getChildren()
- {
- return childTestNodes;
- }
-
- protected void disconnectChildren()
- {
- childTestNodes = new ArrayList();
- }
-
- public abstract String getName();
-
- //Method related to skipping a test
- //(either short circuiting, regular skipping, or validation skipping)
-
- public boolean isShortCircuited()
- {
- if (isTestNode())
- if (hasTestParent())
- return shortCircuited || getTestParent().isShortCircuited();
- else
- return shortCircuited;
- else
- return getTestNode().isShortCircuited();
- }
-
- protected void shortCircuit(String inFailedTestName)
- {
- getTestNode().shortCircuitLocal(inFailedTestName);
- }
-
- protected void shortCircuitLocal(String inFailedTestName)
- {
- skipMessage = "Logical test " + inFailedTestName + " failed.";
- shortCircuited = true;
- }
-
- public boolean isSkipped()
- {
- if (isTestNode())
- if (hasTestParent())
- return skipped || getTestParent().isSkipped();
- else
- return skipped;
- else
- return getTestNode().isSkipped();
- }
-
- private void skipLocal(String message)
- {
- //log("Skipping \"" + getName() + "\" due to: " + message);
- skipMessage = message;
- skipped = true;
- }
-
- public void skip(String message)
- {
- getTestNode().skipLocal(message);
- }
-
- public boolean isValidationSkipped()
- {
- return getTestNode().isValidationSkippedAtRunTime();
- }
-
- protected AbstractMinimalTestNodeTask getInitTimeTask()
- {
- return null;
- }
-
- public boolean isValidationSkippedAtRunTime()
- {
- boolean rtn = isValidationSkippedLocal();
- if (getInitTimeTask() != null)
- rtn = rtn || getInitTimeTask().isValidationSkippedAtInitTime();
- return rtn;
- }
-
- public boolean isValidationSkippedAtInitTime()
- {
- boolean rtn = isValidationSkippedLocal();
- if (hasTestParentInTestFile())
- rtn = rtn || getTestParent().isValidationSkippedAtInitTime();
- return rtn;
- }
-
- public boolean isValidationSkippedLocal()
- {
- return !isValid();
- }
-
- /**
- * Get the validation skip message.
- * @param complete Specified whether we want the entire skip message. When false, will return the
- * skip message for the current test only. When true, will also return the skip message for the
- * test parent (if any)
- */
- public String getValidationSkipMessage(boolean complete)
- {
- if (getInitTimeTask() != null)
- return getInitTimeTask().getValidationSkipMessageAtInitTime(complete);
- else
- return "";
- }
-
- protected TestSuiteCallTask getParentCallIfNoEntryPoint()
- {
- Collection ret = new ArrayList();
- if (isEntryPointAbove())
- getTestParent().collectTestSuiteCallsRecursively(ret, true);
- if (ret.isEmpty())
- return null;
- return (TestSuiteCallTask)ret.iterator().next();
- }
-
- /**
- * Get the enclosing TestBlockTask
- * @return the parent test-block or null if there is none
- */
- public TestBlockTask getParentTestBlock()
- {
- if (hasTestParent())
- {
- if (getTestParent() instanceof TestBlockTask)
- {
- return (TestBlockTask)getTestParent();
- }
- else
- {
- return getTestParent().getParentTestBlock();
- }
- }
- else
- {
- return null;
- }
- }
-
- public Collection getAllTestSuiteCallTasksUpToEntryPoint()
- {
- Collection ret = new ArrayList();
- if (isEntryPointAbove())
- getTestParent().collectTestSuiteCallsRecursively(ret, false);
- return ret;
- }
-
- private void collectTestSuiteCallsRecursively(
- Collection ret,
- boolean stopAfterFirst)
- {
- if (isEntryPoint())
- return;
- else if (this instanceof TestSuiteCallTask)
- {
- ret.add(this);
- if (stopAfterFirst)
- return;
- }
- if (hasTestParent())
- getTestParent().collectTestSuiteCallsRecursively(ret, stopAfterFirst);
- }
-
- public String getValidationSkipMessageAtInitTime(boolean complete) //Only meant to be called at top level
- {
- StringBuffer sb = new StringBuffer();
-
- String skip1 = getValidationSkipMessageLocal();
-
- String skip2 = null;
- if (hasTestParentInTestFile()
- && getTestParent().isValidationSkippedAtInitTime())
- {
- //FIXME: This can be made cleaner, test suite message should go elsewhere
- if (complete)
- {
- skip2 =
- "Invalidation caused at the test-suite level, see above test-suite invalidation output.";
- }
- else
- {
- // For XML logging, we want the entire validation skip message to appear in the
- // output details of the validation skip
- skip2 = getTestParent().getValidationSkipMessageAtInitTime(true);
- }
- }
-
- if (!skip1.equals("") && skip2 != null)
- {
- sb.append(skip1).append("\n\nIn addition: ").append(skip2);
- }
- else
- {
- if (!skip1.equals(""))
- sb.append(skip1);
- if (skip2 != null)
- sb.append(skip2);
- }
- return sb.toString();
- }
-
- public String getValidationSkipMessageLocal()
- {
- return getInvalidationMessage();
- }
-
- public String getSkipMessage()
- {
- if (isTestNode())
- {
- StringBuffer sb = new StringBuffer();
- String msg1 = null;
- String msg2 = null;
- if (hasTestParent())
- msg1 = getTestParent().getSkipMessage();
- msg2 = getSkipMessageLocal();
-
- if (msg1 != null && msg2 != null)
- sb.append(msg1).append(" + ").append(msg2);
- else if (msg1 == null && msg2 == null)
- return null;
- else
- {
- if (msg1 != null)
- sb.append(msg1);
- if (msg2 != null)
- sb.append(msg2);
- }
- return sb.toString();
- }
- else
- return getTestNode().getSkipMessage();
- }
-
- private String getSkipMessageLocal()
- {
- return skipMessage;
- }
-
- //End of skip-related methods
-
- //Child task impl
-
- public void setParentTask(Task in)
- {
- if (in instanceof AbstractMinimalTestNodeTask)
- {
- testParent = (AbstractMinimalTestNodeTask)in;
- testParent.addChild(this); //register back pointer to parent AMTNT
- }
- }
-
- public Collection getUsedProps()
- {
- Collection props = new HashSet();
- getUsedPropsAbove(props);
- getUsedPropsBelow(props);
- return props;
- }
-
- public Collection getUsedPropsAbove(Collection props)
- {
- props.addAll(super.getUsedProps());
- //in case any used props in here, IfTask currently puts some in
- if (hasTestParentInTestFile())
- return getTestParent().getUsedPropsAbove(props);
- else
- return props;
- }
-
- public void getUsedPropsBelow(Collection props)
- {
- for (Iterator iter = getChildren().iterator(); iter.hasNext();)
- {
- ((AbstractMinimalTestNodeTask)iter.next()).getUsedPropsBelow(props);
- }
- }
-
- protected AbstractMinimalTestNodeTask getTestParent()
- {
- return testParent;
- }
-
- protected boolean hasTestParent()
- {
- return testParent != null;
- }
-
- protected boolean hasTestParentInTestFile()
- {
- return testParent != null;
- }
-
- // stuff that should be set for all results
- protected void initializeResult(TestResultBean tr, String fullName)
- {
- tr.setName(fullName);
- tr.setTestUnitName(getTestUnit());
- tr.setSourcePath(AntUtils.getSourcePath(getLocation()));
- }
-
- //These are just implemented to delegate to their parent. More implementation in subclasses
-
- public String getTestUnit()
- {
- return getTestUnit(new TestSuiteCallTaskProvider.GetFromSuite());
- }
-
- protected String getTestUnit(TestSuiteCallTaskProvider testSuiteCallTaskProvider)
- {
- return getTestParent().getTestUnit(testSuiteCallTaskProvider);
- }
-
- public Integer getTestTimeoutSeconds()
- {
- return getTestParent().getTestTimeoutSeconds();
- }
-
- public InternalParameters getParameters()
- {
- InternalParameters parameters = new BasicInternalParameters();
- return getParametersAbove(parameters);
- }
-
- public InternalParameters getParametersAbove(InternalParameters params)
- {
- return getTestParent().getParametersAbove(params);
- }
-
- public void getParametersBelow(InternalParameters params)
- {
- for (Iterator iter = getChildren().iterator(); iter.hasNext();)
- {
- ((AbstractMinimalTestNodeTask)iter.next()).getParametersBelow(params);
- }
- }
-
- public List getMetadataTasks(List list)
- {
- return getTestParent().getMetadataTasks(list);
- }
-
- public String getExplicitDefaultProcessName()
- {
- return getTestParent().getExplicitDefaultProcessName();
- }
-
- public String getDefaultProcessName()
- {
- return getTestParent().getDefaultProcessName();
- }
-
- public void setDefaultProcessTask()
- throws ProcessManagementConfigurationException
- {
- getTestParent().setDefaultProcessTask();
- }
-
- public String getLowestSingleProcessName()
- {
- return getTestParent().getLowestSingleProcessName();
- }
-
- public Collection getAllProcessTasksAbove()
- {
- return getTestParent().getAllProcessTasksAbove();
- }
-
- public void getAllProcessTasksBelow(Collection coll)
- {
- for (Iterator iter = getChildren().iterator(); iter.hasNext();)
- {
- ((AbstractMinimalTestNodeTask)iter.next()).getAllProcessTasksBelow(coll);
- }
- }
-
- /**
- * This hook is called when a result is logged. It allows the notifyOnResultHook() method for all
- * parent tasks to get called.
- *
- * @param tr the actual result being logged
- */
- protected final void notifyOnResult(TestResultBean tr)
- {
- if (hasTestParent())
- {
- getTestParent().notifyOnResultHook(tr);
- getTestParent().notifyOnResult(tr);
- }
- }
-
- //This hook is not called on the first caller to notifyOnResult
- protected void notifyOnResultHook(TestResultBean tr)
- {
- //No-op is default implementation
- }
-
- public boolean shouldRun()
- {
- return !(isShortCircuited() || isSkipped() || isValidationSkipped());
- }
-}
+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.List;
+
+import org.apache.tools.ant.Task;
+
+import org.apache.beehive.test.tools.tch.core.configuration.ProcessManagementConfigurationException;
+import org.apache.beehive.test.tools.tch.core.test.BasicInternalParameters;
+import org.apache.beehive.test.tools.tch.core.test.InternalParameters;
+import org.apache.beehive.test.tools.tch.core.test.TestEntryKey;
+import org.apache.beehive.test.tools.tch.util.AntUtils;
+import org.apache.beehive.test.tools.tch.util.TestResult;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * Abstract base class in the test inheritance chain which provides
+ * the following functionality:
+ * <li>access to test parameters
+ * <li>access to a parent/child tasks
+ * <li>ability to skip the test
+ */
+public abstract class AbstractMinimalTestNodeTask
+ extends BaseTaskContainer
+ implements ChildTask, ParamContainer
+{
+ public static String sep = System.getProperty("line.separator");
+
+ private AbstractMinimalTestNodeTask testParent = null;
+
+ private String skipMessage = null;
+ private boolean skipped = false;
+ private boolean shortCircuited = false;
+
+ //populated by callbacks from ChildTasks
+ private Collection childTestNodes = new ArrayList();
+
+ /**
+ * Hook called to set up the task.
+ */
+ public Task handleTask(Task task)
+ {
+ org.apache.beehive.test.tools.tch.util.DebugLogger.log(
+ "AbstractMinimalTestNodeTask.handleTask()",
+ getLocation());
+ task = super.handleTask(task); //Remember to call super!!!
+ if (task instanceof AnythingTask)
+ {
+ AnythingTask anythingTask = (AnythingTask)task;
+ anythingTask.setParamContainer(this);
+ anythingTask.setTestNode(getClosestAbstractTestNodeInFile(this));
+ }
+ return task;
+ }
+
+ /**
+ * Either returns itself if not nested within a block, or
+ * returns the outer-most block.
+ *
+ * @return The "outer-most" logical test, in the context of
+ * test-blocks.
+ */
+ public LogicalTest getLogicalTest()
+ {
+ if (!isTestBlockAbove() && (this instanceof LogicalTest))
+ return (LogicalTest)this;
+ else
+ return getTestParent().getLogicalTest();
+ }
+
+ public AbstractMinimalTestNodeTask getTestNode()
+ {
+ if (isTestNode())
+ return this;
+ else
+ return getTestParent().getTestNode();
+ }
+
+ public abstract boolean isTestNode();
+
+ /**
+ * Check whether the current task is nested within a test-block
+ *
+ * @return true if this is in a test-block
+ */
+ public boolean isTestBlockAbove()
+ {
+ if (hasTestParent())
+ return getTestParent() instanceof TestBlockTask
+ || getTestParent().isTestBlockAbove();
+ else
+ return false;
+ }
+
+ /**
+ * Get the closest AbstractTestNodeTask that the specified task is nested in.
+ * Will also return the task itself if it is an AbstractTestNodeTask
+ *
+ * @param task task to check
+ * @return closest AbstractTestNodeTask the specified task is nested in
+ */
+ private AbstractTestNodeTask getClosestAbstractTestNodeInFile(AbstractMinimalTestNodeTask task)
+ {
+ // this will never recurse out of the suite. either we reach the <test>, or the <test-suite>
+ // which will cause the recursion to stop. or parent is null, if outside of <test-suite>,
+ // in which case we'll stop also
+ if (task == null)
+ return null;
+ else if (task instanceof AbstractTestNodeTask)
+ return (AbstractTestNodeTask)task;
+ else
+ return getClosestAbstractTestNodeInFile(task.getTestParent());
+ }
+
+ private boolean isEntryPointAbove()
+ {
+ if (hasTestParent())
+ return getTestParent() instanceof EntryPoint
+ || getTestParent().isEntryPointAbove();
+ else
+ return false;
+ }
+
+ public boolean isEntryPoint()
+ {
+ return !isEntryPointAbove();
+ }
+
+ public EntryPoint getEntryPoint()
+ {
+ if (isEntryPointAbove())
+ return getTestParent().getEntryPoint();
+ else if (this instanceof EntryPoint)
+ return (EntryPoint)this;
+ return null;
+
+ }
+
+ public boolean isTopLevel()
+ {
+ return false;
+ }
+
+ public void addChild(AbstractMinimalTestNodeTask in)
+ {
+ childTestNodes.add(in);
+ }
+
+ public Collection getChildren()
+ {
+ return childTestNodes;
+ }
+
+ protected void disconnectChildren()
+ {
+ childTestNodes = new ArrayList();
+ }
+
+ public abstract String getName();
+
+ //Method related to skipping a test
+ //(either short circuiting, regular skipping, or validation skipping)
+
+ public boolean isShortCircuited()
+ {
+ if (isTestNode())
+ if (hasTestParent())
+ return shortCircuited || getTestParent().isShortCircuited();
+ else
+ return shortCircuited;
+ else
+ return getTestNode().isShortCircuited();
+ }
+
+ protected void shortCircuit(String inFailedTestName)
+ {
+ getTestNode().shortCircuitLocal(inFailedTestName);
+ }
+
+ protected void shortCircuitLocal(String inFailedTestName)
+ {
+ skipMessage = "Logical test " + inFailedTestName + " failed.";
+ shortCircuited = true;
+ }
+
+ public boolean isSkipped()
+ {
+ if (isTestNode())
+ if (hasTestParent())
+ return skipped || getTestParent().isSkipped();
+ else
+ return skipped;
+ else
+ return getTestNode().isSkipped();
+ }
+
+ private void skipLocal(String message)
+ {
+ //log("Skipping \"" + getName() + "\" due to: " + message);
+ skipMessage = message;
+ skipped = true;
+ }
+
+ public void skip(String message)
+ {
+ getTestNode().skipLocal(message);
+ }
+
+ public boolean isValidationSkipped()
+ {
+ return getTestNode().isValidationSkippedAtRunTime();
+ }
+
+ protected AbstractMinimalTestNodeTask getInitTimeTask()
+ {
+ return null;
+ }
+
+ public boolean isValidationSkippedAtRunTime()
+ {
+ boolean rtn = isValidationSkippedLocal();
+ if (getInitTimeTask() != null)
+ rtn = rtn || getInitTimeTask().isValidationSkippedAtInitTime();
+ return rtn;
+ }
+
+ public boolean isValidationSkippedAtInitTime()
+ {
+ boolean rtn = isValidationSkippedLocal();
+ if (hasTestParentInTestFile())
+ rtn = rtn || getTestParent().isValidationSkippedAtInitTime();
+ return rtn;
+ }
+
+ public boolean isValidationSkippedLocal()
+ {
+ return !isValid();
+ }
+
+ /**
+ * Get the validation skip message.
+ * @param complete Specified whether we want the entire skip message. When false, will return the
+ * skip message for the current test only. When true, will also return the skip message for the
+ * test parent (if any)
+ */
+ public String getValidationSkipMessage(boolean complete)
+ {
+ if (getInitTimeTask() != null)
+ return getInitTimeTask().getValidationSkipMessageAtInitTime(complete);
+ else
+ return "";
+ }
+
+ protected TestSuiteCallTask getParentCallIfNoEntryPoint()
+ {
+ Collection ret = new ArrayList();
+ if (isEntryPointAbove())
+ getTestParent().collectTestSuiteCallsRecursively(ret, true);
+ if (ret.isEmpty())
+ return null;
+ return (TestSuiteCallTask)ret.iterator().next();
+ }
+
+ /**
+ * Get the enclosing TestBlockTask
+ * @return the parent test-block or null if there is none
+ */
+ public TestBlockTask getParentTestBlock()
+ {
+ if (hasTestParent())
+ {
+ if (getTestParent() instanceof TestBlockTask)
+ {
+ return (TestBlockTask)getTestParent();
+ }
+ else
+ {
+ return getTestParent().getParentTestBlock();
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public Collection getAllTestSuiteCallTasksUpToEntryPoint()
+ {
+ Collection ret = new ArrayList();
+ if (isEntryPointAbove())
+ getTestParent().collectTestSuiteCallsRecursively(ret, false);
+ return ret;
+ }
+
+ private void collectTestSuiteCallsRecursively(
+ Collection ret,
+ boolean stopAfterFirst)
+ {
+ if (isEntryPoint())
+ return;
+ else if (this instanceof TestSuiteCallTask)
+ {
+ ret.add(this);
+ if (stopAfterFirst)
+ return;
+ }
+ if (hasTestParent())
+ getTestParent().collectTestSuiteCallsRecursively(ret, stopAfterFirst);
+ }
+
+ public String getValidationSkipMessageAtInitTime(boolean complete) //Only meant to be called at top level
+ {
+ StringBuffer sb = new StringBuffer();
+
+ String skip1 = getValidationSkipMessageLocal();
+
+ String skip2 = null;
+ if (hasTestParentInTestFile()
+ && getTestParent().isValidationSkippedAtInitTime())
+ {
+ //FIXME: This can be made cleaner, test suite message should go elsewhere
+ if (complete)
+ {
+ skip2 =
+ "Invalidation caused at the test-suite level, see above test-suite invalidation output.";
+ }
+ else
+ {
+ // For XML logging, we want the entire validation skip message to appear in the
+ // output details of the validation skip
+ skip2 = getTestParent().getValidationSkipMessageAtInitTime(true);
+ }
+ }
+
+ if (!skip1.equals("") && skip2 != null)
+ {
+ sb.append(skip1).append("\n\nIn addition: ").append(skip2);
+ }
+ else
+ {
+ if (!skip1.equals(""))
+ sb.append(skip1);
+ if (skip2 != null)
+ sb.append(skip2);
+ }
+ return sb.toString();
+ }
+
+ public String getValidationSkipMessageLocal()
+ {
+ return getInvalidationMessage();
+ }
+
+ public String getSkipMessage()
+ {
+ if (isTestNode())
+ {
+ StringBuffer sb = new StringBuffer();
+ String msg1 = null;
+ String msg2 = null;
+ if (hasTestParent())
+ msg1 = getTestParent().getSkipMessage();
+ msg2 = getSkipMessageLocal();
+
+ if (msg1 != null && msg2 != null)
+ sb.append(msg1).append(" + ").append(msg2);
+ else if (msg1 == null && msg2 == null)
+ return null;
+ else
+ {
+ if (msg1 != null)
+ sb.append(msg1);
+ if (msg2 != null)
+ sb.append(msg2);
+ }
+ return sb.toString();
+ }
+ else
+ return getTestNode().getSkipMessage();
+ }
+
+ private String getSkipMessageLocal()
+ {
+ return skipMessage;
+ }
+
+ //End of skip-related methods
+
+ //Child task impl
+
+ public void setParentTask(Task in)
+ {
+ if (in instanceof AbstractMinimalTestNodeTask)
+ {
+ testParent = (AbstractMinimalTestNodeTask)in;
+ testParent.addChild(this); //register back pointer to parent AMTNT
+ }
+ }
+
+ public Collection getUsedProps()
+ {
+ Collection props = new HashSet();
+ getUsedPropsAbove(props);
+ getUsedPropsBelow(props);
+ return props;
+ }
+
+ public Collection getUsedPropsAbove(Collection props)
+ {
+ props.addAll(super.getUsedProps());
+ //in case any used props in here, IfTask currently puts some in
+ if (hasTestParentInTestFile())
+ return getTestParent().getUsedPropsAbove(props);
+ else
+ return props;
+ }
+
+ public void getUsedPropsBelow(Collection props)
+ {
+ for (Iterator iter = getChildren().iterator(); iter.hasNext();)
+ {
+ ((AbstractMinimalTestNodeTask)iter.next()).getUsedPropsBelow(props);
+ }
+ }
+
+ protected AbstractMinimalTestNodeTask getTestParent()
+ {
+ return testParent;
+ }
+
+ protected boolean hasTestParent()
+ {
+ return testParent != null;
+ }
+
+ protected boolean hasTestParentInTestFile()
+ {
+ return testParent != null;
+ }
+
+ // stuff that should be set for all results
+ protected void initializeResult(TestResultBean tr, String fullName)
+ {
+ tr.setName(fullName);
+ tr.setTestUnitName(getTestUnit());
+ tr.setSourcePath(AntUtils.getSourcePath(getLocation()));
+ }
+
+ //These are just implemented to delegate to their parent. More implementation in subclasses
+
+ public String getTestUnit()
+ {
+ return getTestUnit(new TestSuiteCallTaskProvider.GetFromSuite());
+ }
+
+ protected String getTestUnit(TestSuiteCallTaskProvider testSuiteCallTaskProvider)
+ {
+ return getTestParent().getTestUnit(testSuiteCallTaskProvider);
+ }
+
+ public Integer getTestTimeoutSeconds()
+ {
+ return getTestParent().getTestTimeoutSeconds();
+ }
+
+ public InternalParameters getParameters()
+ {
+ InternalParameters parameters = new BasicInternalParameters();
+ return getParametersAbove(parameters);
+ }
+
+ public InternalParameters getParametersAbove(InternalParameters params)
+ {
+ return getTestParent().getParametersAbove(params);
+ }
+
+ public void getParametersBelow(InternalParameters params)
+ {
+ for (Iterator iter = getChildren().iterator(); iter.hasNext();)
+ {
+ ((AbstractMinimalTestNodeTask)iter.next()).getParametersBelow(params);
+ }
+ }
+
+ public List getMetadataTasks(List list)
+ {
+ return getTestParent().getMetadataTasks(list);
+ }
+
+ public String getExplicitDefaultProcessName()
+ {
+ return getTestParent().getExplicitDefaultProcessName();
+ }
+
+ public String getDefaultProcessName()
+ {
+ return getTestParent().getDefaultProcessName();
+ }
+
+ public void setDefaultProcessTask()
+ throws ProcessManagementConfigurationException
+ {
+ getTestParent().setDefaultProcessTask();
+ }
+
+ public String getLowestSingleProcessName()
+ {
+ return getTestParent().getLowestSingleProcessName();
+ }
+
+ public Collection getAllProcessTasksAbove()
+ {
+ return getTestParent().getAllProcessTasksAbove();
+ }
+
+ public void getAllProcessTasksBelow(Collection coll)
+ {
+ for (Iterator iter = getChildren().iterator(); iter.hasNext();)
+ {
+ ((AbstractMinimalTestNodeTask)iter.next()).getAllProcessTasksBelow(coll);
+ }
+ }
+
+ /**
+ * This hook is called when a result is logged. It allows the notifyOnResultHook() method for all
+ * parent tasks to get called.
+ *
+ * @param tr the actual result being logged
+ */
+ protected final void notifyOnResult(TestResultBean tr)
+ {
+ if (hasTestParent())
+ {
+ getTestParent().notifyOnResultHook(tr);
+ getTestParent().notifyOnResult(tr);
+ }
+ }
+
+ //This hook is not called on the first caller to notifyOnResult
+ protected void notifyOnResultHook(TestResultBean tr)
+ {
+ //No-op is default implementation
+ }
+
+ public boolean shouldRun()
+ {
+ return !(isShortCircuited() || isSkipped() || isValidationSkipped());
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractMinimalTestNodeTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestEntityModifierTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestEntityModifierTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestEntityModifierTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestEntityModifierTask.java Fri Aug 12 08:12:28 2005
@@ -1,67 +1,67 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.Vector;
-
-import org.apache.tools.ant.Task;
-
-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.TchUtils;
-
-public abstract class AbstractTestEntityModifierTask
- extends BaseTaskContainer
- implements ChildTask, TestEntityModifier
-{
- private Task parentTask = null;
-
- private String value = null;
-
- public Task handleTask(Task task)
- {
- task = super.handleTask(task);
- if (task instanceof ChildTask)
- {
- // we must be inside a test-unit-mod task, since only those are allowed
- // to wrap test-suite-call tasks (old way, still supported).
-
- // this sets the parent of the TestSuiteCallTask to the TestSuiteTask.
- ((ChildTask)task).setParentTask(parentTask);
- }
- if (task instanceof TestSuiteCallTask)
- {
- // Test suite call wraps the modifier. This is the newer way
- ((TestSuiteCallTask)task).setTestUnitModiferTask(
- (TestUnitModifierTask)this);
- }
- return task;
- }
-
- //ChildTask implementation.
-
- public void setParentTask(Task in)
- {
- //System.out.println("TUMT.setParentTask(): "+in.getClass().getName());
- parentTask = in;
- }
-
- //end ChildTask impl
-
- public void setValue(String inValue)
- {
- try
- {
- TchUtils.validateName(inValue);
- }
- catch (NonfatalValidationException ex)
- {
- //NonfatalValidationAggregate.addException(ex, getCallingChain());
- invalidate(ex);
- }
- value = inValue;
- }
-
- public String getValue()
- {
- return value;
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.Vector;
+
+import org.apache.tools.ant.Task;
+
+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.TchUtils;
+
+public abstract class AbstractTestEntityModifierTask
+ extends BaseTaskContainer
+ implements ChildTask, TestEntityModifier
+{
+ private Task parentTask = null;
+
+ private String value = null;
+
+ public Task handleTask(Task task)
+ {
+ task = super.handleTask(task);
+ if (task instanceof ChildTask)
+ {
+ // we must be inside a test-unit-mod task, since only those are allowed
+ // to wrap test-suite-call tasks (old way, still supported).
+
+ // this sets the parent of the TestSuiteCallTask to the TestSuiteTask.
+ ((ChildTask)task).setParentTask(parentTask);
+ }
+ if (task instanceof TestSuiteCallTask)
+ {
+ // Test suite call wraps the modifier. This is the newer way
+ ((TestSuiteCallTask)task).setTestUnitModiferTask(
+ (TestUnitModifierTask)this);
+ }
+ return task;
+ }
+
+ //ChildTask implementation.
+
+ public void setParentTask(Task in)
+ {
+ //System.out.println("TUMT.setParentTask(): "+in.getClass().getName());
+ parentTask = in;
+ }
+
+ //end ChildTask impl
+
+ public void setValue(String inValue)
+ {
+ try
+ {
+ TchUtils.validateName(inValue);
+ }
+ catch (NonfatalValidationException ex)
+ {
+ //NonfatalValidationAggregate.addException(ex, getCallingChain());
+ invalidate(ex);
+ }
+ value = inValue;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestEntityModifierTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestNodeTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestNodeTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestNodeTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestNodeTask.java Fri Aug 12 08:12:28 2005
@@ -1,632 +1,632 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.ArrayList;
-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 org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Task;
-
-import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
-import org.apache.beehive.test.tools.tch.core.configuration.ProcessManagementConfigurationException;
-import org.apache.beehive.test.tools.tch.core.process.Process;
-import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
-import org.apache.beehive.test.tools.tch.core.process.ProcessManager;
-import org.apache.beehive.test.tools.tch.core.process.ProcessOverride;
-import org.apache.beehive.test.tools.tch.core.process.ProcessRegistry;
-import org.apache.beehive.test.tools.tch.core.test.InternalParameters;
-import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
-import org.apache.beehive.test.tools.tch.extension.process.exec.ExecProcessManager;
-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.CollectionsUtil;
-import org.apache.beehive.test.tools.tch.util.TestResultAdapter;
-
-/**
- * Abstract base class in the test inheritance hierarchy which
- * provides the following test features:
- * <li>access to mapped processes
- * <li>access to process registry
- * <li>access to the test registry
- * <li>process overrides
- */
-public abstract class AbstractTestNodeTask
- extends AbstractMinimalTestNodeTask
- implements ProcessProvider
-{
- private TestMultiLevelHelper helper = new TestMultiLevelHelper();
-
- private TestRegistry testRegistry = TestRegistry.getRegistry();
-
- //private String testUnit = null;
-
- // Class (TestSuiteCallTaskProvider) -> String (cached test unit)
- private Map testUnitCache = new HashMap();
-
- // process overrides defined for the current test or test-suite
- private Map overrideMap = new HashMap();
-
- private boolean testUnitIsDefined = true;
-
- private Integer testTimeoutSeconds = null;
-
- private InternalParameters cachedParameters = null;
-
- /**
- * Hook called during task setup
- */
- public Task handleTask(Task task)
- {
- //Delegate most extra handling to the helper
- task = super.handleTask(task);
- task = getHelper().handleTask(task);
- //super.handleTask used to be here - any reason?
- // if (task instanceof AnythingTask)
- // {
- // ((AnythingTask)task).setTestNode(this);
- // }
- return task;
- }
-
- public void setTestUnit(String in)
- {
- if (in != null && in.equals(""))
- {
- in = null;
- }
- else
- validateName(in);
- getHelper().setTestUnit(in);
- }
-
- protected String getTestUnit(TestSuiteCallTaskProvider testSuiteCallTaskProvider) //don't bother to synchronize
- {
- String testUnit =
- (String)testUnitCache.get(testSuiteCallTaskProvider.getClass());
- if (testUnit == null && testUnitIsDefined)
- {
- testUnit = getHelper().getTestUnit();
- if (testUnit == null && hasTestParentInTestFile())
- {
- testUnit = getTestParent().getTestUnit(testSuiteCallTaskProvider);
- return testUnit;
- }
- TestSuiteCallTask call =
- testSuiteCallTaskProvider.getTestSuiteCallTask(this);
- if (call != null)
- testUnit =
- call.applyTestUnitModifier(testUnit, testSuiteCallTaskProvider);
- }
- return testUnit;
- }
-
- public void setTimeoutSeconds(String in)
- {
- String parseThis = handleValue(in);
- if (parseThis != null && !parseThis.equals("null"))
- {
- try
- {
- testTimeoutSeconds = new Integer(parseThis);
- }
- catch (NumberFormatException ex)
- {
- //VALIDATION EXCEPTION
- invalidate(
- new NonfatalValidationException(
- ErrorMessageConstants.INTEGER_PARSE_ERROR_CODE,
- ErrorMessageConstants.BROKEN_INT_VAL,
- parseThis));
- }
- }
- }
-
- public Integer getTestTimeoutSeconds()
- {
- if (testTimeoutSeconds != null)
- return testTimeoutSeconds;
- else
- if (hasTestParentInTestFile())
- return getTestParent().getTestTimeoutSeconds();
- else
- return null;
- }
-
- public InternalParameters getParametersAbove(InternalParameters params)
- {
- CollectionsUtil.putAllNoOverride(
- getHelper().getParameters().getProperties(),
- params.getProperties());
- if (hasTestParentInTestFile())
- return getTestParent().getParametersAbove(params);
- else
- return params;
- }
-
- protected InternalParameters getCachedParameters()
- {
- return cachedParameters;
- }
-
- protected void setCachedParameters(InternalParameters in)
- {
- cachedParameters = in;
- }
-
- //added in since the helper has props
-
- public Collection getUsedPropsAbove(Collection props)
- {
- props.addAll(getHelper().getUsedProps());
- return super.getUsedPropsAbove(props);
- }
-
- public void getUsedPropsBelow(Collection props)
- {
- props.addAll(getHelper().getUsedProps());
- super.getUsedPropsBelow(props);
- }
-
- //Recursion
-
-/**
- * Get all metadata tasks that apply to the current test.
- * Traverses up the test parent to get all metadata tasks defined at
- * the current level as well as at the parent scopes.
- */
- public List getMetadataTasks(List list)
- {
- if (getHelper().getMetadataTask() != null)
- list.add(getHelper().getMetadataTask());
- if (hasTestParentInTestFile())
- return getTestParent().getMetadataTasks(list);
- else
- return list;
- }
-
- public String getExplicitDefaultProcessName()
- {
- String name = getHelper().getDefaultProcessName();
- if (name == null)
- {
- if (hasTestParentInTestFile())
- name = getTestParent().getExplicitDefaultProcessName();
- }
- return name;
- }
-
- public String getLowestSingleProcessName()
- {
- String name = getHelper().getSingleProcessName();
- if (name == null)
- {
- if (hasTestParentInTestFile())
- name = getTestParent().getLowestSingleProcessName();
- }
- return name;
- }
-
- public final void logInform(String message)
- {
- logInform(message, getLocation());
- }
-
- public final void logInform(String message, Location location)
- {
- TestResultAdapter res =
- new TestResultAdapter(TchConstants.INFORM_LEVEL_INT);
- res.setOutputMsg(message);
- res.setSourcePath(AntUtils.getSourcePath(location));
- notifyOnResult(res);
- }
-
- public final void logInternal(String message)
- {
- TestResultAdapter res =
- new TestResultAdapter(TchConstants.INTERNAL_LEVEL_INT);
- res.setName("");
- res.setOutputMsg(message);
- res.setSourcePath(AntUtils.getSourcePath(getLocation()));
- notifyOnResult(res);
- }
-
- public final String getDefaultProcessName()
- {
- String name = getExplicitDefaultProcessName();
- if (name == null)
- {
- //This means nothing explicitly called as default
- //Check to see if just one process defined at any level
- name = getLowestSingleProcessName();
- if (name == null)
- {
- name = getHelper().getProcessRegistry().getImplicitProcessName();
- }
- }
- return name;
- }
-
- public void setDefaultProcessTask()
- throws ProcessManagementConfigurationException
- {
- getHelper().setDefaultProcessTask();
- if (hasTestParentInTestFile())
- getTestParent().setDefaultProcessTask();
- }
-
- //Another one moved up
-
- public ProcessRegistry getProcessRegistry()
- {
- return getHelper().getProcessRegistry();
- }
-
- //Other stuff
-
- public TestRegistry getTestRegistry()
- {
- return testRegistry;
- }
-
- public ProcessEngine getProcessEngine()
- {
- return getHelper().getProcessEngine();
- }
-
- public final Collection getProcessNames()
- {
- Collection rtn = new HashSet();
- for (Iterator iter = getAllProcessTasksAbove().iterator(); iter.hasNext();)
- {
- rtn.addAll(((ProcessTask)iter.next()).getNames());
- }
- return rtn;
- }
-
- /**
- * Return only the process tasks that are defined locally. We need
- * this for process overrides for scoping purposes
- * @return
- */
- protected Collection getAllLocalProcessTasks()
- {
- Collection rtn = new HashSet(getHelper().getProcessTasks());
- return rtn;
- }
-
- //only to be called if isLogicalTest()
- // returns ProcessTasks
- protected Collection getAllProcessTasks()
- {
- Collection rtn = new HashSet();
- rtn.addAll(getAllProcessTasksAbove());
-
- if (hasTestParentInTestFile())
- {
- rtn.addAll(getTestParent().getAllProcessTasksAbove());
- }
- return rtn;
- }
-
- /**
- * Returns all ProcessTasks which are defined in the current scope (not above or below)
- * @return list of ProcessTask objects
- */
- protected List getCurrentProcessTasksList()
- {
- List rtn = new ArrayList(getHelper().getProcessTasks());
- for (Iterator iter = rtn.iterator(); iter.hasNext();)
- {
- ProcessTask pt = (ProcessTask)iter.next();
- }
- return rtn;
- }
-
- /**
- * Returns all ProcessTasks which are defined at the test-suite level
- * @return list of ProcessTask objects
- */
- protected List getAllProcessTasksListAbove()
- {
- List rtn = new ArrayList();
- if (hasTestParentInTestFile())
- {
- rtn.addAll(getTestParent().getAllProcessTasksAbove());
- }
-
- for (Iterator iter = rtn.iterator(); iter.hasNext();)
- {
- ProcessTask pt = (ProcessTask)iter.next();
- }
- return rtn;
- }
-
- protected final Collection getAllActiveProcessHandlers()
- {
- Collection ret = new HashSet();
- for (Iterator iter = getAllProcessEntries().iterator(); iter.hasNext();)
- {
- ProcessRegistry.Entry entry = (ProcessRegistry.Entry)iter.next();
- Process proc = entry.getProcess();
- if (proc.isActive())
- {
- ret.add(entry.getProcessHandler());
- }
- }
- return ret;
- }
-
- /**
- * Gets all process entries for all proceses mapped to this test
- *
- * @return Collection of ProcessRegistry.Entry
- */
- protected final Collection getAllProcessEntries()
- {
- Collection ret = new HashSet();
- for (Iterator iter = getAllProcessNames().iterator(); iter.hasNext();)
- {
- ret.add(getProcessEntry((String)iter.next()));
- }
- return ret;
- }
-
- private ProcessRegistry.Entry getProcessEntry(String processName)
- {
- return getHelper().getProcessRegistry().getProcessEntryAssumeValidated(
- processName);
- }
-
- public Collection getAllProcessNames()
- {
- Collection rtn = new HashSet();
- for (Iterator iter = getAllProcessTasks().iterator(); iter.hasNext();)
- {
- rtn.addAll(((ProcessTask)iter.next()).getNames());
- }
- // check if default process is set
- if (rtn.isEmpty() && getDefaultProcessName() != null)
- {
- rtn.add(getDefaultProcessName());
- }
- return rtn;
- }
-
- public Collection getAllProcessTasksAbove()
- {
- Collection rtn = new HashSet(getHelper().getProcessTasks());
- if (hasTestParentInTestFile())
- {
- rtn.addAll(getTestParent().getAllProcessTasksAbove());
- }
- return rtn;
- }
-
- protected boolean preInitialize() throws BuildException
- {
- if (super.preInitialize())
- {
- if (!isTestNode() && getHelper().getTestUnit() != null)
- {
- //VALIDATION EXCEPTION
- invalidate(
- new NonfatalValidationException(
- ErrorMessageConstants.TEST_UNIT_AT_WRONG_LEVEL_ERROR_CODE));
- }
- return true;
- }
- else
- return false;
- }
-
- protected boolean initialize()
- {
- if (super.initialize())
- {
- if (!getHelper().getInvalidationManager().isValid())
- addInvalidations(
- getHelper()
- .getInvalidationManager()
- .getNonfatalValidationAggregate());
- return true;
- }
- return false;
- }
-
- protected boolean preRun()
- {
- if (super.preRun())
- {
- getHelper().setProcessEngine(this);
- return true;
- }
- return false;
- }
-
- protected void setTestUnitUndefined()
- {
- testUnitIsDefined = false;
- }
-
- protected boolean isTestUnitDefined()
- {
- return testUnitIsDefined;
- }
-
- /**
- * Retrives *all* the UnitConfigurationInfos from ProcessTasks anywhere in
- * scope returned in a Map (Process -> Collection of UnitConfigurationInfo)
- * This is for static configuration
- * Should only be called is isTopLevel()
- * <p>
- * Note this is not recursive so relies on getAllProcessTasks recursing
- */
- protected Map getAllUnitConfigurationInfo()
- {
- Map rtn = new HashMap();
- for (Iterator iter = getAllProcessTasks().iterator(); iter.hasNext();)
- {
- ProcessTask processTask = (ProcessTask)iter.next();
- Collection processes = processTask.getProcesses();
- Collection info = processTask.getAllUnitConfigurationInfo();
- for (Iterator processIter = processes.iterator(); processIter.hasNext();)
- {
- Process key = (Process)processIter.next();
- if (rtn.containsKey(key))
- {
- ((Collection)rtn.get(key)).addAll(info);
- }
- else
- {
- rtn.put(key, new HashSet(info));
- }
- }
- }
- return rtn;
- }
-
- /**
- * Get a map of process names -> ProcessOverride that is defined in the current test or test-unit.
- * This will only get the ones defined in the current scope.. not above or below
- */
- protected Map getCurrentProcessOverrides()
- {
- Map rtn = new HashMap();
-
- for (Iterator iter = getCurrentProcessTasksList().iterator();
- iter.hasNext();
- )
- {
- ProcessTask processTask = (ProcessTask)iter.next();
- Collection processes = processTask.getProcesses();
- Collection po_list = processTask.getAllProcessOverrides();
-
- for (Iterator processIter = processes.iterator(); processIter.hasNext();)
- {
- Process key = (Process)processIter.next();
- for (Iterator listIter = po_list.iterator(); listIter.hasNext();)
- {
- ProcessOverride po = (ProcessOverride)listIter.next();
- rtn.put(key.getName(), po);
- }
- }
- }
- return rtn;
- }
-
- /**
- * Get a map of process names -> ProcessOverride that are defined above the current test.
- */
- protected Map getProcessOverridesAbove()
- {
- Map rtn = new HashMap();
-
- for (Iterator iter = getAllProcessTasksListAbove().iterator();
- iter.hasNext();
- )
- {
- ProcessTask processTask = (ProcessTask)iter.next();
- Collection processes = processTask.getProcesses();
- Collection po_list = processTask.getAllProcessOverrides();
-
- for (Iterator processIter = processes.iterator(); processIter.hasNext();)
- {
- Process key = (Process)processIter.next();
- for (Iterator listIter = po_list.iterator(); listIter.hasNext();)
- {
- ProcessOverride po = (ProcessOverride)listIter.next();
- rtn.put(key.getName(), po);
- }
- }
- }
- return rtn;
- }
-
- private void validateName(String name)
- {
- try
- {
- TchUtils.validateName(name);
- }
- catch (NonfatalValidationException ex)
- {
- invalidate(ex);
- }
- }
-
- /**
- * Get the {@link TestMultiLevelHelper} associated with the current task
- *
- * @return
- */
- protected TestMultiLevelHelper getHelper()
- {
- return helper;
- }
-
- /**
- * Get a map of all process names -> {@link ProcessOverride}
- *
- * @return the process override map
- */
- public Map getProcessOverrideMap()
- {
- return overrideMap;
- }
-
- /**
- * Set the map of all process names -> {@link ProcessOverride)
- *
- * @param overrideMap the process override map
- */
- public void setProcessOverrideMap(Map overrideMap)
- {
- this.overrideMap = overrideMap;
- }
-
- /**
- * Write out the .cmd file for all processes which contain process overrides
- * defined at the current scope
- *
- * @param overrideMap map of process names -> ProcessOverride
- * @param cmdFileModifier suffix to add to the filename
- */
- public void writeProcessOverrideCmdFiles(
- Map overrideMap,
- String cmdFileModifier)
- {
- if (overrideMap == null)
- return;
- // Write out the
- for (Iterator iter = overrideMap.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iter.next();
- try
- {
- ProcessManager pm =
- getProcessRegistry()
- .getProcessEntryForTest((String)entry.getKey(), getName())
- .getProcessManager();
- Process p =
- getProcessRegistry()
- .getProcessEntryForTest((String)entry.getKey(), getName())
- .getProcess();
- p.setCmdFileModifier("_" + cmdFileModifier);
- if (pm instanceof ExecProcessManager)
- {
- ((ExecProcessManager)pm).writeOutCommandLine(p);
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.ArrayList;
+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 org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Task;
+
+import org.apache.beehive.test.tools.tch.core.configuration.NonfatalValidationException;
+import org.apache.beehive.test.tools.tch.core.configuration.ProcessManagementConfigurationException;
+import org.apache.beehive.test.tools.tch.core.process.Process;
+import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
+import org.apache.beehive.test.tools.tch.core.process.ProcessManager;
+import org.apache.beehive.test.tools.tch.core.process.ProcessOverride;
+import org.apache.beehive.test.tools.tch.core.process.ProcessRegistry;
+import org.apache.beehive.test.tools.tch.core.test.InternalParameters;
+import org.apache.beehive.test.tools.tch.core.test.TestRegistry;
+import org.apache.beehive.test.tools.tch.extension.process.exec.ExecProcessManager;
+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.CollectionsUtil;
+import org.apache.beehive.test.tools.tch.util.TestResultAdapter;
+
+/**
+ * Abstract base class in the test inheritance hierarchy which
+ * provides the following test features:
+ * <li>access to mapped processes
+ * <li>access to process registry
+ * <li>access to the test registry
+ * <li>process overrides
+ */
+public abstract class AbstractTestNodeTask
+ extends AbstractMinimalTestNodeTask
+ implements ProcessProvider
+{
+ private TestMultiLevelHelper helper = new TestMultiLevelHelper();
+
+ private TestRegistry testRegistry = TestRegistry.getRegistry();
+
+ //private String testUnit = null;
+
+ // Class (TestSuiteCallTaskProvider) -> String (cached test unit)
+ private Map testUnitCache = new HashMap();
+
+ // process overrides defined for the current test or test-suite
+ private Map overrideMap = new HashMap();
+
+ private boolean testUnitIsDefined = true;
+
+ private Integer testTimeoutSeconds = null;
+
+ private InternalParameters cachedParameters = null;
+
+ /**
+ * Hook called during task setup
+ */
+ public Task handleTask(Task task)
+ {
+ //Delegate most extra handling to the helper
+ task = super.handleTask(task);
+ task = getHelper().handleTask(task);
+ //super.handleTask used to be here - any reason?
+ // if (task instanceof AnythingTask)
+ // {
+ // ((AnythingTask)task).setTestNode(this);
+ // }
+ return task;
+ }
+
+ public void setTestUnit(String in)
+ {
+ if (in != null && in.equals(""))
+ {
+ in = null;
+ }
+ else
+ validateName(in);
+ getHelper().setTestUnit(in);
+ }
+
+ protected String getTestUnit(TestSuiteCallTaskProvider testSuiteCallTaskProvider) //don't bother to synchronize
+ {
+ String testUnit =
+ (String)testUnitCache.get(testSuiteCallTaskProvider.getClass());
+ if (testUnit == null && testUnitIsDefined)
+ {
+ testUnit = getHelper().getTestUnit();
+ if (testUnit == null && hasTestParentInTestFile())
+ {
+ testUnit = getTestParent().getTestUnit(testSuiteCallTaskProvider);
+ return testUnit;
+ }
+ TestSuiteCallTask call =
+ testSuiteCallTaskProvider.getTestSuiteCallTask(this);
+ if (call != null)
+ testUnit =
+ call.applyTestUnitModifier(testUnit, testSuiteCallTaskProvider);
+ }
+ return testUnit;
+ }
+
+ public void setTimeoutSeconds(String in)
+ {
+ String parseThis = handleValue(in);
+ if (parseThis != null && !parseThis.equals("null"))
+ {
+ try
+ {
+ testTimeoutSeconds = new Integer(parseThis);
+ }
+ catch (NumberFormatException ex)
+ {
+ //VALIDATION EXCEPTION
+ invalidate(
+ new NonfatalValidationException(
+ ErrorMessageConstants.INTEGER_PARSE_ERROR_CODE,
+ ErrorMessageConstants.BROKEN_INT_VAL,
+ parseThis));
+ }
+ }
+ }
+
+ public Integer getTestTimeoutSeconds()
+ {
+ if (testTimeoutSeconds != null)
+ return testTimeoutSeconds;
+ else
+ if (hasTestParentInTestFile())
+ return getTestParent().getTestTimeoutSeconds();
+ else
+ return null;
+ }
+
+ public InternalParameters getParametersAbove(InternalParameters params)
+ {
+ CollectionsUtil.putAllNoOverride(
+ getHelper().getParameters().getProperties(),
+ params.getProperties());
+ if (hasTestParentInTestFile())
+ return getTestParent().getParametersAbove(params);
+ else
+ return params;
+ }
+
+ protected InternalParameters getCachedParameters()
+ {
+ return cachedParameters;
+ }
+
+ protected void setCachedParameters(InternalParameters in)
+ {
+ cachedParameters = in;
+ }
+
+ //added in since the helper has props
+
+ public Collection getUsedPropsAbove(Collection props)
+ {
+ props.addAll(getHelper().getUsedProps());
+ return super.getUsedPropsAbove(props);
+ }
+
+ public void getUsedPropsBelow(Collection props)
+ {
+ props.addAll(getHelper().getUsedProps());
+ super.getUsedPropsBelow(props);
+ }
+
+ //Recursion
+
+/**
+ * Get all metadata tasks that apply to the current test.
+ * Traverses up the test parent to get all metadata tasks defined at
+ * the current level as well as at the parent scopes.
+ */
+ public List getMetadataTasks(List list)
+ {
+ if (getHelper().getMetadataTask() != null)
+ list.add(getHelper().getMetadataTask());
+ if (hasTestParentInTestFile())
+ return getTestParent().getMetadataTasks(list);
+ else
+ return list;
+ }
+
+ public String getExplicitDefaultProcessName()
+ {
+ String name = getHelper().getDefaultProcessName();
+ if (name == null)
+ {
+ if (hasTestParentInTestFile())
+ name = getTestParent().getExplicitDefaultProcessName();
+ }
+ return name;
+ }
+
+ public String getLowestSingleProcessName()
+ {
+ String name = getHelper().getSingleProcessName();
+ if (name == null)
+ {
+ if (hasTestParentInTestFile())
+ name = getTestParent().getLowestSingleProcessName();
+ }
+ return name;
+ }
+
+ public final void logInform(String message)
+ {
+ logInform(message, getLocation());
+ }
+
+ public final void logInform(String message, Location location)
+ {
+ TestResultAdapter res =
+ new TestResultAdapter(TchConstants.INFORM_LEVEL_INT);
+ res.setOutputMsg(message);
+ res.setSourcePath(AntUtils.getSourcePath(location));
+ notifyOnResult(res);
+ }
+
+ public final void logInternal(String message)
+ {
+ TestResultAdapter res =
+ new TestResultAdapter(TchConstants.INTERNAL_LEVEL_INT);
+ res.setName("");
+ res.setOutputMsg(message);
+ res.setSourcePath(AntUtils.getSourcePath(getLocation()));
+ notifyOnResult(res);
+ }
+
+ public final String getDefaultProcessName()
+ {
+ String name = getExplicitDefaultProcessName();
+ if (name == null)
+ {
+ //This means nothing explicitly called as default
+ //Check to see if just one process defined at any level
+ name = getLowestSingleProcessName();
+ if (name == null)
+ {
+ name = getHelper().getProcessRegistry().getImplicitProcessName();
+ }
+ }
+ return name;
+ }
+
+ public void setDefaultProcessTask()
+ throws ProcessManagementConfigurationException
+ {
+ getHelper().setDefaultProcessTask();
+ if (hasTestParentInTestFile())
+ getTestParent().setDefaultProcessTask();
+ }
+
+ //Another one moved up
+
+ public ProcessRegistry getProcessRegistry()
+ {
+ return getHelper().getProcessRegistry();
+ }
+
+ //Other stuff
+
+ public TestRegistry getTestRegistry()
+ {
+ return testRegistry;
+ }
+
+ public ProcessEngine getProcessEngine()
+ {
+ return getHelper().getProcessEngine();
+ }
+
+ public final Collection getProcessNames()
+ {
+ Collection rtn = new HashSet();
+ for (Iterator iter = getAllProcessTasksAbove().iterator(); iter.hasNext();)
+ {
+ rtn.addAll(((ProcessTask)iter.next()).getNames());
+ }
+ return rtn;
+ }
+
+ /**
+ * Return only the process tasks that are defined locally. We need
+ * this for process overrides for scoping purposes
+ * @return
+ */
+ protected Collection getAllLocalProcessTasks()
+ {
+ Collection rtn = new HashSet(getHelper().getProcessTasks());
+ return rtn;
+ }
+
+ //only to be called if isLogicalTest()
+ // returns ProcessTasks
+ protected Collection getAllProcessTasks()
+ {
+ Collection rtn = new HashSet();
+ rtn.addAll(getAllProcessTasksAbove());
+
+ if (hasTestParentInTestFile())
+ {
+ rtn.addAll(getTestParent().getAllProcessTasksAbove());
+ }
+ return rtn;
+ }
+
+ /**
+ * Returns all ProcessTasks which are defined in the current scope (not above or below)
+ * @return list of ProcessTask objects
+ */
+ protected List getCurrentProcessTasksList()
+ {
+ List rtn = new ArrayList(getHelper().getProcessTasks());
+ for (Iterator iter = rtn.iterator(); iter.hasNext();)
+ {
+ ProcessTask pt = (ProcessTask)iter.next();
+ }
+ return rtn;
+ }
+
+ /**
+ * Returns all ProcessTasks which are defined at the test-suite level
+ * @return list of ProcessTask objects
+ */
+ protected List getAllProcessTasksListAbove()
+ {
+ List rtn = new ArrayList();
+ if (hasTestParentInTestFile())
+ {
+ rtn.addAll(getTestParent().getAllProcessTasksAbove());
+ }
+
+ for (Iterator iter = rtn.iterator(); iter.hasNext();)
+ {
+ ProcessTask pt = (ProcessTask)iter.next();
+ }
+ return rtn;
+ }
+
+ protected final Collection getAllActiveProcessHandlers()
+ {
+ Collection ret = new HashSet();
+ for (Iterator iter = getAllProcessEntries().iterator(); iter.hasNext();)
+ {
+ ProcessRegistry.Entry entry = (ProcessRegistry.Entry)iter.next();
+ Process proc = entry.getProcess();
+ if (proc.isActive())
+ {
+ ret.add(entry.getProcessHandler());
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Gets all process entries for all proceses mapped to this test
+ *
+ * @return Collection of ProcessRegistry.Entry
+ */
+ protected final Collection getAllProcessEntries()
+ {
+ Collection ret = new HashSet();
+ for (Iterator iter = getAllProcessNames().iterator(); iter.hasNext();)
+ {
+ ret.add(getProcessEntry((String)iter.next()));
+ }
+ return ret;
+ }
+
+ private ProcessRegistry.Entry getProcessEntry(String processName)
+ {
+ return getHelper().getProcessRegistry().getProcessEntryAssumeValidated(
+ processName);
+ }
+
+ public Collection getAllProcessNames()
+ {
+ Collection rtn = new HashSet();
+ for (Iterator iter = getAllProcessTasks().iterator(); iter.hasNext();)
+ {
+ rtn.addAll(((ProcessTask)iter.next()).getNames());
+ }
+ // check if default process is set
+ if (rtn.isEmpty() && getDefaultProcessName() != null)
+ {
+ rtn.add(getDefaultProcessName());
+ }
+ return rtn;
+ }
+
+ public Collection getAllProcessTasksAbove()
+ {
+ Collection rtn = new HashSet(getHelper().getProcessTasks());
+ if (hasTestParentInTestFile())
+ {
+ rtn.addAll(getTestParent().getAllProcessTasksAbove());
+ }
+ return rtn;
+ }
+
+ protected boolean preInitialize() throws BuildException
+ {
+ if (super.preInitialize())
+ {
+ if (!isTestNode() && getHelper().getTestUnit() != null)
+ {
+ //VALIDATION EXCEPTION
+ invalidate(
+ new NonfatalValidationException(
+ ErrorMessageConstants.TEST_UNIT_AT_WRONG_LEVEL_ERROR_CODE));
+ }
+ return true;
+ }
+ else
+ return false;
+ }
+
+ protected boolean initialize()
+ {
+ if (super.initialize())
+ {
+ if (!getHelper().getInvalidationManager().isValid())
+ addInvalidations(
+ getHelper()
+ .getInvalidationManager()
+ .getNonfatalValidationAggregate());
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean preRun()
+ {
+ if (super.preRun())
+ {
+ getHelper().setProcessEngine(this);
+ return true;
+ }
+ return false;
+ }
+
+ protected void setTestUnitUndefined()
+ {
+ testUnitIsDefined = false;
+ }
+
+ protected boolean isTestUnitDefined()
+ {
+ return testUnitIsDefined;
+ }
+
+ /**
+ * Retrives *all* the UnitConfigurationInfos from ProcessTasks anywhere in
+ * scope returned in a Map (Process -> Collection of UnitConfigurationInfo)
+ * This is for static configuration
+ * Should only be called is isTopLevel()
+ * <p>
+ * Note this is not recursive so relies on getAllProcessTasks recursing
+ */
+ protected Map getAllUnitConfigurationInfo()
+ {
+ Map rtn = new HashMap();
+ for (Iterator iter = getAllProcessTasks().iterator(); iter.hasNext();)
+ {
+ ProcessTask processTask = (ProcessTask)iter.next();
+ Collection processes = processTask.getProcesses();
+ Collection info = processTask.getAllUnitConfigurationInfo();
+ for (Iterator processIter = processes.iterator(); processIter.hasNext();)
+ {
+ Process key = (Process)processIter.next();
+ if (rtn.containsKey(key))
+ {
+ ((Collection)rtn.get(key)).addAll(info);
+ }
+ else
+ {
+ rtn.put(key, new HashSet(info));
+ }
+ }
+ }
+ return rtn;
+ }
+
+ /**
+ * Get a map of process names -> ProcessOverride that is defined in the current test or test-unit.
+ * This will only get the ones defined in the current scope.. not above or below
+ */
+ protected Map getCurrentProcessOverrides()
+ {
+ Map rtn = new HashMap();
+
+ for (Iterator iter = getCurrentProcessTasksList().iterator();
+ iter.hasNext();
+ )
+ {
+ ProcessTask processTask = (ProcessTask)iter.next();
+ Collection processes = processTask.getProcesses();
+ Collection po_list = processTask.getAllProcessOverrides();
+
+ for (Iterator processIter = processes.iterator(); processIter.hasNext();)
+ {
+ Process key = (Process)processIter.next();
+ for (Iterator listIter = po_list.iterator(); listIter.hasNext();)
+ {
+ ProcessOverride po = (ProcessOverride)listIter.next();
+ rtn.put(key.getName(), po);
+ }
+ }
+ }
+ return rtn;
+ }
+
+ /**
+ * Get a map of process names -> ProcessOverride that are defined above the current test.
+ */
+ protected Map getProcessOverridesAbove()
+ {
+ Map rtn = new HashMap();
+
+ for (Iterator iter = getAllProcessTasksListAbove().iterator();
+ iter.hasNext();
+ )
+ {
+ ProcessTask processTask = (ProcessTask)iter.next();
+ Collection processes = processTask.getProcesses();
+ Collection po_list = processTask.getAllProcessOverrides();
+
+ for (Iterator processIter = processes.iterator(); processIter.hasNext();)
+ {
+ Process key = (Process)processIter.next();
+ for (Iterator listIter = po_list.iterator(); listIter.hasNext();)
+ {
+ ProcessOverride po = (ProcessOverride)listIter.next();
+ rtn.put(key.getName(), po);
+ }
+ }
+ }
+ return rtn;
+ }
+
+ private void validateName(String name)
+ {
+ try
+ {
+ TchUtils.validateName(name);
+ }
+ catch (NonfatalValidationException ex)
+ {
+ invalidate(ex);
+ }
+ }
+
+ /**
+ * Get the {@link TestMultiLevelHelper} associated with the current task
+ *
+ * @return
+ */
+ protected TestMultiLevelHelper getHelper()
+ {
+ return helper;
+ }
+
+ /**
+ * Get a map of all process names -> {@link ProcessOverride}
+ *
+ * @return the process override map
+ */
+ public Map getProcessOverrideMap()
+ {
+ return overrideMap;
+ }
+
+ /**
+ * Set the map of all process names -> {@link ProcessOverride)
+ *
+ * @param overrideMap the process override map
+ */
+ public void setProcessOverrideMap(Map overrideMap)
+ {
+ this.overrideMap = overrideMap;
+ }
+
+ /**
+ * Write out the .cmd file for all processes which contain process overrides
+ * defined at the current scope
+ *
+ * @param overrideMap map of process names -> ProcessOverride
+ * @param cmdFileModifier suffix to add to the filename
+ */
+ public void writeProcessOverrideCmdFiles(
+ Map overrideMap,
+ String cmdFileModifier)
+ {
+ if (overrideMap == null)
+ return;
+ // Write out the
+ for (Iterator iter = overrideMap.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ try
+ {
+ ProcessManager pm =
+ getProcessRegistry()
+ .getProcessEntryForTest((String)entry.getKey(), getName())
+ .getProcessManager();
+ Process p =
+ getProcessRegistry()
+ .getProcessEntryForTest((String)entry.getKey(), getName())
+ .getProcess();
+ p.setCmdFileModifier("_" + cmdFileModifier);
+ if (pm instanceof ExecProcessManager)
+ {
+ ((ExecProcessManager)pm).writeOutCommandLine(p);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestNodeTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReplicationTask.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReplicationTask.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReplicationTask.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReplicationTask.java Fri Aug 12 08:12:28 2005
@@ -1,160 +1,160 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.Properties;
-
-import org.apache.beehive.test.tools.tch.core.configuration.PropValueSubstitutionRegistry;
-import org.apache.beehive.test.tools.tch.util.TchUtils;
-import org.apache.beehive.test.tools.tch.util.PerThreadCache;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * Abstract base class in the test inheritence chain.
- * This class is meant to be extended by tests which require test
- * replication functionality. Basically, if the test can be run individually
- * using the test replication command line options, it should extend this
- * class. The class provides the following:
- * <li>generation of command line for rerunning the test
- * <li>
- */
-public abstract class AbstractTestReplicationTask extends AbstractTestNodeTask
-{
- private Properties propSnapshot = null;
- private Thread initialThread = null; //Thread of the execute() call
- private PerThreadCache perThreadCache = PerThreadCache.getInstance();
-
- protected boolean initialize()
- {
- if (super.initialize())
- {
- setInitialThread();
- //needed in case we are in individual test mode, idempotent
- setPropSnapshot();
- return true;
- }
- return false;
- }
-
- protected boolean preRun()
- {
- if (super.preRun())
- {
- setInitialThread();
- //needed in case we are in individual test mode, idempotent
- setPropSnapshot();
- return true;
- }
- return false;
- }
-
- private TestReplicationHelper getTestReplicationHelper(String fullName)
- {
- // this used to be a singleton. but full name changes now for every subtest name, so need to make new
- // one. this should be refactored so we can just call something like setTestName on a cached instance
- TestReplicationHelper testReplicationHelper =
- new TestReplicationHelper(
- getLocation(),
- getPropSnapshot(),
- getProject().getProperties(),
- getAllActiveProcessHandlers());
- testReplicationHelper.addTest(fullName, getUsedProps());
- return testReplicationHelper;
- }
-
- private Properties getPropSnapshot()
- {
- if (propSnapshot == null) //lazy init
- setPropSnapshot();
- return propSnapshot;
- }
-
- private void setInitialThread()
- {
- initialThread = Thread.currentThread();
- }
-
- private void setPropSnapshot()
- {
- //Go to the PerThreadCache and grab the right stuff (latest props)
- //Have to use referenced thread in case this is called from a remote
- //callback
- propSnapshot =
- (Properties)perThreadCache.getLast(Snapshot.PROPERTIES, initialThread);
- }
-
- private String getScriptReplicationCommandLine(String fullName)
- {
- return new TestCommandLineBuilder(getTestReplicationHelper(fullName))
- .getCommandLine();
- }
-
- public void populateCommandLine(String fullName, TestResultBean res)
- {
- String commandLine = getScriptReplicationCommandLine(fullName);
- if (AntProperties.isPropValSubstitutionEnabled())
- {
- res.setCommandLine(substitutePropValues(commandLine));
- if (AntProperties.isReplicationWinCmdlineEnabled())
- {
- res.setWinCommandLine(substitutePropValues(commandLine, true));
- }
- }
- else
- {
- res.setCommandLine(commandLine);
- }
- }
-
- private String getJavaReplicationCommandLine(String fullName)
- {
- return new TestCommandLineBuilder(getTestReplicationHelper(fullName))
- .getJavaCommandLine();
- }
-
- public void populateJavaCommandLine(String fullName, TestResultBean res)
- {
- String commandLine = getJavaReplicationCommandLine(fullName);
- if (AntProperties.isPropValSubstitutionEnabled())
- {
- res.setVerboseCommandLine(substitutePropValues(commandLine));
- if (AntProperties.isReplicationWinCmdlineEnabled())
- {
- res.setVerboseWinCommandLine(substitutePropValues(commandLine, true));
- }
- }
- else
- {
- res.setVerboseCommandLine(commandLine);
- }
- }
-
- public String getAntReplicationFile(String fullName)
- {
- // catching everything, we don't want problems
- // with ant-file-gen kill the run
- try
- {
- //AntFileBuilder builder =
- // new AntFileBuilder(getTestReplicationHelper(fullName));
- //return builder.getAntFile();
- throw new Exception("Not Supported");
- }
- catch (Throwable th)
- {
- return "Error generating ant file\n\n"
- + TchUtils.throwable2StackTrace(th);
- }
- }
-
- private String substitutePropValues(String in)
- {
- return substitutePropValues(in, false);
- }
-
- private String substitutePropValues(String in, boolean windows)
- {
- if (windows)
- return PropValueSubstitutionRegistry.getInstance().filterStringWin(in);
- else
- return PropValueSubstitutionRegistry.getInstance().filterStringUnix(in);
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.Properties;
+
+import org.apache.beehive.test.tools.tch.core.configuration.PropValueSubstitutionRegistry;
+import org.apache.beehive.test.tools.tch.util.TchUtils;
+import org.apache.beehive.test.tools.tch.util.PerThreadCache;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * Abstract base class in the test inheritence chain.
+ * This class is meant to be extended by tests which require test
+ * replication functionality. Basically, if the test can be run individually
+ * using the test replication command line options, it should extend this
+ * class. The class provides the following:
+ * <li>generation of command line for rerunning the test
+ * <li>
+ */
+public abstract class AbstractTestReplicationTask extends AbstractTestNodeTask
+{
+ private Properties propSnapshot = null;
+ private Thread initialThread = null; //Thread of the execute() call
+ private PerThreadCache perThreadCache = PerThreadCache.getInstance();
+
+ protected boolean initialize()
+ {
+ if (super.initialize())
+ {
+ setInitialThread();
+ //needed in case we are in individual test mode, idempotent
+ setPropSnapshot();
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean preRun()
+ {
+ if (super.preRun())
+ {
+ setInitialThread();
+ //needed in case we are in individual test mode, idempotent
+ setPropSnapshot();
+ return true;
+ }
+ return false;
+ }
+
+ private TestReplicationHelper getTestReplicationHelper(String fullName)
+ {
+ // this used to be a singleton. but full name changes now for every subtest name, so need to make new
+ // one. this should be refactored so we can just call something like setTestName on a cached instance
+ TestReplicationHelper testReplicationHelper =
+ new TestReplicationHelper(
+ getLocation(),
+ getPropSnapshot(),
+ getProject().getProperties(),
+ getAllActiveProcessHandlers());
+ testReplicationHelper.addTest(fullName, getUsedProps());
+ return testReplicationHelper;
+ }
+
+ private Properties getPropSnapshot()
+ {
+ if (propSnapshot == null) //lazy init
+ setPropSnapshot();
+ return propSnapshot;
+ }
+
+ private void setInitialThread()
+ {
+ initialThread = Thread.currentThread();
+ }
+
+ private void setPropSnapshot()
+ {
+ //Go to the PerThreadCache and grab the right stuff (latest props)
+ //Have to use referenced thread in case this is called from a remote
+ //callback
+ propSnapshot =
+ (Properties)perThreadCache.getLast(Snapshot.PROPERTIES, initialThread);
+ }
+
+ private String getScriptReplicationCommandLine(String fullName)
+ {
+ return new TestCommandLineBuilder(getTestReplicationHelper(fullName))
+ .getCommandLine();
+ }
+
+ public void populateCommandLine(String fullName, TestResultBean res)
+ {
+ String commandLine = getScriptReplicationCommandLine(fullName);
+ if (AntProperties.isPropValSubstitutionEnabled())
+ {
+ res.setCommandLine(substitutePropValues(commandLine));
+ if (AntProperties.isReplicationWinCmdlineEnabled())
+ {
+ res.setWinCommandLine(substitutePropValues(commandLine, true));
+ }
+ }
+ else
+ {
+ res.setCommandLine(commandLine);
+ }
+ }
+
+ private String getJavaReplicationCommandLine(String fullName)
+ {
+ return new TestCommandLineBuilder(getTestReplicationHelper(fullName))
+ .getJavaCommandLine();
+ }
+
+ public void populateJavaCommandLine(String fullName, TestResultBean res)
+ {
+ String commandLine = getJavaReplicationCommandLine(fullName);
+ if (AntProperties.isPropValSubstitutionEnabled())
+ {
+ res.setVerboseCommandLine(substitutePropValues(commandLine));
+ if (AntProperties.isReplicationWinCmdlineEnabled())
+ {
+ res.setVerboseWinCommandLine(substitutePropValues(commandLine, true));
+ }
+ }
+ else
+ {
+ res.setVerboseCommandLine(commandLine);
+ }
+ }
+
+ public String getAntReplicationFile(String fullName)
+ {
+ // catching everything, we don't want problems
+ // with ant-file-gen kill the run
+ try
+ {
+ //AntFileBuilder builder =
+ // new AntFileBuilder(getTestReplicationHelper(fullName));
+ //return builder.getAntFile();
+ throw new Exception("Not Supported");
+ }
+ catch (Throwable th)
+ {
+ return "Error generating ant file\n\n"
+ + TchUtils.throwable2StackTrace(th);
+ }
+ }
+
+ private String substitutePropValues(String in)
+ {
+ return substitutePropValues(in, false);
+ }
+
+ private String substitutePropValues(String in, boolean windows)
+ {
+ if (windows)
+ return PropValueSubstitutionRegistry.getInstance().filterStringWin(in);
+ else
+ return PropValueSubstitutionRegistry.getInstance().filterStringUnix(in);
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReplicationTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReproducer.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReproducer.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReproducer.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReproducer.java Fri Aug 12 08:12:28 2005
@@ -1,55 +1,55 @@
-package org.apache.beehive.test.tools.tch.core;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- */
-abstract class AbstractTestReproducer
-{
- private TestReplicationHelper helper = null;
-
- public AbstractTestReproducer(TestReplicationHelper in)
- {
- helper = in;
- }
-
- protected String getBuildfile()
- {
- return helper.getBuildfile();
- }
-
- protected String getTestNamesValue()
- {
- return helper.getTestNamesValue();
- }
-
- protected Map resolveProperties()
- {
- return helper.resolveProperties();
- }
-
- protected Map getAllProperties()
- {
- return helper.getAllProperties();
- }
-
- protected Map getAllProperties(Map specialProperties, Collection exclusions)
- {
- return helper.getAllProperties(specialProperties, exclusions);
- }
-
- protected void addAllProperties(
- StringBuffer sb,
- Map specialProperties,
- Collection exclusions)
- {
- helper.addAllProperties(sb, specialProperties, exclusions);
- }
-
- protected Collection getProcessHandlers()
- {
- return helper.getProcessHandlers();
- }
-}
+package org.apache.beehive.test.tools.tch.core;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ */
+abstract class AbstractTestReproducer
+{
+ private TestReplicationHelper helper = null;
+
+ public AbstractTestReproducer(TestReplicationHelper in)
+ {
+ helper = in;
+ }
+
+ protected String getBuildfile()
+ {
+ return helper.getBuildfile();
+ }
+
+ protected String getTestNamesValue()
+ {
+ return helper.getTestNamesValue();
+ }
+
+ protected Map resolveProperties()
+ {
+ return helper.resolveProperties();
+ }
+
+ protected Map getAllProperties()
+ {
+ return helper.getAllProperties();
+ }
+
+ protected Map getAllProperties(Map specialProperties, Collection exclusions)
+ {
+ return helper.getAllProperties(specialProperties, exclusions);
+ }
+
+ protected void addAllProperties(
+ StringBuffer sb,
+ Map specialProperties,
+ Collection exclusions)
+ {
+ helper.addAllProperties(sb, specialProperties, exclusions);
+ }
+
+ protected Collection getProcessHandlers()
+ {
+ return helper.getProcessHandlers();
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/AbstractTestReproducer.java
------------------------------------------------------------------------------
svn:eol-style = native