custom Printer per SMTestProxy instance and its children

This commit is contained in:
Sergey Simonchik
2012-06-14 18:26:46 +04:00
parent 72829c458c
commit 23fa1f8ee7
10 changed files with 131 additions and 13 deletions
@@ -90,7 +90,8 @@ public class SMTestRunnerConnectionUtil {
runnerSettings,
configurationSettings,
new CompositeTestLocationProvider(locator),
false);
false,
null);
}
public static SMTRunnerConsoleView createConsoleWithCustomLocator(@NotNull final String testFrameworkName,
@@ -98,7 +99,8 @@ public class SMTestRunnerConnectionUtil {
final RunnerSettings runnerSettings,
final ConfigurationPerRunnerSettings configurationSettings,
@Nullable final TestLocationProvider locator,
final boolean idBasedTreeConstruction) {
final boolean idBasedTreeConstruction,
@Nullable final TestProxyPrinterProvider printerProvider) {
// Console
final String splitterPropertyName = testFrameworkName + ".Splitter.Proportion";
final SMTRunnerConsoleView console =
@@ -109,7 +111,8 @@ public class SMTestRunnerConnectionUtil {
super.attachToProcess(processHandler);
attachEventsProcessors(consoleProperties, getResultsViewer(),
getResultsViewer().getStatisticsPane(),
processHandler, testFrameworkName, locator, idBasedTreeConstruction);
processHandler, testFrameworkName, locator, idBasedTreeConstruction,
printerProvider);
}
};
console.setHelpId("reference.runToolWindow.testResultsTab");
@@ -213,7 +216,8 @@ public class SMTestRunnerConnectionUtil {
final ProcessHandler processHandler,
@NotNull final String testFrameworkName,
@Nullable final TestLocationProvider locator,
boolean idBasedTreeConstruction) {
boolean idBasedTreeConstruction,
@Nullable TestProxyPrinterProvider printerProvider) {
//build messages consumer
final OutputToGeneralTestEventsConverter outputConsumer;
if (consoleProperties instanceof SMCustomMessagesParsing) {
@@ -233,6 +237,9 @@ public class SMTestRunnerConnectionUtil {
if (locator != null) {
eventsProcessor.setLocator(locator);
}
if (printerProvider != null) {
eventsProcessor.setPrinterProvider(printerProvider);
}
// ui actions
final SMTRunnerUIActionsHandler uiActionsHandler = new SMTRunnerUIActionsHandler(consoleProperties);
@@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.testframework.sm.SMRunnerUtil;
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
import com.intellij.execution.testframework.sm.runner.events.*;
@@ -48,6 +49,7 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven
private final String myTestFrameworkName;
private boolean myIsTestingFinished = false;
private TestLocationProvider myLocator = null;
private TestProxyPrinterProvider myTestProxyPrinterProvider = null;
public GeneralIdBasedToSMTRunnerEventsConvertor(@NotNull SMTestProxy.SMRootTestProxy testsRootProxy,
@NotNull String testFrameworkName) {
@@ -112,6 +114,11 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven
});
}
@Override
public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) {
myTestProxyPrinterProvider = printerProvider;
}
public void onTestStarted(@NotNull final TestStartedEvent testStartedEvent) {
SMRunnerUtil.addToInvokeLater(new Runnable() {
public void run() {
@@ -145,6 +152,14 @@ public class GeneralIdBasedToSMTRunnerEventsConvertor implements GeneralTestEven
}
SMTestProxy childProxy = new SMTestProxy(startedNodeEvent.getName(), suite, startedNodeEvent.getLocationUrl(), true);
TestProxyPrinterProvider printerProvider = myTestProxyPrinterProvider;
String nodeType = startedNodeEvent.getNodeType();
if (printerProvider != null && nodeType != null) {
Printer printer = printerProvider.getPrinterByType(nodeType, startedNodeEvent.getNodeArgs());
if (printer != null) {
childProxy.setPreferredPrinter(printer);
}
}
childNode = new Node(startedNodeEvent.getId(), parentNode, childProxy);
myNodeByIdMap.put(nodeId, childNode);
myRunningNodes.add(childNode);
@@ -74,4 +74,6 @@ public interface GeneralTestEventsProcessor extends Disposable {
void addEventsListener(@NotNull SMTRunnerEventsListener viewer);
void onFinishTesting();
void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider);
}
@@ -113,6 +113,10 @@ public class GeneralToSMTRunnerEventsConvertor implements GeneralTestEventsProce
});
}
@Override
public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) {
}
public void onTestStarted(@NotNull final TestStartedEvent testStartedEvent) {
SMRunnerUtil.addToInvokeLater(new Runnable() {
public void run() {
@@ -60,6 +60,7 @@ public class SMTestProxy extends AbstractTestProxy {
private boolean myIsEmpty = true;
TestLocationProvider myLocator = null;
private final boolean myPreservePresentableName;
private Printer myPreferredPrinter = null;
public SMTestProxy(final String testName, final boolean isSuite,
@Nullable final String locationUrl) {
@@ -79,6 +80,10 @@ public class SMTestProxy extends AbstractTestProxy {
myLocator = locator;
}
public void setPreferredPrinter(@NotNull Printer preferredPrinter) {
myPreferredPrinter = preferredPrinter;
}
public boolean isInProgress() {
//final SMTestProxy parent = getParent();
@@ -172,8 +177,24 @@ public class SMTestProxy extends AbstractTestProxy {
// if parent is being printed then all childs output
// should be also send to the same printer
child.setPrinter(myPrinter);
if (myPreferredPrinter != null && child.myPreferredPrinter == null) {
child.setPreferredPrinter(myPreferredPrinter);
}
}
@Nullable
private Printer getRightPrinter(@Nullable Printer printer) {
if (myPreferredPrinter != null && printer != null) {
return myPreferredPrinter;
}
return printer;
}
public void setPrinter(Printer printer) {
super.setPrinter(getRightPrinter(printer));
}
public String getName() {
return myName;
}
@@ -397,13 +418,14 @@ public class SMTestProxy extends AbstractTestProxy {
* @param printer Printer
*/
public void printOn(final Printer printer) {
super.printOn(printer);
final Printer rightPrinter = getRightPrinter(printer);
super.printOn(rightPrinter);
invokeInAlarm(new Runnable() {
@Override
public void run() {
//Tests State, that provide and formats additional output
myState.printOn(printer);
myState.printOn(rightPrinter);
}
});
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.testframework.sm.runner;
import com.intellij.execution.testframework.Printer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Sergey Simonchik
*/
public interface TestProxyPrinterProvider {
@Nullable
Printer getPrinterByType(@NotNull String nodeType, @Nullable String arguments);
}
@@ -26,14 +26,20 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent {
private final int myParentId;
private final String myLocationUrl;
private final String myNodeType;
private final String myNodeArgs;
protected BaseStartedNodeEvent(@NotNull String name,
int id,
int parentId,
@Nullable final String locationUrl) {
@Nullable final String locationUrl,
@Nullable String nodeType,
@Nullable String nodeArgs) {
super(name, id);
myParentId = parentId;
myLocationUrl = locationUrl;
myNodeType = nodeType;
myNodeArgs = nodeArgs;
validate();
}
@@ -58,6 +64,16 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent {
return myLocationUrl;
}
@Nullable
public String getNodeType() {
return myNodeType;
}
@Nullable
public String getNodeArgs() {
return myNodeArgs;
}
@Override
protected void appendToStringInfo(@NotNull StringBuilder buf) {
append(buf, "parentId", myParentId);
@@ -68,4 +84,14 @@ public abstract class BaseStartedNodeEvent extends TreeNodeEvent {
return TreeNodeEvent.getIntAttribute(message, "parentNodeId");
}
@Nullable
public static String getNodeType(@NotNull MessageWithAttributes message) {
return message.getAttributes().get("nodeType");
}
@Nullable
public static String getNodeArgs(@NotNull MessageWithAttributes message) {
return message.getAttributes().get("nodeArgs");
}
}
@@ -26,11 +26,15 @@ public class TestStartedEvent extends BaseStartedNodeEvent {
public TestStartedEvent(@NotNull TestStarted testStarted,
@Nullable String locationUrl) {
super(testStarted.getTestName(), TreeNodeEvent.getNodeId(testStarted),
getParentNodeId(testStarted), locationUrl);
super(testStarted.getTestName(),
TreeNodeEvent.getNodeId(testStarted),
getParentNodeId(testStarted),
locationUrl,
BaseStartedNodeEvent.getNodeType(testStarted),
BaseStartedNodeEvent.getNodeArgs(testStarted));
}
public TestStartedEvent(@NotNull String name, @Nullable String locationUrl) {
super(name, -1, -1, locationUrl);
super(name, -1, -1, locationUrl, null, null);
}
}
@@ -26,12 +26,16 @@ public class TestSuiteStartedEvent extends BaseStartedNodeEvent {
public TestSuiteStartedEvent(@NotNull TestSuiteStarted suiteStarted,
@Nullable String locationUrl) {
super(suiteStarted.getSuiteName(), TreeNodeEvent.getNodeId(suiteStarted),
getParentNodeId(suiteStarted), locationUrl);
super(suiteStarted.getSuiteName(),
TreeNodeEvent.getNodeId(suiteStarted),
getParentNodeId(suiteStarted),
locationUrl,
BaseStartedNodeEvent.getNodeType(suiteStarted),
BaseStartedNodeEvent.getNodeArgs(suiteStarted));
}
public TestSuiteStartedEvent(@NotNull String name, @Nullable String locationUrl) {
super(name, -1, -1, locationUrl);
super(name, -1, -1, locationUrl, null, null);
}
}
@@ -100,6 +100,10 @@ public class MockGeneralTestEventsProcessorAdapter implements GeneralTestEventsP
public void onFinishTesting() {
}
@Override
public void setPrinterProvider(@NotNull TestProxyPrinterProvider printerProvider) {
}
@Override
public void dispose() {
myOutputBuffer.setLength(0);