(mostly saving progress) provide on-line results for testng tests, requires testng built from https://github.com/lukasj/testng
1.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/AntSessionInfo.java Sun Oct 30 22:14:10 2011 +0100
1.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/AntSessionInfo.java Thu Nov 10 15:48:37 2011 +0100
1.3 @@ -60,6 +60,9 @@
1.4 */
1.5 private SessionType sessionType;
1.6
1.7 + /** Suite name, defaults to "Ant suite" */
1.8 + private String sessionName = "Ant suite";
1.9 +
1.10 /**
1.11 */
1.12 AntSessionInfo() {
1.13 @@ -90,4 +93,13 @@
1.14 void setSessionType(SessionType sessionType) {
1.15 this.sessionType = sessionType;
1.16 }
1.17 +
1.18 + String getSessionName() {
1.19 + return sessionName;
1.20 + }
1.21 +
1.22 + void setSessionName(String sessionName) {
1.23 + this.sessionName = sessionName;
1.24 + }
1.25 +
1.26 }
2.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/JumpAction.java Sun Oct 30 22:14:10 2011 +0100
2.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/JumpAction.java Thu Nov 10 15:48:37 2011 +0100
2.3 @@ -69,12 +69,12 @@
2.4 * tries to jump to the callstack frame source code. Otherwise does nothing.
2.5 */
2.6 public void actionPerformed(ActionEvent e) {
2.7 - if (node instanceof TestsuiteNode){
2.8 - OutputUtils.openTestsuite((TestsuiteNode)node);
2.9 + if (node instanceof TestNGSuiteNode){
2.10 + OutputUtils.openTestsuite((TestNGSuiteNode)node);
2.11 } else if (node instanceof CallstackFrameNode){
2.12 OutputUtils.openCallstackFrame(node, callstackFrameInfo);
2.13 - } else if (node instanceof TestMethodNode){
2.14 - OutputUtils.openTestMethod((TestMethodNode)node);
2.15 + } else if (node instanceof TestNGMethodNode){
2.16 + OutputUtils.openTestMethod((TestNGMethodNode)node);
2.17 }
2.18 }
2.19
3.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/OutputUtils.java Sun Oct 30 22:14:10 2011 +0100
3.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/OutputUtils.java Thu Nov 10 15:48:37 2011 +0100
3.3 @@ -80,7 +80,7 @@
3.4 private OutputUtils() {
3.5 }
3.6
3.7 - static void openTestsuite(TestsuiteNode node) {
3.8 + static void openTestsuite(TestNGSuiteNode node) {
3.9 TestSuite suite = node.getSuite();
3.10 if ((suite != null) && (suite instanceof TestSuite)) {
3.11 final FileObject fo = ((TestNGTestSuite) suite).getSuiteFO();
3.12 @@ -116,7 +116,7 @@
3.13 }
3.14 }
3.15
3.16 - static void openTestMethod(final TestMethodNode node) {
3.17 + static void openTestMethod(final TestNGMethodNode node) {
3.18 final FileObject fo = node.getTestcase().getClassFileObject();
3.19 if (fo != null) {
3.20 final long[] line = new long[]{0};
3.21 @@ -156,7 +156,7 @@
3.22 }
3.23
3.24 static void openCallstackFrame(Node node, String frameInfo) {
3.25 - TestMethodNode methodNode = getTestMethodNode(node);
3.26 + TestNGMethodNode methodNode = getTestMethodNode(node);
3.27 FileLocator locator = methodNode.getTestcase().getSession().getFileLocator();
3.28 if (locator == null) {
3.29 return;
3.30 @@ -190,11 +190,11 @@
3.31
3.32 /**
3.33 */
3.34 - private static TestMethodNode getTestMethodNode(Node node) {
3.35 - while (!(node instanceof TestMethodNode)) {
3.36 + private static TestNGMethodNode getTestMethodNode(Node node) {
3.37 + while (!(node instanceof TestNGMethodNode)) {
3.38 node = node.getParentNode();
3.39 }
3.40 - return (TestMethodNode) node;
3.41 + return (TestNGMethodNode) node;
3.42 }
3.43
3.44 /**
4.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/RegexpPatterns.java Sun Oct 30 22:14:10 2011 +0100
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,69 +0,0 @@
4.4 -/*
4.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 - *
4.7 - * Copyright © 1997-2011 Oracle and/or its affiliates. Inc. All rights reserved.
4.8 - *
4.9 - * The contents of this file are subject to the terms of either the GNU
4.10 - * General Public License Version 2 only ("GPL") or the Common
4.11 - * Development and Distribution License("CDDL") (collectively, the
4.12 - * "License"). You may not use this file except in compliance with the
4.13 - * License. You can obtain a copy of the License at
4.14 - * http://www.netbeans.org/cddl-gplv2.html
4.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.16 - * specific language governing permissions and limitations under the
4.17 - * License. When distributing the software, include this License Header
4.18 - * Notice in each file and include the License file at
4.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
4.20 - * particular file as subject to the "Classpath" exception as provided
4.21 - * by Sun in the GPL Version 2 section of the License file that
4.22 - * accompanied this code. If applicable, add the following below the
4.23 - * License Header, with the fields enclosed by brackets [] replaced by
4.24 - * your own identifying information:
4.25 - * "Portions Copyrighted [year] [name of copyright owner]"
4.26 - *
4.27 - * Contributor(s):
4.28 - *
4.29 - * The Original Software is NetBeans. The Initial Developer of the Original
4.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
4.31 - * Microsystems, Inc. All Rights Reserved.
4.32 - *
4.33 - * If you wish your version of this file to be governed by only the CDDL
4.34 - * or only the GPL Version 2, indicate your decision by adding
4.35 - * "[Contributor] elects to include this software in this distribution
4.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.37 - * single choice of license, a recipient has the option to distribute
4.38 - * your version of this file under either the CDDL, the GPL Version 2 or
4.39 - * to extend the choice of license to its licensees as provided above.
4.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
4.41 - * Version 2 license, then the option applies only if the new code is
4.42 - * made subject to such option by the copyright holder.
4.43 - */
4.44 -
4.45 -package org.netbeans.modules.contrib.testng.output;
4.46 -
4.47 -/**
4.48 - * Collection of basic regex patterns for matching Java identifiers.
4.49 - *
4.50 - * @author Marian Petras
4.51 - */
4.52 -public final class RegexpPatterns {
4.53 -
4.54 - /** */
4.55 - private static final String JAVA_ID_START_REGEX
4.56 - = "\\p{javaJavaIdentifierStart}"; //NOI18N
4.57 - /** */
4.58 - private static final String JAVA_ID_PART_REGEX
4.59 - = "\\p{javaJavaIdentifierPart}"; //NOI18N
4.60 - /** */
4.61 - public static final String JAVA_ID_REGEX
4.62 - = "(?:" + JAVA_ID_START_REGEX + ')' + //NOI18N
4.63 - "(?:" + JAVA_ID_PART_REGEX + ")*"; //NOI18N
4.64 - /** */
4.65 - public static final String JAVA_ID_REGEX_FULL
4.66 - = JAVA_ID_REGEX + "(?:\\." + JAVA_ID_REGEX + ")*"; //NOI18N
4.67 -
4.68 - /** Creates a new instance of RegexpPatterns */
4.69 - private RegexpPatterns() {
4.70 - }
4.71 -
4.72 -}
5.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/RegexpUtils.java Sun Oct 30 22:14:10 2011 +0100
5.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/RegexpUtils.java Thu Nov 10 15:48:37 2011 +0100
5.3 @@ -52,6 +52,24 @@
5.4 */
5.5 final class RegexpUtils {
5.6
5.7 +/** */
5.8 + private static final String JAVA_ID_START_REGEX
5.9 + = "\\p{javaJavaIdentifierStart}"; //NOI18N
5.10 + /** */
5.11 + private static final String JAVA_ID_PART_REGEX
5.12 + = "\\p{javaJavaIdentifierPart}"; //NOI18N
5.13 + /** */
5.14 + public static final String JAVA_ID_REGEX
5.15 + = "(?:" + JAVA_ID_START_REGEX + ')' + //NOI18N
5.16 + "(?:" + JAVA_ID_PART_REGEX + ")*"; //NOI18N
5.17 + /** */
5.18 + public static final String JAVA_ID_REGEX_FULL
5.19 + = JAVA_ID_REGEX + "(?:\\." + JAVA_ID_REGEX + ")*"; //NOI18N
5.20 +
5.21 + static final String RUNNING_SUITE_REGEX = "[^\"]*\"([^\"]+)\" [a-z]+ \"(\\d+)\"[^:]*: ([^\\)]*)\\)";
5.22 + static final String TEST_REGEX = "[^\"]*\"([^\"]+)\" - ([^\\(]+)\\(([^\\)]*)\\)([^:]+: (.*)\\))?";
5.23 + static final String STATS_REGEX = "\\D+(\\d+)\\D+(\\d+)(\\D+(\\d+))?";
5.24 +
5.25 /** */
5.26 static final String TESTSUITE_PREFIX = "[TestNGAntTask]";//"Testsuite: "; //NOI18N
5.27 /** */
5.28 @@ -84,16 +102,16 @@
5.29 = "\\p{Blank}*(?:(FAILED) *|(?i:.*\\berror\\b.*))"; //NOI18N
5.30 /** */
5.31 static final String TESTCASE_HEADER_PLAIN_REGEX
5.32 - = "\\p{Blank}*(" + RegexpPatterns.JAVA_ID_REGEX //NOI18N
5.33 + = "\\p{Blank}*(" + JAVA_ID_REGEX //NOI18N
5.34 + ")\\p{Blank}+took\\p{Blank}+(.+)" + SECONDS_REGEX; //NOI18N
5.35 /** */
5.36 static final String TESTCASE_HEADER_BRIEF_REGEX
5.37 - = "\\p{Blank}*(" + RegexpPatterns.JAVA_ID_REGEX //NOI18N
5.38 - + ") *\\( *(" + RegexpPatterns.JAVA_ID_REGEX_FULL //NOI18N
5.39 + = "\\p{Blank}*(" + JAVA_ID_REGEX //NOI18N
5.40 + + ") *\\( *(" + JAVA_ID_REGEX_FULL //NOI18N
5.41 + ") *\\) *:" + TESTCASE_ISSUE_REGEX; //NOI18N
5.42 /** */
5.43 static final String TESTCASE_EXCEPTION_REGEX
5.44 - = "((?:" + RegexpPatterns.JAVA_ID_REGEX_FULL //NOI18N
5.45 + = "((?:" + JAVA_ID_REGEX_FULL //NOI18N
5.46 + "\\.?(?:Exception|Error|ComparisonFailure))" //NOI18N
5.47 + "|java\\.lang\\.Throwable)" //NOI18N
5.48 + "(?: *: *(.*))?"; //NOI18N
5.49 @@ -105,16 +123,16 @@
5.50 static final String CALLSTACK_LINE_REGEX
5.51 = "(?:\\t\\t?| +| *\\t? *\\[catch\\] )" //NOI18N
5.52 + CALLSTACK_LINE_PREFIX
5.53 - + RegexpPatterns.JAVA_ID_REGEX + "(?:\\." //NOI18N
5.54 - + RegexpPatterns.JAVA_ID_REGEX + ")+" //NOI18N
5.55 + + JAVA_ID_REGEX + "(?:\\." //NOI18N
5.56 + + JAVA_ID_REGEX + ")+" //NOI18N
5.57 + "(?: ?\\([^()]+\\))?"; //NOI18N
5.58 /** */
5.59 static final String NESTED_EXCEPTION_PREFIX = "Caused by: "; //NOI18N
5.60 /** */
5.61 static final String NESTED_EXCEPTION_REGEX
5.62 - = "(" + RegexpPatterns.JAVA_ID_REGEX_FULL + ")(?:: (.*))?";//NOI18N
5.63 + = "(" + JAVA_ID_REGEX_FULL + ")(?:: (.*))?";//NOI18N
5.64 static final String LOCATION_IN_FILE_REGEX
5.65 - = RegexpPatterns.JAVA_ID_REGEX_FULL + "(?:\\:[0-9]+)?"; //NOI18N
5.66 + = JAVA_ID_REGEX_FULL + "(?:\\:[0-9]+)?"; //NOI18N
5.67 /** */
5.68 static final String XML_DECL_PREFIX = "<?xml"; //NOI18N
5.69 /** */
5.70 @@ -143,7 +161,7 @@
5.71
5.72 /** */
5.73 static final String TEST_LISTENER_PREFIX
5.74 - = "junit.framework.TestListener: "; //NOI18N
5.75 + = "[NBTestListener] "; //NOI18N
5.76 /** */
5.77 static final String TESTS_COUNT_PREFIX = "tests to run: "; //NOI18N
5.78 /** */
5.79 @@ -225,7 +243,7 @@
5.80 Pattern getFullJavaIdPattern() {
5.81 if (fullJavaIdPattern == null) {
5.82 fullJavaIdPattern
5.83 - = Pattern.compile(RegexpPatterns.JAVA_ID_REGEX_FULL);
5.84 + = Pattern.compile(JAVA_ID_REGEX_FULL);
5.85 }
5.86 return fullJavaIdPattern;
5.87 }
6.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestMethodNode.java Sun Oct 30 22:14:10 2011 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,107 +0,0 @@
6.4 -/*
6.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6.6 - *
6.7 - * Copyright © 1997-2011 Oracle and/or its affiliates. All rights reserved.
6.8 - *
6.9 - * The contents of this file are subject to the terms of either the GNU
6.10 - * General Public License Version 2 only ("GPL") or the Common
6.11 - * Development and Distribution License("CDDL") (collectively, the
6.12 - * "License"). You may not use this file except in compliance with the
6.13 - * License. You can obtain a copy of the License at
6.14 - * http://www.netbeans.org/cddl-gplv2.html
6.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
6.16 - * specific language governing permissions and limitations under the
6.17 - * License. When distributing the software, include this License Header
6.18 - * Notice in each file and include the License file at
6.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
6.20 - * particular file as subject to the "Classpath" exception as provided
6.21 - * by Sun in the GPL Version 2 section of the License file that
6.22 - * accompanied this code. If applicable, add the following below the
6.23 - * License Header, with the fields enclosed by brackets [] replaced by
6.24 - * your own identifying information:
6.25 - * "Portions Copyrighted [year] [name of copyright owner]"
6.26 - *
6.27 - * Contributor(s):
6.28 - *
6.29 - * The Original Software is NetBeans. The Initial Developer of the Original
6.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
6.31 - * Microsystems, Inc. All Rights Reserved.
6.32 - *
6.33 - * If you wish your version of this file to be governed by only the CDDL
6.34 - * or only the GPL Version 2, indicate your decision by adding
6.35 - * "[Contributor] elects to include this software in this distribution
6.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
6.37 - * single choice of license, a recipient has the option to distribute
6.38 - * your version of this file under either the CDDL, the GPL Version 2 or
6.39 - * to extend the choice of license to its licensees as provided above.
6.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
6.41 - * Version 2 license, then the option applies only if the new code is
6.42 - * made subject to such option by the copyright holder.
6.43 - */
6.44 -package org.netbeans.modules.contrib.testng.output;
6.45 -
6.46 -import java.util.ArrayList;
6.47 -import java.util.List;
6.48 -import javax.swing.Action;
6.49 -import org.netbeans.api.project.Project;
6.50 -import org.netbeans.modules.contrib.testng.actions.DebugTestMethodAction;
6.51 -import org.netbeans.modules.contrib.testng.actions.RunTestMethodAction;
6.52 -import org.netbeans.modules.gsf.testrunner.api.DiffViewAction;
6.53 -import org.openide.util.actions.SystemAction;
6.54 -import org.netbeans.modules.gsf.testrunner.api.Testcase;
6.55 -import org.netbeans.spi.project.SingleMethod;
6.56 -import org.openide.util.lookup.AbstractLookup;
6.57 -import org.openide.util.lookup.InstanceContent;
6.58 -
6.59 -/**
6.60 - *
6.61 - * @author Marian Petras
6.62 - * @author Lukas Jungmann
6.63 - */
6.64 -final class TestMethodNode extends org.netbeans.modules.gsf.testrunner.api.TestMethodNode {
6.65 -
6.66 - private InstanceContent ic;
6.67 -
6.68 - public TestMethodNode(Testcase testcase, Project project) {
6.69 - this(testcase, project, new InstanceContent());
6.70 - }
6.71 -
6.72 - private TestMethodNode(Testcase tc, Project p, InstanceContent ic) {
6.73 - super(tc, p, new AbstractLookup(ic));
6.74 - this.ic = ic;
6.75 - }
6.76 -
6.77 - @Override
6.78 - public Action[] getActions(boolean context) {
6.79 - ic.add(new SingleMethod(getTestcase().getClassFileObject(), getTestcase().getName()));
6.80 - ic.add(getTestcase());
6.81 - List<Action> actions = new ArrayList<Action>();
6.82 - Action preferred = getPreferredAction();
6.83 - if (preferred != null) {
6.84 - actions.add(preferred);
6.85 - }
6.86 - if ((testcase.getTrouble() != null) && (testcase.getTrouble().getComparisonFailure() != null)){
6.87 - actions.add(new DiffViewAction(testcase));
6.88 - }
6.89 - if (!getTestcase().isConfigMethod()) {
6.90 - actions.add(SystemAction.get(RunTestMethodAction.class));
6.91 - actions.add(SystemAction.get(DebugTestMethodAction.class));
6.92 - }
6.93 - return actions.toArray(new Action[actions.size()]);
6.94 - }
6.95 -
6.96 - @Override
6.97 - public Action getPreferredAction() {
6.98 - return new JumpAction(this, null);
6.99 - }
6.100 -
6.101 - public TestNGTestcase getTestcase() {
6.102 - return (TestNGTestcase) testcase;
6.103 - }
6.104 -
6.105 - @Override
6.106 - public String getHtmlDisplayName() {
6.107 - return !getTestcase().isConfigMethod() ? super.getHtmlDisplayName()
6.108 - : "<i>" + super.getHtmlDisplayName() + "</i>";
6.109 - }
6.110 -}
7.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGAntLogger.java Sun Oct 30 22:14:10 2011 +0100
7.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGAntLogger.java Thu Nov 10 15:48:37 2011 +0100
7.3 @@ -45,15 +45,12 @@
7.4 import java.util.Collections;
7.5 import java.util.List;
7.6 import java.util.Properties;
7.7 -import java.util.logging.Level;
7.8 -import java.util.logging.Logger;
7.9 import org.apache.tools.ant.module.spi.AntEvent;
7.10 import org.apache.tools.ant.module.spi.AntLogger;
7.11 import org.apache.tools.ant.module.spi.AntSession;
7.12 import org.apache.tools.ant.module.spi.TaskStructure;
7.13 import org.netbeans.api.project.FileOwnerQuery;
7.14 import org.netbeans.api.project.Project;
7.15 -import org.netbeans.modules.contrib.testng.output.antutils.TestCounter;
7.16 import org.netbeans.modules.gsf.testrunner.api.Report;
7.17 import org.netbeans.modules.gsf.testrunner.api.TestSession.SessionType;
7.18 import org.openide.filesystems.FileUtil;
7.19 @@ -71,13 +68,13 @@
7.20 * @author Lukas Jungmann
7.21 */
7.22 @ServiceProvider(service = AntLogger.class)
7.23 -public final class TestNGAntLogger extends AntLogger {// implements ITestListener {
7.24 +public final class TestNGAntLogger extends AntLogger {
7.25
7.26 /** levels of interest for logging (info, warning, error, ...) */
7.27 private static final int[] LEVELS_OF_INTEREST = {
7.28 AntEvent.LOG_INFO,
7.29 AntEvent.LOG_WARN, //test failures
7.30 - AntEvent.LOG_VERBOSE,
7.31 + AntEvent.LOG_VERBOSE, //our test listener
7.32 AntEvent.LOG_ERR
7.33 };
7.34 public static final String TASK_JAVA = "java"; //NOI18N
7.35 @@ -170,7 +167,7 @@
7.36 * @return list of invidividual parts of the given command-line,
7.37 * or an empty list if the command-line was empty
7.38 */
7.39 - private static final List<String> parseCmdLine(String cmdLine) {
7.40 + private static List<String> parseCmdLine(String cmdLine) {
7.41 cmdLine = cmdLine.trim();
7.42
7.43 /* maybe the command-line is empty: */
7.44 @@ -304,22 +301,41 @@
7.45 if (sessionInfo.getSessionType() == null) {
7.46 sessionInfo.setSessionType(sessionType);
7.47 }
7.48 + //TODO: do the same for java/java debug tasks
7.49 + TaskStructure struct = event.getTaskStructure();
7.50 + String tmp = struct.getAttribute("suitename");
7.51 + if (tmp != null) {
7.52 + sessionInfo.setSessionName(event.evaluate(tmp));
7.53 + }
7.54 + tmp = struct.getAttribute("verbose");
7.55 + if (tmp == null) {
7.56 + tmp = struct.getAttribute("log");
7.57 + }
7.58 + boolean offline = false;
7.59 + if (tmp != null) {
7.60 + int logLevel = Integer.valueOf(event.evaluate(tmp));
7.61 + //logging is explicitly turned off by the user, so show only final
7.62 + //results computed off-line from testng-results.xml file
7.63 + offline = logLevel == 0;
7.64 + }
7.65
7.66 /*
7.67 * Count the test classes in the try-catch block so that
7.68 * 'testTaskStarted(...)' is called even if counting fails
7.69 * (throws an exception):
7.70 */
7.71 - int testClassCount;
7.72 - try {
7.73 - testClassCount = TestCounter.getTestClassCount(event);
7.74 - } catch (Exception ex) {
7.75 - testClassCount = 0;
7.76 - Logger.getLogger(TestNGAntLogger.class.getName()).log(Level.SEVERE, null, ex);
7.77 - }
7.78 + //would have to parse all incoming xmls, take includes/excludes
7.79 + //into accout, dependencies between tests, groups etc
7.80 +// int testClassCount;
7.81 +// try {
7.82 +// testClassCount = TestCounter.getTestClassCount(event);
7.83 +// } catch (Exception ex) {
7.84 +// testClassCount = 0;
7.85 +// Logger.getLogger(TestNGAntLogger.class.getName()).log(Level.SEVERE, null, ex);
7.86 +// }
7.87
7.88 - final boolean hasXmlOutput = hasXmlOutput(event);
7.89 - getOutputReader(event).testTaskStarted(testClassCount, hasXmlOutput, event);
7.90 +// getOutputReader(event).testTaskStarted(testClassCount, hasXmlOutput, event);
7.91 + getOutputReader(event).testTaskStarted(offline, event);
7.92 }
7.93 }
7.94
7.95 @@ -406,48 +422,4 @@
7.96 }
7.97 return sessionInfo;
7.98 }
7.99 -
7.100 - /**
7.101 - * Finds whether the test report will be generated in XML format.
7.102 - */
7.103 - private static boolean hasXmlOutput(AntEvent event) {
7.104 - final String taskName = event.getTaskName();
7.105 - if (TASK_TESTNG.equals(taskName) || TASK_JAVA.equals(taskName)) {
7.106 - return true;
7.107 - } else {
7.108 - assert false;
7.109 - return false;
7.110 - }
7.111 - }
7.112 -
7.113 -// public void onTestStart(ITestResult itr) {
7.114 -// System.out.println("Starting: " + itr.getName());
7.115 -// System.err.println("Starting: " + itr.getName());
7.116 -// }
7.117 -//
7.118 -// public void onTestSuccess(ITestResult itr) {
7.119 -// System.out.println("succ: " + itr.getName());
7.120 -// System.err.println("succ: " + itr.getName());
7.121 -// }
7.122 -//
7.123 -// public void onTestFailure(ITestResult itr) {
7.124 -//
7.125 -// }
7.126 -//
7.127 -// public void onTestSkipped(ITestResult itr) {
7.128 -//
7.129 -// }
7.130 -//
7.131 -// public void onTestFailedButWithinSuccessPercentage(ITestResult itr) {
7.132 -//
7.133 -// }
7.134 -//
7.135 -// public void onStart(ITestContext itc) {
7.136 -//
7.137 -// }
7.138 -//
7.139 -// public void onFinish(ITestContext itc) {
7.140 -//
7.141 -// }
7.142 -//
7.143 }
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGMethodNode.java Thu Nov 10 15:48:37 2011 +0100
8.3 @@ -0,0 +1,109 @@
8.4 +/*
8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8.6 + *
8.7 + * Copyright © 1997-2011 Oracle and/or its affiliates. All rights reserved.
8.8 + *
8.9 + * The contents of this file are subject to the terms of either the GNU
8.10 + * General Public License Version 2 only ("GPL") or the Common
8.11 + * Development and Distribution License("CDDL") (collectively, the
8.12 + * "License"). You may not use this file except in compliance with the
8.13 + * License. You can obtain a copy of the License at
8.14 + * http://www.netbeans.org/cddl-gplv2.html
8.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
8.16 + * specific language governing permissions and limitations under the
8.17 + * License. When distributing the software, include this License Header
8.18 + * Notice in each file and include the License file at
8.19 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
8.20 + * particular file as subject to the "Classpath" exception as provided
8.21 + * by Sun in the GPL Version 2 section of the License file that
8.22 + * accompanied this code. If applicable, add the following below the
8.23 + * License Header, with the fields enclosed by brackets [] replaced by
8.24 + * your own identifying information:
8.25 + * "Portions Copyrighted [year] [name of copyright owner]"
8.26 + *
8.27 + * Contributor(s):
8.28 + *
8.29 + * The Original Software is NetBeans. The Initial Developer of the Original
8.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
8.31 + * Microsystems, Inc. All Rights Reserved.
8.32 + *
8.33 + * If you wish your version of this file to be governed by only the CDDL
8.34 + * or only the GPL Version 2, indicate your decision by adding
8.35 + * "[Contributor] elects to include this software in this distribution
8.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
8.37 + * single choice of license, a recipient has the option to distribute
8.38 + * your version of this file under either the CDDL, the GPL Version 2 or
8.39 + * to extend the choice of license to its licensees as provided above.
8.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
8.41 + * Version 2 license, then the option applies only if the new code is
8.42 + * made subject to such option by the copyright holder.
8.43 + */
8.44 +package org.netbeans.modules.contrib.testng.output;
8.45 +
8.46 +import java.util.ArrayList;
8.47 +import java.util.List;
8.48 +import javax.swing.Action;
8.49 +import org.netbeans.api.project.Project;
8.50 +import org.netbeans.modules.contrib.testng.actions.DebugTestMethodAction;
8.51 +import org.netbeans.modules.contrib.testng.actions.RunTestMethodAction;
8.52 +import org.netbeans.modules.gsf.testrunner.api.DiffViewAction;
8.53 +import org.netbeans.modules.gsf.testrunner.api.TestMethodNode;
8.54 +import org.netbeans.modules.gsf.testrunner.api.Testcase;
8.55 +import org.netbeans.spi.project.SingleMethod;
8.56 +import org.openide.util.actions.SystemAction;
8.57 +import org.openide.util.lookup.AbstractLookup;
8.58 +import org.openide.util.lookup.InstanceContent;
8.59 +
8.60 +/**
8.61 + *
8.62 + * @author Marian Petras
8.63 + * @author Lukas Jungmann
8.64 + */
8.65 +final class TestNGMethodNode extends TestMethodNode {
8.66 +
8.67 + private InstanceContent ic;
8.68 +
8.69 + public TestNGMethodNode(Testcase testcase, Project project) {
8.70 + this(testcase, project, new InstanceContent());
8.71 + }
8.72 +
8.73 + private TestNGMethodNode(Testcase tc, Project p, InstanceContent ic) {
8.74 + super(tc, p, new AbstractLookup(ic));
8.75 + this.ic = ic;
8.76 + }
8.77 +
8.78 + @Override
8.79 + public Action[] getActions(boolean context) {
8.80 + ic.add(new SingleMethod(getTestcase().getClassFileObject(), getTestcase().getName()));
8.81 + ic.add(getTestcase());
8.82 + List<Action> actions = new ArrayList<Action>();
8.83 + Action preferred = getPreferredAction();
8.84 + if (preferred != null) {
8.85 + actions.add(preferred);
8.86 + }
8.87 + if ((testcase.getTrouble() != null) && (testcase.getTrouble().getComparisonFailure() != null)){
8.88 + //TODO: differs in TestNG
8.89 + actions.add(new DiffViewAction(testcase));
8.90 + }
8.91 + if (!getTestcase().isConfigMethod()) {
8.92 + actions.add(SystemAction.get(RunTestMethodAction.class));
8.93 + actions.add(SystemAction.get(DebugTestMethodAction.class));
8.94 + }
8.95 + return actions.toArray(new Action[actions.size()]);
8.96 + }
8.97 +
8.98 + @Override
8.99 + public Action getPreferredAction() {
8.100 + return new JumpAction(this, null);
8.101 + }
8.102 +
8.103 + public TestNGTestcase getTestcase() {
8.104 + return (TestNGTestcase) testcase;
8.105 + }
8.106 +
8.107 + @Override
8.108 + public String getHtmlDisplayName() {
8.109 + return !getTestcase().isConfigMethod() ? super.getHtmlDisplayName()
8.110 + : "<i>" + super.getHtmlDisplayName() + "</i>";
8.111 + }
8.112 +}
9.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGOutputReader.java Sun Oct 30 22:14:10 2011 +0100
9.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGOutputReader.java Thu Nov 10 15:48:37 2011 +0100
9.3 @@ -47,13 +47,9 @@
9.4 import java.nio.charset.UnsupportedCharsetException;
9.5 import java.text.NumberFormat;
9.6 import java.text.ParseException;
9.7 -import java.util.ArrayList;
9.8 -import java.util.Arrays;
9.9 +import java.util.*;
9.10 import java.util.logging.Level;
9.11 import java.util.logging.Logger;
9.12 -import java.util.GregorianCalendar;
9.13 -import java.util.List;
9.14 -import java.util.Properties;
9.15 import java.util.regex.Matcher;
9.16 import java.util.regex.Pattern;
9.17 import org.apache.tools.ant.module.spi.AntEvent;
9.18 @@ -64,78 +60,64 @@
9.19 import org.netbeans.api.java.platform.JavaPlatformManager;
9.20 import org.netbeans.api.project.FileOwnerQuery;
9.21 import org.netbeans.api.project.Project;
9.22 -import org.netbeans.modules.gsf.testrunner.api.Manager;
9.23 -import org.netbeans.modules.gsf.testrunner.api.OutputLine;
9.24 -import org.netbeans.modules.gsf.testrunner.api.Report;
9.25 -import org.netbeans.modules.gsf.testrunner.api.Status;
9.26 -import org.netbeans.modules.gsf.testrunner.api.TestSession;
9.27 import org.netbeans.modules.gsf.testrunner.api.TestSession.SessionType;
9.28 -import org.netbeans.modules.gsf.testrunner.api.TestSuite;
9.29 -import org.netbeans.modules.gsf.testrunner.api.Testcase;
9.30 -import org.netbeans.modules.gsf.testrunner.api.Trouble;
9.31 +import org.netbeans.modules.gsf.testrunner.api.*;
9.32 import org.openide.filesystems.FileObject;
9.33 import org.openide.filesystems.FileUtil;
9.34 -import org.openide.util.Exceptions;
9.35 import org.xml.sax.SAXException;
9.36 -import static java.util.Calendar.MILLISECOND;
9.37 -import static java.util.logging.Level.FINER;
9.38 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.ADD_ERROR_PREFIX;
9.39 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.ADD_FAILURE_PREFIX;
9.40 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.END_OF_TEST_PREFIX;
9.41 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.START_OF_TEST_PREFIX;
9.42 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.TESTCASE_PREFIX;
9.43 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.TEST_LISTENER_PREFIX;
9.44 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.TESTS_COUNT_PREFIX;
9.45 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.TESTSUITE_PREFIX;
9.46 -import static org.netbeans.modules.contrib.testng.output.RegexpUtils.TESTSUITE_STATS_PREFIX;
9.47
9.48 /**
9.49 - * Obtains events from a single session of an Ant <code>junit</code> task
9.50 - * and builds a {@link Report}.
9.51 - * The events are delivered by the {@link TestNGAntLogger}.
9.52 + * Obtains events from a single session of an Ant
9.53 + * <code>junit</code> task and builds a {@link Report}. The events are delivered
9.54 + * by the {@link TestNGAntLogger}.
9.55 *
9.56 - * @see TestNGAntLogger
9.57 - * @see Report
9.58 - * @author Marian Petras
9.59 - * @author Lukas Jungmann
9.60 + * @see TestNGAntLogger
9.61 + * @see Report
9.62 + * @author Marian Petras
9.63 + * @author Lukas Jungmann
9.64 */
9.65 final class TestNGOutputReader {
9.66
9.67 - private static final int MAX_REPORT_FILE_SIZE = 1 << 22; //2 MiB
9.68 - /** */
9.69 + private static final Logger LOG = Logger.getLogger(TestNGOutputReader.class.getName());
9.70 + private static final Logger progressLogger = Logger.getLogger(
9.71 + "org.netbeans.modules.contrib.testng.outputreader.progress");
9.72 + /**
9.73 + *
9.74 + */
9.75 private final NumberFormat numberFormat = NumberFormat.getInstance();
9.76 - /** */
9.77 + /**
9.78 + *
9.79 + */
9.80 private final SessionType sessionType;
9.81 - /** whether XML report is expected */
9.82 + /**
9.83 + * whether XML report is expected
9.84 + */
9.85 private boolean expectXmlReport;
9.86 - /** */
9.87 + /**
9.88 + *
9.89 + */
9.90 private final File antScript;
9.91 - /** */
9.92 + /**
9.93 + *
9.94 + */
9.95 private final long timeOfSessionStart;
9.96 private long lastSuiteTime = 0;
9.97 - private final Logger LOG;
9.98 - private final Logger progressLogger;
9.99 - /** */
9.100 - private RegexpUtils regexp = RegexpUtils.getInstance();
9.101 - /** */
9.102 - private boolean lastHeaderBrief;
9.103 - /** */
9.104 + /**
9.105 + *
9.106 + */
9.107 private final Manager manager = Manager.getInstance();
9.108 - /** */
9.109 + /**
9.110 + *
9.111 + */
9.112 private ClassPath platformSources;
9.113 - private TestSession testSession;
9.114 + private TestNGTestSession testSession;
9.115 private Project project;
9.116 private File resultsDir;
9.117 - private TestNGTestcase testcase;
9.118 - private Report report;
9.119 + private Map<String, Report> reports;
9.120
9.121 - enum State {
9.122 -
9.123 - DEFAULT, SUITE_STARTED, TESTCASE_STARTED, SUITE_FINISHED, TESTCASE_ISSUE
9.124 - };
9.125 - private State state = State.DEFAULT;
9.126 -
9.127 - /** Creates a new instance of TestNGOutputReader */
9.128 + /**
9.129 + * Creates a new instance of TestNGOutputReader
9.130 + */
9.131 TestNGOutputReader(final AntSession session,
9.132 final AntSessionInfo sessionInfo,
9.133 final Project project,
9.134 @@ -148,11 +130,10 @@
9.135 FileObject fileObj = FileUtil.toFileObject(antScript);
9.136 this.project = FileOwnerQuery.getOwner(fileObj);
9.137 }
9.138 - this.testSession = new TestNGTestSession("", this.project, sessionType, new TestNGTestNodeFactory()); //NOI18N
9.139 + this.testSession = new TestNGTestSession(
9.140 + sessionInfo.getSessionName(), this.project, sessionType, new TestNGTestNodeFactory());
9.141 testSession.setRerunHandler(new TestNGExecutionManager(session, testSession, props));
9.142 - this.progressLogger = Logger.getLogger(
9.143 - "org.netbeans.modules.contrib.testng.outputreader.progress"); //NOI18N
9.144 - this.LOG = Logger.getLogger(TestNGOutputReader.class.getName());
9.145 + reports = new HashMap<String, Report>();
9.146 }
9.147
9.148 Project getProject() {
9.149 @@ -168,118 +149,124 @@
9.150 if (msg == null) {
9.151 return;
9.152 }
9.153 + if (!msg.startsWith(RegexpUtils.TEST_LISTENER_PREFIX) || expectXmlReport) {
9.154 + //this message is not for us...
9.155 + return;
9.156 + }
9.157 verboseMessageLogged(msg);
9.158 - displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN);
9.159 +// displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN);
9.160 }
9.161 + private boolean suiteSummary = false;
9.162 +
9.163 + private class SuiteStats {
9.164 +
9.165 + private String name = null;
9.166 + private int testRun = -1;
9.167 + private int testFail = -1;
9.168 + private int testSkip = -1;
9.169 + private int confFail = 0;
9.170 + private int confSkip = 0;
9.171 + }
9.172 + private SuiteStats suiteStat;
9.173
9.174 /**
9.175 */
9.176 synchronized void verboseMessageLogged(String msg) {
9.177 - Matcher matcher = RegexpUtils.JAVA_EXECUTABLE.matcher(msg);
9.178 - if (matcher.find()) {
9.179 - String executable = matcher.group(1);
9.180 - ClassPath platformSrcs = findPlatformSources(executable);
9.181 - if (platformSrcs != null) {
9.182 - this.platformSources = platformSrcs;
9.183 + //suite starting
9.184 + if (getMessage(msg).startsWith("RUNNING: ")) {
9.185 + Matcher m = Pattern.compile(RegexpUtils.RUNNING_SUITE_REGEX).matcher(msg);
9.186 + if (m.matches()) {
9.187 + suiteStarted(m.group(1), Integer.valueOf(m.group(2)), m.group(3));
9.188 + } else {
9.189 + assert false : "Cannot match: '" + msg + "'.";
9.190 }
9.191 + return;
9.192 }
9.193 -// switch (state) {
9.194 -// case SUITE_STARTED: {
9.195 -// if (msg.startsWith(TEST_LISTENER_PREFIX)) {
9.196 -// String testListenerMsg = msg.substring(TEST_LISTENER_PREFIX.length());
9.197 -// if (testListenerMsg.startsWith(TESTS_COUNT_PREFIX)) {
9.198 -//// String countStr = testListenerMsg.substring(TESTS_COUNT_PREFIX.length());
9.199 -// return;
9.200 -// }
9.201 -//
9.202 -// int leftBracketIndex = testListenerMsg.indexOf('(');
9.203 -// if (leftBracketIndex == -1) {
9.204 -// return;
9.205 -// }
9.206 -//
9.207 -// final String shortMsg = testListenerMsg.substring(0, leftBracketIndex);
9.208 -// if (shortMsg.equals(START_OF_TEST_PREFIX)) {
9.209 -// String restOfMsg = testListenerMsg.substring(START_OF_TEST_PREFIX.length());
9.210 -// if (restOfMsg.length() != 0) {
9.211 -// char firstChar = restOfMsg.charAt(0);
9.212 -// char lastChar = restOfMsg.charAt(restOfMsg.length() - 1);
9.213 -// if ((firstChar == '(') && (lastChar == ')')) {
9.214 -// testCaseStarted(restOfMsg.substring(1, restOfMsg.length() - 1));
9.215 -// }
9.216 -// }
9.217 -// return;
9.218 -// }
9.219 -// }
9.220 -// break;
9.221 -// }
9.222 -// case TESTCASE_STARTED: {
9.223 -// if (msg.startsWith(TEST_LISTENER_PREFIX)) {
9.224 -// String testListenerMsg = msg.substring(TEST_LISTENER_PREFIX.length());
9.225 -// int leftBracketIndex = testListenerMsg.indexOf('(');
9.226 -// if (leftBracketIndex == -1) {
9.227 -// return;
9.228 -// }
9.229 -// final String shortMsg = testListenerMsg.substring(0, leftBracketIndex);
9.230 -//
9.231 -// if (shortMsg.equals(END_OF_TEST_PREFIX)) {
9.232 -// String restOfMsg = testListenerMsg.substring(END_OF_TEST_PREFIX.length());
9.233 -// if (restOfMsg.length() != 0) {
9.234 -// char firstChar = restOfMsg.charAt(0);
9.235 -// char lastChar = restOfMsg.charAt(restOfMsg.length() - 1);
9.236 -// if ((firstChar == '(') && (lastChar == ')')) {
9.237 -// String name = restOfMsg.substring(1, restOfMsg.length() - 1);
9.238 -// if (name.equals(testSession.getCurrentTestCase().getName())) {
9.239 -// testCaseFinished();
9.240 -// }
9.241 -// }
9.242 -// }
9.243 -// return;
9.244 -// } else if (shortMsg.equals(ADD_FAILURE_PREFIX)
9.245 -// || shortMsg.equals(ADD_ERROR_PREFIX)) {
9.246 -// int lastCharIndex = testListenerMsg.length() - 1;
9.247 -//
9.248 -// String insideBrackets = testListenerMsg.substring(
9.249 -// shortMsg.length() + 1,
9.250 -// lastCharIndex);
9.251 -// int commaIndex = insideBrackets.indexOf(',');
9.252 -// String testName = (commaIndex == -1)
9.253 -// ? insideBrackets
9.254 -// : insideBrackets.substring(0, commaIndex);
9.255 -// if (!testName.equals(testSession.getCurrentTestCase().getName())) {
9.256 -// return;
9.257 -// }
9.258 -// testSession.getCurrentTestCase().setTrouble(new Trouble(shortMsg.equals(ADD_ERROR_PREFIX)));
9.259 -// boolean hasErrMsg = (commaIndex != -1)
9.260 -// && ((commaIndex + 2) <= insideBrackets.length()); // #166912
9.261 -// if (hasErrMsg) {
9.262 -// int errMsgStart;
9.263 -// if (Character.isSpaceChar(insideBrackets.charAt(commaIndex + 1))) {
9.264 -// errMsgStart = commaIndex + 2;
9.265 -// } else {
9.266 -// errMsgStart = commaIndex + 1;
9.267 -// }
9.268 -// String troubleMsg = insideBrackets.substring(errMsgStart);
9.269 -// if (!troubleMsg.equals("null")) { //NOI18N
9.270 -// addStackTraceLine(testSession.getCurrentTestCase(), troubleMsg, false);
9.271 -// }
9.272 -// }
9.273 -// return;
9.274 -// }
9.275 -// }
9.276 -// break;
9.277 -// }
9.278 -// case DEFAULT:
9.279 -// case SUITE_FINISHED:
9.280 -// case TESTCASE_ISSUE: {
9.281 -// Matcher matcher = RegexpUtils.JAVA_EXECUTABLE.matcher(msg);
9.282 -// if (matcher.find()) {
9.283 -// String executable = matcher.group(1);
9.284 -// ClassPath platformSrcs = findPlatformSources(executable);
9.285 -// if (platformSrcs != null) {
9.286 -// this.platformSources = platformSrcs;
9.287 -// }
9.288 -// }
9.289 -// break;
9.290 + //suite finishing
9.291 + if (getMessage(msg).equals("===============================================")) {
9.292 + suiteSummary = !suiteSummary;
9.293 + if (suiteSummary) {
9.294 + suiteStat = new SuiteStats();
9.295 + } else {
9.296 + suiteFinished(suiteStat);
9.297 + suiteStat = null;
9.298 + }
9.299 + return;
9.300 + } else if (suiteSummary) {
9.301 + if (suiteStat.name != null) {
9.302 + Matcher m = Pattern.compile(RegexpUtils.STATS_REGEX).matcher(msg);
9.303 + if (suiteStat.testRun < 0) {
9.304 + //Tests run/fail/skip
9.305 + if (m.matches()) {
9.306 + suiteStat.testRun = Integer.valueOf(m.group(1));
9.307 + suiteStat.testFail = Integer.valueOf(m.group(2));
9.308 + suiteStat.testSkip = Integer.valueOf(m.group(4));
9.309 + } else {
9.310 + assert false : "Cannot match: '" + msg + "'.";
9.311 + }
9.312 + } else {
9.313 + //Configuration fail/skip
9.314 + if (m.matches()) {
9.315 + suiteStat.confFail = Integer.valueOf(m.group(1));
9.316 + suiteStat.confSkip = Integer.valueOf(m.group(2));
9.317 + } else {
9.318 + assert false : "Cannot match: '" + msg + "'.";
9.319 + }
9.320 + }
9.321 + } else {
9.322 + suiteStat.name = getMessage(msg).trim();
9.323 + }
9.324 + return;
9.325 + }
9.326 + //test
9.327 + if (getMessage(msg).startsWith("INVOKING: ")) {
9.328 + Matcher m = Pattern.compile(RegexpUtils.TEST_REGEX).matcher(msg);
9.329 + if (m.matches()) {
9.330 + testStarted(m.group(1), m.group(2), m.group(3), m.group(5));
9.331 + } else {
9.332 + assert false : "Cannot match: '" + msg + "'.";
9.333 + }
9.334 + return;
9.335 + }
9.336 +
9.337 + Matcher m = Pattern.compile(RegexpUtils.TEST_REGEX).matcher(msg);
9.338 + if (getMessage(msg).startsWith("PASSED: ")) {
9.339 + if (m.matches()) {
9.340 + testFinished("PASSED", m.group(1), m.group(2), m.group(3), m.group(5));
9.341 + } else {
9.342 + assert false : "Cannot match: '" + msg + "'.";
9.343 + }
9.344 + return;
9.345 + }
9.346 +
9.347 + if (getMessage(msg).startsWith("PASSED with failures: ")) {
9.348 + }
9.349 +
9.350 + if (getMessage(msg).startsWith("SKIPPED: ")) {
9.351 + if (m.matches()) {
9.352 + testFinished("SKIPPED", m.group(1), m.group(2), m.group(3), m.group(5));
9.353 + } else {
9.354 + assert false : "Cannot match: '" + msg + "'.";
9.355 + }
9.356 + return;
9.357 + }
9.358 +
9.359 + if (getMessage(msg).startsWith("FAILED: ")) {
9.360 + if (m.matches()) {
9.361 + testFinished("FAILED", m.group(1), m.group(2), m.group(3), m.group(5));
9.362 + } else {
9.363 + assert false : "Cannot match: '" + msg + "'.";
9.364 + }
9.365 + return;
9.366 + }
9.367 +
9.368 + //configuration methods
9.369 +// Matcher matcher = RegexpUtils.JAVA_EXECUTABLE.matcher(msg);
9.370 +// if (matcher.find()) {
9.371 +// String executable = matcher.group(1);
9.372 +// ClassPath platformSrcs = findPlatformSources(executable);
9.373 +// if (platformSrcs != null) {
9.374 +// this.platformSources = platformSrcs;
9.375 // }
9.376 // }
9.377 }
9.378 @@ -289,67 +276,10 @@
9.379 if (msg == null) {
9.380 return;
9.381 }
9.382 - displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN);
9.383 -// switch (state) {
9.384 -// case TESTCASE_ISSUE:
9.385 -// case SUITE_FINISHED: {
9.386 -// if (msg.startsWith(TESTCASE_PREFIX)) {
9.387 -// String header = msg.substring(TESTCASE_PREFIX.length());
9.388 -// boolean success =
9.389 -// lastHeaderBrief
9.390 -// ? tryParseBriefHeader(header)
9.391 -// || !(lastHeaderBrief = !tryParsePlainHeader(header))
9.392 -// : tryParsePlainHeader(header)
9.393 -// || (lastHeaderBrief = tryParseBriefHeader(header));
9.394 -// if (success) {
9.395 -// state = State.TESTCASE_ISSUE;
9.396 -// }
9.397 -// break;
9.398 -// }
9.399 -// }
9.400 -// case DEFAULT: {
9.401 -// if (msg.contains(TESTSUITE_PREFIX)) {
9.402 -// String suiteName = msg.substring(TESTSUITE_PREFIX.length());
9.403 -// if (regexp.getFullJavaIdPattern().matcher(suiteName).matches()) {
9.404 -// suiteStarted(suiteName);
9.405 -// resultsDir = determineResultsDir(event);
9.406 -// }
9.407 -// }
9.408 -//
9.409 -// if (state.equals(State.TESTCASE_ISSUE) && !msg.equals("")) {
9.410 -// addStackTraceLine(testcase, msg, true);
9.411 -// }
9.412 -// break;
9.413 -// }
9.414 -// case SUITE_STARTED: {
9.415 -// if (msg.startsWith(TESTSUITE_STATS_PREFIX)) {
9.416 -// Matcher matcher = regexp.getSuiteStatsPattern().matcher(msg);
9.417 -// if (matcher.matches()) {
9.418 -// try {
9.419 -// suiteFinished(Integer.parseInt(matcher.group(1)),
9.420 -// Integer.parseInt(matcher.group(2)),
9.421 -// Integer.parseInt(matcher.group(3)),
9.422 -// parseTime(matcher.group(4)));
9.423 -// } catch (NumberFormatException ex) {
9.424 -// assert false;
9.425 -// }
9.426 -// } else {
9.427 -// assert false;
9.428 -// }
9.429 -// break;
9.430 -// }
9.431 -// }
9.432 -// case TESTCASE_STARTED: {
9.433 -// int posTestListener = msg.indexOf(TEST_LISTENER_PREFIX);
9.434 -// if (posTestListener != -1) {
9.435 -// displayOutput(msg.substring(0, posTestListener), event.getLogLevel() == AntEvent.LOG_WARN);
9.436 -// verboseMessageLogged(msg.substring(posTestListener));
9.437 -// } else {
9.438 -// displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN);
9.439 -// }
9.440 -// break;
9.441 -// }
9.442 -// }
9.443 + if (!expectXmlReport) {
9.444 + //log/verbose level = 0 so don't show output
9.445 + displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN);
9.446 + }
9.447 }
9.448
9.449 /**
9.450 @@ -368,10 +298,11 @@
9.451 /**
9.452 * Tries to determine test results directory.
9.453 *
9.454 - * @param event Ant event serving as a source of information
9.455 - * @return <code>File<code> object representing the results directory,
9.456 - * or <code>null</code> if the results directory could not be
9.457 - * determined
9.458 + * @param event Ant event serving as a source of information
9.459 + * @return
9.460 + * <code>File<code> object representing the results directory,
9.461 + * or
9.462 + * <code>null</code> if the results directory could not be determined
9.463 */
9.464 private static File determineResultsDir(final AntEvent event) {
9.465 File resultsDir = null;
9.466 @@ -400,8 +331,11 @@
9.467 return null;
9.468 }
9.469 String todirAttr = (taskStruct.getAttribute("outputdir") != null) //NOI18N
9.470 - ? taskStruct.getAttribute("outputdir") : "test-output"; //NOI18N
9.471 - File resultsDir = getFile(todirAttr, event);
9.472 + ? taskStruct.getAttribute("outputdir") //NOI18N
9.473 + : (taskStruct.getAttribute("workingDir") != null) //NOI18N
9.474 + ? taskStruct.getAttribute("workingDir") + "test-output" //NOI18N
9.475 + : "test-output"; //NOI18N
9.476 + File resultsDir = new File(event.evaluate(todirAttr));
9.477 return findAbsolutePath(resultsDir, taskStruct, event);
9.478 }
9.479
9.480 @@ -432,14 +366,24 @@
9.481 ? todirPath.indexOf("\"", 1) + 1 //NOI18N
9.482 : todirPath.indexOf(" "); //NOI18N
9.483 todirPath = todirPath.substring(0, index);
9.484 + //found, let's finish
9.485 + break;
9.486 }
9.487 }
9.488 }
9.489 }
9.490 }
9.491
9.492 - File resultsDir = (todirPath != ".") ? new File(todirPath) //NOI18N
9.493 - : null;
9.494 + if (todirPath == null) {
9.495 + //-d not set, what about parent java/exec's 'dir'?
9.496 + String dir = taskStruct.getAttribute("dir");
9.497 + if (dir != null) {
9.498 + todirPath = event.evaluate(dir) + "/test-output";
9.499 + } else {
9.500 + todirPath = "test-output";
9.501 + }
9.502 + }
9.503 + File resultsDir = new File(event.evaluate(todirPath));
9.504 return findAbsolutePath(resultsDir, taskStruct, event);
9.505 }
9.506
9.507 @@ -471,7 +415,9 @@
9.508 */
9.509 private ClassPath findPlatformSources(final String javaExecutable) {
9.510
9.511 - /* Copied from JavaAntLogger */
9.512 + /*
9.513 + * Copied from JavaAntLogger
9.514 + */
9.515
9.516 final JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
9.517 for (int i = 0; i < platforms.length; i++) {
9.518 @@ -491,38 +437,34 @@
9.519
9.520 /**
9.521 * Notifies that a test (Ant) task was just started.
9.522 - *
9.523 - * @param expectedSuitesCount expected number of test suites going to be
9.524 - * executed by this task
9.525 */
9.526 - void testTaskStarted(int expectedSuitesCount, boolean expectXmlOutput, AntEvent event) {
9.527 + void testTaskStarted(boolean expectXmlOutput, AntEvent event) {
9.528 this.expectXmlReport = expectXmlOutput;
9.529 - manager.testStarted(testSession);
9.530 -// manager.displaySuiteRunning(testSession, TestSuite.ANONYMOUS_TEST_SUITE);
9.531 + if (!expectXmlReport) {
9.532 + manager.testStarted(testSession);
9.533 + }
9.534 resultsDir = determineResultsDir(event);
9.535 }
9.536
9.537 /**
9.538 */
9.539 void testTaskFinished() {
9.540 - state = State.SUITE_FINISHED;
9.541 - closePreviousReport(); // #171050
9.542 - }
9.543 -
9.544 - private void closePreviousReport() {
9.545 - //get results from report xml file
9.546 - if (resultsDir != null) {
9.547 - File reportFile = findReportFile();
9.548 - if ((reportFile != null) && isValidReportFile(reportFile)) {
9.549 - TestNGSuite reportSuite = parseReportFile(reportFile, testSession);
9.550 - for (TestNGTestSuite ts : reportSuite.getTestSuites()) {
9.551 - manager.displaySuiteRunning(testSession, ts);
9.552 - testSession.addSuite(ts);
9.553 - report = testSession.getReport(ts.getElapsedTime());
9.554 - manager.displayReport(testSession, report, true);
9.555 + if (expectXmlReport) {
9.556 + manager.testStarted(testSession);
9.557 + //get results from report xml file
9.558 + if (resultsDir != null) {
9.559 + File reportFile = findReportFile();
9.560 + if ((reportFile != null) && isValidReportFile(reportFile)) {
9.561 + XmlResult reportSuite = parseReportFile(reportFile, testSession);
9.562 + for (TestNGTestSuite ts : reportSuite.getTestSuites()) {
9.563 + manager.displaySuiteRunning(testSession, ts);
9.564 + testSession.setCurrentSuite(ts.getName());
9.565 + testSession.addSuite(ts);
9.566 + Report report = testSession.getReport(ts.getElapsedTime());
9.567 + manager.displayReport(testSession, report, true);
9.568 + }
9.569 }
9.570 }
9.571 - report = null;
9.572 }
9.573 }
9.574
9.575 @@ -533,50 +475,21 @@
9.576 }
9.577
9.578 //------------------ UPDATE OF DISPLAY -------------------
9.579 -
9.580 /**
9.581 */
9.582 private void displayOutput(final String text, final boolean error) {
9.583 manager.displayOutput(testSession, text, error);
9.584 - if (state == State.TESTCASE_STARTED) {
9.585 - List<String> addedLines = new ArrayList<String>();
9.586 - addedLines.add(text);
9.587 - Testcase tc = testSession.getCurrentTestCase();
9.588 - if (tc != null) {
9.589 - tc.addOutputLines(addedLines);
9.590 - }
9.591 - }
9.592 +// if (state == State.TESTCASE_STARTED) {
9.593 +// List<String> addedLines = new ArrayList<String>();
9.594 +// addedLines.add(text);
9.595 +// Testcase tc = testSession.getCurrentTestCase();
9.596 +// if (tc != null) {
9.597 +// tc.addOutputLines(addedLines);
9.598 +// }
9.599 +// }
9.600 }
9.601
9.602 //--------------------------------------------------------
9.603 - /**
9.604 - */
9.605 - private boolean tryParsePlainHeader(String testcaseHeader) {
9.606 - final Matcher matcher = regexp.getTestcaseHeaderPlainPattern().matcher(testcaseHeader);
9.607 - if (matcher.matches()) {
9.608 - String methodName = matcher.group(1);
9.609 - String timeString = matcher.group(2);
9.610 -
9.611 - testcase = findTest(testSession.getCurrentSuite(), methodName);
9.612 - testcase.setTimeMillis(parseTime(timeString));
9.613 -
9.614 - return true;
9.615 - } else {
9.616 - return false;
9.617 - }
9.618 - }
9.619 -
9.620 - private TestNGTestcase findTest(TestSuite suite, String methodName) {
9.621 - TestNGTestcase ret = null;
9.622 - for (Testcase tcase : suite.getTestcases()) {
9.623 - if (tcase.getName().equals(methodName)) {
9.624 - ret = (TestNGTestcase) tcase;
9.625 - break;
9.626 - }
9.627 - }
9.628 - return ret;
9.629 - }
9.630 -
9.631 private File findReportFile() {
9.632 File file = new File(resultsDir, "testng-results.xml"); //NOI18N
9.633 return (file.isFile() ? file : null);
9.634 @@ -597,17 +510,17 @@
9.635 long timeDelta = lastModified - timeOfSessionStart;
9.636
9.637 final Logger logger = Logger.getLogger("org.netbeans.modules.contrib.testng.outputreader.timestamps");//NOI18N
9.638 - final Level logLevel = FINER;
9.639 + final Level logLevel = Level.FINER;
9.640 if (logger.isLoggable(logLevel)) {
9.641 logger.log(logLevel, "Report file: " + reportFile.getPath());//NOI18N
9.642
9.643 final GregorianCalendar timeStamp = new GregorianCalendar();
9.644
9.645 timeStamp.setTimeInMillis(timeOfSessionStart);
9.646 - logger.log(logLevel, "Session start: " + String.format("%1$tT.%2$03d", timeStamp, timeStamp.get(MILLISECOND)));//NOI18N
9.647 + logger.log(logLevel, "Session start: " + String.format("%1$tT.%2$03d", timeStamp, timeStamp.get(Calendar.MILLISECOND)));//NOI18N
9.648
9.649 timeStamp.setTimeInMillis(lastModified);
9.650 - logger.log(logLevel, "Report timestamp: " + String.format("%1$tT.%2$03d", timeStamp, timeStamp.get(MILLISECOND)));//NOI18N
9.651 + logger.log(logLevel, "Report timestamp: " + String.format("%1$tT.%2$03d", timeStamp, timeStamp.get(Calendar.MILLISECOND)));//NOI18N
9.652 }
9.653
9.654 if (timeDelta >= 0) {
9.655 @@ -618,11 +531,10 @@
9.656 * Normally we would return 'false' here, but:
9.657 *
9.658 * We must take into account that modification timestamps of files
9.659 - * usually do not hold milliseconds, just seconds.
9.660 - * The worst case we must accept is that the session started
9.661 - * on YYYY.MM.DD hh:mm:ss.999 and the file was saved exactly in the same
9.662 - * millisecond but its time stamp is just YYYY.MM.DD hh:mm:ss, i.e
9.663 - * 999 milliseconds earlier.
9.664 + * usually do not hold milliseconds, just seconds. The worst case we
9.665 + * must accept is that the session started on YYYY.MM.DD hh:mm:ss.999
9.666 + * and the file was saved exactly in the same millisecond but its time
9.667 + * stamp is just YYYY.MM.DD hh:mm:ss, i.e 999 milliseconds earlier.
9.668 */
9.669 return -timeDelta <= timeOfSessionStart % 1000;
9.670
9.671 @@ -632,14 +544,14 @@
9.672 //
9.673 // final GregorianCalendar sessStartCal = new GregorianCalendar();
9.674 // sessStartCal.setTimeInMillis(timeOfSessionStart);
9.675 -// int sessStartMillis = sessStartCal.get(MILLISECOND);
9.676 +// int sessStartMillis = sessStartCal.get(Calendar.MILLISECOND);
9.677 // if (timeDelta < -sessStartMillis) {
9.678 // return false;
9.679 // }
9.680 //
9.681 // final GregorianCalendar fileModCal = new GregorianCalendar();
9.682 // fileModCal.setTimeInMillis(lastModified);
9.683 -// if (fileModCal.get(MILLISECOND) != 0) {
9.684 +// if (fileModCal.get(Calendar.MILLISECOND) != 0) {
9.685 // /* So the file's timestamp does hold milliseconds! */
9.686 // return false;
9.687 // }
9.688 @@ -652,8 +564,8 @@
9.689 // return lastModified >= (timeOfSessionStart - sessStartMillis);
9.690 }
9.691
9.692 - private static TestNGSuite parseReportFile(File reportFile, TestSession session) {
9.693 - TestNGSuite reports = null;
9.694 + private static XmlResult parseReportFile(File reportFile, TestSession session) {
9.695 + XmlResult reports = null;
9.696 try {
9.697 reports = XmlOutputParser.parseXmlOutput(
9.698 new InputStreamReader(
9.699 @@ -662,14 +574,74 @@
9.700 } catch (UnsupportedCharsetException ex) {
9.701 assert false;
9.702 } catch (SAXException ex) {
9.703 - /* This exception has already been handled. */
9.704 + /*
9.705 + * This exception has already been handled.
9.706 + */
9.707 } catch (IOException ex) {
9.708 /*
9.709 - * Failed to read the report file - but we still have
9.710 - * the report built from the Ant output.
9.711 + * Failed to read the report file - but we still have the report
9.712 + * built from the Ant output.
9.713 */
9.714 - Logger.getLogger(TestNGOutputReader.class.getName()).log(Level.INFO, "I/O exception while reading JUnit XML report file from JUnit: ", ex);//NOI18N
9.715 + Logger.getLogger(TestNGOutputReader.class.getName()).log(Level.INFO, "I/O exception while reading TestNG XML report file from TestNG: ", ex);//NOI18N
9.716 }
9.717 return reports;
9.718 }
9.719 +
9.720 + private void suiteStarted(String name, int expectedTCases, String config) {
9.721 + TestSuite suite = new TestNGTestSuite(name, testSession, expectedTCases, config);
9.722 + testSession.addSuite(suite);
9.723 + testSession.setCurrentSuite(name);
9.724 + manager.displaySuiteRunning(testSession, suite);
9.725 + platformSources = null;
9.726 + reports.put(name, new Report(name, project));
9.727 + }
9.728 +
9.729 + private void suiteFinished(SuiteStats stats) {
9.730 + testSession.setCurrentSuite(stats.name);
9.731 + TestNGTestSuite s = (TestNGTestSuite) testSession.getCurrentSuite();
9.732 + s.finish(stats.testRun, stats.testFail, stats.testSkip, stats.confFail, stats.confSkip);
9.733 + manager.displayReport(testSession, reports.get(stats.name), true);
9.734 + }
9.735 +
9.736 + private void testStarted(String suiteName, String testCase, String parameters, String values) {
9.737 + testSession.setCurrentSuite(suiteName);
9.738 + TestNGTestcase tc = ((TestNGTestSuite) ((TestNGTestSession) testSession).getCurrentSuite()).getTestCase(testCase, parameters);
9.739 + if (tc == null) {
9.740 + tc = new TestNGTestcase(testCase, parameters, values, testSession);
9.741 + testSession.addTestCase(tc);
9.742 + manager.testStarted(testSession);
9.743 + Report r = reports.get(suiteName);
9.744 + r.update(testSession.getReport(lastSuiteTime));
9.745 + manager.displayReport(testSession, r, false);
9.746 + } else {
9.747 + tc.addValues(values);
9.748 + }
9.749 + }
9.750 +
9.751 + private void testFinished(String st, String suiteName, String testCase, String parameters, String values) {
9.752 + testSession.setCurrentSuite(suiteName);
9.753 + TestNGTestcase tc = ((TestNGTestSuite) ((TestNGTestSession) testSession).getCurrentSuite()).getTestCase(testCase, parameters);
9.754 + if (tc == null) {
9.755 + //TestNG does not log invoke message for junit tests...
9.756 + tc = new TestNGTestcase(testCase, parameters, values, testSession);
9.757 + testSession.addTestCase(tc);
9.758 + manager.testStarted(testSession);
9.759 + }
9.760 + assert tc != null;
9.761 + if ("PASSED".equals(st)) {
9.762 + tc.setStatus(Status.PASSED);
9.763 + } else if ("FAILED".equals(st)) {
9.764 + tc.setStatus(Status.FAILED);
9.765 + } else if ("SKIPPED".equals(st)) {
9.766 + tc.setStatus(Status.SKIPPED);
9.767 + }
9.768 + Report r = reports.get(suiteName);
9.769 + r.update(testSession.getReport(lastSuiteTime));
9.770 + manager.displayReport(testSession, r, false);
9.771 + }
9.772 +
9.773 + private String getMessage(String msg) {
9.774 + int prefixLength = RegexpUtils.TEST_LISTENER_PREFIX.length();
9.775 + return msg.substring(prefixLength);
9.776 + }
9.777 }
10.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGSuite.java Sun Oct 30 22:14:10 2011 +0100
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,78 +0,0 @@
10.4 -/*
10.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
10.6 - *
10.7 - * Copyright © 2010-2011 Oracle and/or its affiliates. All rights reserved.
10.8 - *
10.9 - * The contents of this file are subject to the terms of either the GNU
10.10 - * General Public License Version 2 only ("GPL") or the Common
10.11 - * Development and Distribution License("CDDL") (collectively, the
10.12 - * "License"). You may not use this file except in compliance with the
10.13 - * License. You can obtain a copy of the License at
10.14 - * http://www.netbeans.org/cddl-gplv2.html
10.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
10.16 - * specific language governing permissions and limitations under the
10.17 - * License. When distributing the software, include this License Header
10.18 - * Notice in each file and include the License file at
10.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
10.20 - * particular file as subject to the "Classpath" exception as provided
10.21 - * by Sun in the GPL Version 2 section of the License file that
10.22 - * accompanied this code. If applicable, add the following below the
10.23 - * License Header, with the fields enclosed by brackets [] replaced by
10.24 - * your own identifying information:
10.25 - * "Portions Copyrighted [year] [name of copyright owner]"
10.26 - *
10.27 - * If you wish your version of this file to be governed by only the CDDL
10.28 - * or only the GPL Version 2, indicate your decision by adding
10.29 - * "[Contributor] elects to include this software in this distribution
10.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
10.31 - * single choice of license, a recipient has the option to distribute
10.32 - * your version of this file under either the CDDL, the GPL Version 2 or
10.33 - * to extend the choice of license to its licensees as provided above.
10.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
10.35 - * Version 2 license, then the option applies only if the new code is
10.36 - * made subject to such option by the copyright holder.
10.37 - *
10.38 - * Contributor(s):
10.39 - *
10.40 - * Portions Copyrighted 2010 Sun Microsystems, Inc.
10.41 - */
10.42 -
10.43 -package org.netbeans.modules.contrib.testng.output;
10.44 -
10.45 -import java.util.ArrayList;
10.46 -import java.util.List;
10.47 -
10.48 -/**
10.49 - *
10.50 - * @author lukas
10.51 - */
10.52 -public class TestNGSuite {
10.53 -
10.54 - private String name;
10.55 - private List<TestNGTest> suites;
10.56 -
10.57 - public TestNGSuite(String name) {
10.58 - this.name = name;
10.59 - suites = new ArrayList<TestNGTest>();
10.60 - }
10.61 -
10.62 - public void addTestNGTest(TestNGTest ts) {
10.63 - suites.add(ts);
10.64 - }
10.65 -
10.66 - public List<TestNGTestSuite> getTestSuites() {
10.67 - List<TestNGTestSuite> s = new ArrayList<TestNGTestSuite>();
10.68 - for (TestNGTest t: suites) {
10.69 - s.addAll(t.getTestcases());
10.70 - }
10.71 - return s;
10.72 - }
10.73 -
10.74 - List<TestNGTest> getTestNGTests() {
10.75 - return suites;
10.76 - }
10.77 -
10.78 - public String getName() {
10.79 - return name;
10.80 - }
10.81 -}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGSuiteNode.java Thu Nov 10 15:48:37 2011 +0100
11.3 @@ -0,0 +1,96 @@
11.4 +/*
11.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
11.6 + *
11.7 + * Copyright © 1997-2011 Oracle and/or its affiliates. All rights reserved.
11.8 + *
11.9 + * The contents of this file are subject to the terms of either the GNU
11.10 + * General Public License Version 2 only ("GPL") or the Common
11.11 + * Development and Distribution License("CDDL") (collectively, the
11.12 + * "License"). You may not use this file except in compliance with the
11.13 + * License. You can obtain a copy of the License at
11.14 + * http://www.netbeans.org/cddl-gplv2.html
11.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11.16 + * specific language governing permissions and limitations under the
11.17 + * License. When distributing the software, include this License Header
11.18 + * Notice in each file and include the License file at
11.19 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
11.20 + * particular file as subject to the "Classpath" exception as provided
11.21 + * by Sun in the GPL Version 2 section of the License file that
11.22 + * accompanied this code. If applicable, add the following below the
11.23 + * License Header, with the fields enclosed by brackets [] replaced by
11.24 + * your own identifying information:
11.25 + * "Portions Copyrighted [year] [name of copyright owner]"
11.26 + *
11.27 + * Contributor(s):
11.28 + *
11.29 + * The Original Software is NetBeans. The Initial Developer of the Original
11.30 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
11.31 + * Microsystems, Inc. All Rights Reserved.
11.32 + *
11.33 + * If you wish your version of this file to be governed by only the CDDL
11.34 + * or only the GPL Version 2, indicate your decision by adding
11.35 + * "[Contributor] elects to include this software in this distribution
11.36 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
11.37 + * single choice of license, a recipient has the option to distribute
11.38 + * your version of this file under either the CDDL, the GPL Version 2 or
11.39 + * to extend the choice of license to its licensees as provided above.
11.40 + * However, if you add GPL Version 2 code and therefore, elected the GPL
11.41 + * Version 2 license, then the option applies only if the new code is
11.42 + * made subject to such option by the copyright holder.
11.43 + */
11.44 +
11.45 +package org.netbeans.modules.contrib.testng.output;
11.46 +
11.47 +import java.util.ArrayList;
11.48 +import java.util.List;
11.49 +import javax.swing.Action;
11.50 +import org.netbeans.modules.contrib.testng.actions.DebugTestClassAction;
11.51 +import org.netbeans.modules.contrib.testng.actions.RunTestClassAction;
11.52 +import org.netbeans.modules.gsf.testrunner.api.TestsuiteNode;
11.53 +import org.openide.util.actions.SystemAction;
11.54 +import org.openide.util.lookup.AbstractLookup;
11.55 +import org.openide.util.lookup.InstanceContent;
11.56 +
11.57 +/**
11.58 + *
11.59 + * @author Marian Petras
11.60 + */
11.61 +public final class TestNGSuiteNode extends TestsuiteNode {
11.62 +
11.63 + private InstanceContent ic;
11.64 +
11.65 + /**
11.66 + *
11.67 + * @param suiteName name of the test suite, or {@code ANONYMOUS_SUITE}
11.68 + * in the case of anonymous suite
11.69 + * @see ResultDisplayHandler#ANONYMOUS_SUITE
11.70 + */
11.71 + public TestNGSuiteNode(final String suiteName, final boolean filtered) {
11.72 + this(suiteName, filtered, new InstanceContent());
11.73 + }
11.74 +
11.75 + private TestNGSuiteNode(String suiteName, boolean filtered, InstanceContent ic) {
11.76 + super(null, suiteName, filtered, new AbstractLookup(ic));
11.77 + this.ic = ic;
11.78 + }
11.79 +
11.80 + @Override
11.81 + public Action[] getActions(boolean context) {
11.82 + ic.add(((TestNGTestSuite) getSuite()).getSuiteFO());
11.83 + List<Action> actions = new ArrayList<Action>();
11.84 + Action preferred = getPreferredAction();
11.85 + if (preferred != null) {
11.86 + actions.add(preferred);
11.87 + }
11.88 + actions.add(SystemAction.get(RunTestClassAction.class));
11.89 + actions.add(SystemAction.get(DebugTestClassAction.class));
11.90 + return actions.toArray(new Action[actions.size()]);
11.91 + }
11.92 +
11.93 + @Override
11.94 + public Action getPreferredAction() {
11.95 + return new JumpAction(this, null);
11.96 + }
11.97 +
11.98 +
11.99 +}
12.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestNodeFactory.java Sun Oct 30 22:14:10 2011 +0100
12.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestNodeFactory.java Thu Nov 10 15:48:37 2011 +0100
12.3 @@ -42,6 +42,7 @@
12.4 import org.netbeans.api.project.Project;
12.5 import org.netbeans.modules.gsf.testrunner.api.TestRunnerNodeFactory;
12.6 import org.netbeans.modules.gsf.testrunner.api.Testcase;
12.7 +import org.netbeans.modules.gsf.testrunner.api.TestsuiteNode;
12.8 import org.openide.nodes.Node;
12.9
12.10 /**
12.11 @@ -52,7 +53,7 @@
12.12
12.13 @Override
12.14 public Node createTestMethodNode(Testcase testcase, Project project) {
12.15 - return new TestMethodNode(testcase, project);
12.16 + return new TestNGMethodNode(testcase, project);
12.17 }
12.18
12.19 @Override
12.20 @@ -61,8 +62,8 @@
12.21 }
12.22
12.23 @Override
12.24 - public org.netbeans.modules.gsf.testrunner.api.TestsuiteNode createTestSuiteNode(String suiteName, boolean filtered) {
12.25 - return new TestsuiteNode(suiteName, filtered);
12.26 + public TestsuiteNode createTestSuiteNode(String suiteName, boolean filtered) {
12.27 + return new TestNGSuiteNode(suiteName, filtered);
12.28 }
12.29
12.30 }
13.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestSession.java Sun Oct 30 22:14:10 2011 +0100
13.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestSession.java Thu Nov 10 15:48:37 2011 +0100
13.3 @@ -39,8 +39,10 @@
13.4 package org.netbeans.modules.contrib.testng.output;
13.5
13.6 import java.lang.reflect.Method;
13.7 +import java.util.ArrayList;
13.8 import java.util.Arrays;
13.9 import java.util.HashSet;
13.10 +import java.util.List;
13.11 import java.util.Set;
13.12 import org.netbeans.api.extexecution.print.LineConvertors.FileLocator;
13.13 import org.netbeans.api.java.classpath.ClassPath;
13.14 @@ -55,6 +57,7 @@
13.15 import org.netbeans.api.project.Sources;
13.16 import org.netbeans.modules.gsf.testrunner.api.TestRunnerNodeFactory;
13.17 import org.netbeans.modules.gsf.testrunner.api.TestSession;
13.18 +import org.netbeans.modules.gsf.testrunner.api.TestSuite;
13.19 import org.netbeans.spi.java.classpath.ClassPathProvider;
13.20 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
13.21 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
13.22 @@ -67,6 +70,8 @@
13.23 public class TestNGTestSession extends TestSession {
13.24
13.25 private FileLocator projectFileLocator = null;
13.26 + private final List<TestNGTestSuite> suites = new ArrayList<TestNGTestSuite>();
13.27 + private TestSuite currentSuite;
13.28
13.29 public TestNGTestSession(String name, Project project, SessionType sessionType, TestRunnerNodeFactory nodeFactory) {
13.30 super(name, project, sessionType, nodeFactory);
13.31 @@ -84,6 +89,30 @@
13.32 return locator;
13.33 }
13.34
13.35 + @Override
13.36 + public void addSuite(TestSuite suite) {
13.37 + super.addSuite(suite);
13.38 + suites.add((TestNGTestSuite) suite);
13.39 + }
13.40 +
13.41 + @Override
13.42 + public TestSuite getCurrentSuite() {
13.43 + if (currentSuite == null) {
13.44 + return super.getCurrentSuite();
13.45 + }
13.46 + return currentSuite;
13.47 + }
13.48 +
13.49 + public void setCurrentSuite(String name) {
13.50 + for (TestNGTestSuite ts : suites) {
13.51 + if (ts.getName().equals(name)) {
13.52 + currentSuite = ts;
13.53 + break;
13.54 + }
13.55 + }
13.56 + }
13.57 +
13.58 +
13.59 class ProjectFileLocator implements FileLocator {
13.60
13.61 private ClassPath classpath;
14.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestSuite.java Sun Oct 30 22:14:10 2011 +0100
14.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestSuite.java Thu Nov 10 15:48:37 2011 +0100
14.3 @@ -38,11 +38,12 @@
14.4 */
14.5 package org.netbeans.modules.contrib.testng.output;
14.6
14.7 -import java.util.List;
14.8 -import org.netbeans.api.extexecution.print.LineConvertors.FileLocator;
14.9 +import java.io.File;
14.10 import org.netbeans.modules.gsf.testrunner.api.TestSession;
14.11 import org.netbeans.modules.gsf.testrunner.api.TestSuite;
14.12 +import org.netbeans.modules.gsf.testrunner.api.Testcase;
14.13 import org.openide.filesystems.FileObject;
14.14 +import org.openide.filesystems.FileUtil;
14.15
14.16 /**
14.17 *
14.18 @@ -54,20 +55,30 @@
14.19 private final TestSession session;
14.20 private FileObject suiteFO = null;
14.21 private long elapsedTime = 0;
14.22 + private int expectedTestCases;
14.23 + private FileObject cfgFO;
14.24
14.25 - public TestNGTestSuite(String name, TestSession session) {
14.26 + TestNGTestSuite(String tcClassName, TestSession testSession) {
14.27 + super(tcClassName);
14.28 + this.session = testSession;
14.29 + }
14.30 +
14.31 + public TestNGTestSuite(String name, TestSession session, int expectedTCases, String configFile) {
14.32 super(name);
14.33 this.session = session;
14.34 + expectedTestCases = expectedTCases;
14.35 + cfgFO = configFile.equals("null") ? null : FileUtil.toFileObject(FileUtil.normalizeFile(new File(configFile)));
14.36 }
14.37
14.38 FileObject getSuiteFO() {
14.39 - if (suiteFO == null) {
14.40 - FileLocator locator = session.getFileLocator();
14.41 - if (locator != null) {
14.42 - suiteFO = locator.find(getName().replace('.', '/') + ".java"); //NOI18N
14.43 - }
14.44 - }
14.45 - return suiteFO;
14.46 + return cfgFO;
14.47 +// if (suiteFO == null) {
14.48 +// FileLocator locator = session.getFileLocator();
14.49 +// if (locator != null) {
14.50 +// suiteFO = locator.find(getName().replace('.', '/') + ".java"); //NOI18N
14.51 +// }
14.52 +// }
14.53 +// return suiteFO;
14.54 }
14.55
14.56 public long getElapsedTime() {
14.57 @@ -77,4 +88,19 @@
14.58 public void setElapsedTime(long elapsedTime) {
14.59 this.elapsedTime = elapsedTime;
14.60 }
14.61 +
14.62 + public void finish(int run, int fail, int skip, int confFail, int confSkip) {
14.63 + //not needed?
14.64 + //TODO: update tcases with proper status
14.65 + }
14.66 +
14.67 + public TestNGTestcase getTestCase(String testCase, String parameters) {
14.68 + for (Testcase tc: getTestcases()) {
14.69 + if (tc.getName().equals(testCase) && ((TestNGTestcase) tc).getParameters().equals(parameters)) {
14.70 + return (TestNGTestcase) tc;
14.71 + }
14.72 + }
14.73 + return null;
14.74 + }
14.75 +
14.76 }
15.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestcase.java Sun Oct 30 22:14:10 2011 +0100
15.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/TestNGTestcase.java Thu Nov 10 15:48:37 2011 +0100
15.3 @@ -38,6 +38,8 @@
15.4 */
15.5 package org.netbeans.modules.contrib.testng.output;
15.6
15.7 +import java.util.ArrayList;
15.8 +import java.util.List;
15.9 import org.netbeans.api.extexecution.print.LineConvertors.FileLocator;
15.10 import org.netbeans.modules.gsf.testrunner.api.TestSession;
15.11 import org.netbeans.modules.gsf.testrunner.api.Testcase;
15.12 @@ -52,10 +54,26 @@
15.13
15.14 private FileObject classFO = null;
15.15 private boolean confMethod = false;
15.16 + private String parameters;
15.17 + private List<String> values = new ArrayList<String>();
15.18
15.19
15.20 - public TestNGTestcase(String name, String type, TestSession session) {
15.21 - super(name, type, session);
15.22 + public TestNGTestcase(String name, String params, String values, TestSession session) {
15.23 + super(name, "TestNG Test", session);
15.24 + parameters = params;
15.25 + this.values.add(values);
15.26 + }
15.27 +
15.28 + public String getParameters() {
15.29 + return parameters;
15.30 + }
15.31 +
15.32 + public void addValues(String values) {
15.33 + this.values.add(values);
15.34 + }
15.35 +
15.36 + public int getInvocationCount() {
15.37 + return values.size();
15.38 }
15.39
15.40 public FileObject getClassFileObject() {
16.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/TestsuiteNode.java Sun Oct 30 22:14:10 2011 +0100
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,94 +0,0 @@
16.4 -/*
16.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
16.6 - *
16.7 - * Copyright © 1997-2011 Oracle and/or its affiliates. All rights reserved.
16.8 - *
16.9 - * The contents of this file are subject to the terms of either the GNU
16.10 - * General Public License Version 2 only ("GPL") or the Common
16.11 - * Development and Distribution License("CDDL") (collectively, the
16.12 - * "License"). You may not use this file except in compliance with the
16.13 - * License. You can obtain a copy of the License at
16.14 - * http://www.netbeans.org/cddl-gplv2.html
16.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16.16 - * specific language governing permissions and limitations under the
16.17 - * License. When distributing the software, include this License Header
16.18 - * Notice in each file and include the License file at
16.19 - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
16.20 - * particular file as subject to the "Classpath" exception as provided
16.21 - * by Sun in the GPL Version 2 section of the License file that
16.22 - * accompanied this code. If applicable, add the following below the
16.23 - * License Header, with the fields enclosed by brackets [] replaced by
16.24 - * your own identifying information:
16.25 - * "Portions Copyrighted [year] [name of copyright owner]"
16.26 - *
16.27 - * Contributor(s):
16.28 - *
16.29 - * The Original Software is NetBeans. The Initial Developer of the Original
16.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
16.31 - * Microsystems, Inc. All Rights Reserved.
16.32 - *
16.33 - * If you wish your version of this file to be governed by only the CDDL
16.34 - * or only the GPL Version 2, indicate your decision by adding
16.35 - * "[Contributor] elects to include this software in this distribution
16.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
16.37 - * single choice of license, a recipient has the option to distribute
16.38 - * your version of this file under either the CDDL, the GPL Version 2 or
16.39 - * to extend the choice of license to its licensees as provided above.
16.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
16.41 - * Version 2 license, then the option applies only if the new code is
16.42 - * made subject to such option by the copyright holder.
16.43 - */
16.44 -
16.45 -package org.netbeans.modules.contrib.testng.output;
16.46 -
16.47 -import java.util.ArrayList;
16.48 -import java.util.List;
16.49 -import javax.swing.Action;
16.50 -import org.netbeans.modules.contrib.testng.actions.DebugTestClassAction;
16.51 -import org.netbeans.modules.contrib.testng.actions.RunTestClassAction;
16.52 -import org.openide.util.actions.SystemAction;
16.53 -import org.openide.util.lookup.AbstractLookup;
16.54 -import org.openide.util.lookup.InstanceContent;
16.55 -
16.56 -/**
16.57 - *
16.58 - * @author Marian Petras
16.59 - */
16.60 -public final class TestsuiteNode extends org.netbeans.modules.gsf.testrunner.api.TestsuiteNode {
16.61 -
16.62 - private InstanceContent ic;
16.63 -
16.64 - /**
16.65 - *
16.66 - * @param suiteName name of the test suite, or {@code ANONYMOUS_SUITE}
16.67 - * in the case of anonymous suite
16.68 - * @see ResultDisplayHandler#ANONYMOUS_SUITE
16.69 - */
16.70 - public TestsuiteNode(final String suiteName, final boolean filtered) {
16.71 - this(suiteName, filtered, new InstanceContent());
16.72 - }
16.73 -
16.74 - private TestsuiteNode(String suiteName, boolean filtered, InstanceContent ic) {
16.75 - super(null, suiteName, filtered, new AbstractLookup(ic));
16.76 - this.ic = ic;
16.77 - }
16.78 -
16.79 - @Override
16.80 - public Action[] getActions(boolean context) {
16.81 - ic.add(((TestNGTestSuite) getSuite()).getSuiteFO());
16.82 - List<Action> actions = new ArrayList<Action>();
16.83 - Action preferred = getPreferredAction();
16.84 - if (preferred != null) {
16.85 - actions.add(preferred);
16.86 - }
16.87 - actions.add(SystemAction.get(RunTestClassAction.class));
16.88 - actions.add(SystemAction.get(DebugTestClassAction.class));
16.89 - return actions.toArray(new Action[actions.size()]);
16.90 - }
16.91 -
16.92 - @Override
16.93 - public Action getPreferredAction() {
16.94 - return new JumpAction(this, null);
16.95 - }
16.96 -
16.97 -}
17.1 --- a/testng/src/org/netbeans/modules/contrib/testng/output/XmlOutputParser.java Sun Oct 30 22:14:10 2011 +0100
17.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/XmlOutputParser.java Thu Nov 10 15:48:37 2011 +0100
17.3 @@ -40,6 +40,8 @@
17.4
17.5 import java.io.IOException;
17.6 import java.io.Reader;
17.7 +import java.util.ArrayList;
17.8 +import java.util.List;
17.9 import java.util.logging.Logger;
17.10 import org.netbeans.modules.gsf.testrunner.api.Status;
17.11 import org.netbeans.modules.gsf.testrunner.api.TestSession;
17.12 @@ -85,7 +87,7 @@
17.13 private static final int STATE_FULL_STACKTRACE = 15;
17.14 private int state = STATE_OUT_OF_SCOPE;
17.15 /** */
17.16 - private TestNGSuite reports;
17.17 + private XmlResult reports;
17.18 private TestNGTest test;
17.19 private TestNGTestSuite testsuite;
17.20 private TestNGTestcase testcase;
17.21 @@ -102,7 +104,7 @@
17.22 xmlReader.setContentHandler(this);
17.23 }
17.24
17.25 - static TestNGSuite parseXmlOutput(Reader reader, TestSession session) throws SAXException, IOException {
17.26 + static XmlResult parseXmlOutput(Reader reader, TestSession session) throws SAXException, IOException {
17.27 assert reader != null;
17.28 XmlOutputParser parser = new XmlOutputParser(session);
17.29 try {
17.30 @@ -148,6 +150,7 @@
17.31 if ("class".equals(qName)) { //NOI18N
17.32 tcClassName = attributes.getValue("name"); //NOI18N
17.33 testsuite = new TestNGTestSuite(tcClassName, testSession);
17.34 +
17.35 state = STATE_CLASS;
17.36 }
17.37 break;
17.38 @@ -212,7 +215,7 @@
17.39 if (name == null || "".equals(name.trim())) {
17.40 name = NbBundle.getMessage(XmlOutputParser.class, "UNKNOWN_NAME");
17.41 }
17.42 - reports = new TestNGSuite(name);
17.43 + reports = new XmlResult(name);
17.44 state = STATE_SUITE;
17.45 }
17.46 }
17.47 @@ -330,7 +333,8 @@
17.48 }
17.49
17.50 private TestNGTestcase createTestcaseReport(String className, String name, int time) {
17.51 - TestNGTestcase tc = new TestNGTestcase(name, "TestNG Test", testSession);
17.52 +// TestNGTestcase tc = new TestNGTestcase(name, "TestNG Test", testSession);
17.53 + TestNGTestcase tc = new TestNGTestcase(name, "params", "values", testSession);
17.54 tc.setTimeMillis(time);
17.55 tc.setClassName(className);
17.56 return tc;
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/testng/src/org/netbeans/modules/contrib/testng/output/XmlResult.java Thu Nov 10 15:48:37 2011 +0100
18.3 @@ -0,0 +1,78 @@
18.4 +/*
18.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
18.6 + *
18.7 + * Copyright © 2010-2011 Oracle and/or its affiliates. All rights reserved.
18.8 + *
18.9 + * The contents of this file are subject to the terms of either the GNU
18.10 + * General Public License Version 2 only ("GPL") or the Common
18.11 + * Development and Distribution License("CDDL") (collectively, the
18.12 + * "License"). You may not use this file except in compliance with the
18.13 + * License. You can obtain a copy of the License at
18.14 + * http://www.netbeans.org/cddl-gplv2.html
18.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18.16 + * specific language governing permissions and limitations under the
18.17 + * License. When distributing the software, include this License Header
18.18 + * Notice in each file and include the License file at
18.19 + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
18.20 + * particular file as subject to the "Classpath" exception as provided
18.21 + * by Sun in the GPL Version 2 section of the License file that
18.22 + * accompanied this code. If applicable, add the following below the
18.23 + * License Header, with the fields enclosed by brackets [] replaced by
18.24 + * your own identifying information:
18.25 + * "Portions Copyrighted [year] [name of copyright owner]"
18.26 + *
18.27 + * If you wish your version of this file to be governed by only the CDDL
18.28 + * or only the GPL Version 2, indicate your decision by adding
18.29 + * "[Contributor] elects to include this software in this distribution
18.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
18.31 + * single choice of license, a recipient has the option to distribute
18.32 + * your version of this file under either the CDDL, the GPL Version 2 or
18.33 + * to extend the choice of license to its licensees as provided above.
18.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
18.35 + * Version 2 license, then the option applies only if the new code is
18.36 + * made subject to such option by the copyright holder.
18.37 + *
18.38 + * Contributor(s):
18.39 + *
18.40 + * Portions Copyrighted 2010 Sun Microsystems, Inc.
18.41 + */
18.42 +
18.43 +package org.netbeans.modules.contrib.testng.output;
18.44 +
18.45 +import java.util.ArrayList;
18.46 +import java.util.List;
18.47 +
18.48 +/**
18.49 + *
18.50 + * @author lukas
18.51 + */
18.52 +public class XmlResult {
18.53 +
18.54 + private String name;
18.55 + private List<TestNGTest> suites;
18.56 +
18.57 + public XmlResult(String name) {
18.58 + this.name = name;
18.59 + suites = new ArrayList<TestNGTest>();
18.60 + }
18.61 +
18.62 + public void addTestNGTest(TestNGTest ts) {
18.63 + suites.add(ts);
18.64 + }
18.65 +
18.66 + public List<TestNGTestSuite> getTestSuites() {
18.67 + List<TestNGTestSuite> s = new ArrayList<TestNGTestSuite>();
18.68 + for (TestNGTest t: suites) {
18.69 + s.addAll(t.getTestcases());
18.70 + }
18.71 + return s;
18.72 + }
18.73 +
18.74 + List<TestNGTest> getTestNGTests() {
18.75 + return suites;
18.76 + }
18.77 +
18.78 + public String getName() {
18.79 + return name;
18.80 + }
18.81 +}
19.1 --- a/testng/test/unit/src/org/netbeans/modules/contrib/testng/output/RegexpUtilsTest.java Sun Oct 30 22:14:10 2011 +0100
19.2 +++ b/testng/test/unit/src/org/netbeans/modules/contrib/testng/output/RegexpUtilsTest.java Thu Nov 10 15:48:37 2011 +0100
19.3 @@ -508,6 +508,80 @@
19.4 assertEquals("ab c\tde", specialTrim("ab c\tde\t"));
19.5 }
19.6
19.7 + public void testRunningSuite() throws Exception {
19.8 + Pattern pattern = getPattern("RUNNING_SUITE_REGEX");
19.9 + final String matchingString =
19.10 + "[NBTestListener] RUNNING: Suite: \"Junit via TestNG XML\" containing \"5\" Tests (config: /space/sources/tng_fork/src/test/resources/junit-suite.xml)";
19.11 + Matcher m = pattern.matcher(matchingString);
19.12 + assertTrue(m.matches());
19.13 + assertEquals(4, m.groupCount());
19.14 + assertEquals("Junit via TestNG XML", m.group(1));
19.15 + assertEquals("5", m.group(2));
19.16 + assertEquals("/space/sources/tng_fork/src/test/resources/junit-suite.xml", m.group(3));
19.17 + final String matchingString2 =
19.18 + "[NBTestListener] RUNNING: Suite: \"Junit via TestNG XML\" containing \"5\" Tests (config: c:\\test\\resources\\junit-suite.xml)";
19.19 + m = pattern.matcher(matchingString2);
19.20 + assertTrue(m.matches());
19.21 + assertEquals(4, m.groupCount());
19.22 + assertEquals("Junit via TestNG XML", m.group(1));
19.23 + assertEquals("5", m.group(2));
19.24 + assertEquals("c:\\test\\resources\\junit-suite.xml", m.group(3));
19.25 + }
19.26 +
19.27 + public void testTestRegexp() throws Exception {
19.28 + Pattern pattern = getPattern("TEST_REGEX");
19.29 + final String matchingString =
19.30 + "[NBTestListener] PASSED: \"Regression1\" - test.parameters.ParameterSample.testSingleString()";
19.31 + Matcher m = pattern.matcher(matchingString);
19.32 + assertTrue(m.matches());
19.33 + assertEquals(6, m.groupCount());
19.34 + assertEquals("Regression1", m.group(1));
19.35 + assertEquals("test.parameters.ParameterSample.testSingleString", m.group(2));
19.36 + assertEquals("", m.group(3));
19.37 + assertNull(m.group(4));
19.38 + assertNull(m.group(5));
19.39 + final String matchingString2 =
19.40 + "[NBTestListener] PASSED: \"Regression1\" - test.parameters.ParameterSample.testSingleString(java.lang.String)(value(s): \"Cedric\")";
19.41 + m = pattern.matcher(matchingString2);
19.42 + assertTrue(m.matches());
19.43 + assertEquals(6, m.groupCount());
19.44 + assertEquals("Regression1", m.group(1));
19.45 + assertEquals("test.parameters.ParameterSample.testSingleString", m.group(2));
19.46 + assertEquals("java.lang.String", m.group(3));
19.47 + assertEquals("(value(s): \"Cedric\")", m.group(4));
19.48 + assertEquals("\"Cedric\"", m.group(5));
19.49 + final String matchingString3 =
19.50 + "[NBTestListener] PASSED: \"Injection\" - test.inject.NoInjectionTest.withInjection(java.lang.reflect.Method)(value(s): public void test.inject.NoInjectionTest.withInjection(java.lang.reflect.Method))";
19.51 + m = pattern.matcher(matchingString3);
19.52 + assertTrue(m.matches());
19.53 + assertEquals(6, m.groupCount());
19.54 + assertEquals("Injection", m.group(1));
19.55 + assertEquals("test.inject.NoInjectionTest.withInjection", m.group(2));
19.56 + assertEquals("java.lang.reflect.Method", m.group(3));
19.57 + assertEquals("(value(s): public void test.inject.NoInjectionTest.withInjection(java.lang.reflect.Method))", m.group(4));
19.58 + assertEquals("java.lang.reflect.Method", m.group(5));
19.59 + }
19.60 +
19.61 + public void testStatsRegexp() throws Exception {
19.62 + Pattern pattern = getPattern("STATS_REGEX");
19.63 + final String matchingString =
19.64 + "[NBTestListener] Tests run: 559, Failures: 4, Skips: 9";
19.65 + Matcher m = pattern.matcher(matchingString);
19.66 + assertTrue(m.matches());
19.67 + assertEquals(5, m.groupCount());
19.68 + assertEquals("559", m.group(1));
19.69 + assertEquals("4", m.group(2));
19.70 + assertEquals("9", m.group(4));
19.71 + final String matchingString2 =
19.72 + "[NBTestListener] Configuration Failures: 22, Skips: 11";
19.73 + m = pattern.matcher(matchingString2);
19.74 + assertTrue(m.matches());
19.75 + assertEquals(5, m.groupCount());
19.76 + assertEquals("22", m.group(1));
19.77 + assertEquals("11", m.group(2));
19.78 + assertNull(m.group(3));
19.79 + assertNull(m.group(4));
19.80 + }
19.81
19.82 private Pattern getPattern(String fieldName) throws Exception {
19.83 return Pattern.compile(getRegex(fieldName));
20.1 --- a/testng/test/unit/src/org/netbeans/modules/contrib/testng/output/XmlOutputParserTest.java Sun Oct 30 22:14:10 2011 +0100
20.2 +++ b/testng/test/unit/src/org/netbeans/modules/contrib/testng/output/XmlOutputParserTest.java Thu Nov 10 15:48:37 2011 +0100
20.3 @@ -38,11 +38,7 @@
20.4 */
20.5 package org.netbeans.modules.contrib.testng.output;
20.6
20.7 -import java.io.BufferedReader;
20.8 -import java.io.File;
20.9 -import java.io.FileReader;
20.10 -import java.io.IOException;
20.11 -import java.io.Reader;
20.12 +import java.io.*;
20.13 import java.util.List;
20.14 import org.netbeans.api.project.Project;
20.15 import org.netbeans.junit.NbTestCase;
20.16 @@ -64,7 +60,7 @@
20.17 }
20.18
20.19 public void testParseSimpleXmlOutput() throws Exception {
20.20 - TestNGSuite suite = parseResultXML(new File(getDataDir(), "results/testng-results.xml"));
20.21 + XmlResult suite = parseResultXML(new File(getDataDir(), "results/testng-results.xml"));
20.22 assertEquals("Ant suite", suite.getName());
20.23 List<TestNGTest> testNGTests = suite.getTestNGTests();
20.24 assertEquals(2, testNGTests.size());
20.25 @@ -109,14 +105,14 @@
20.26 }
20.27
20.28 public void testParseXmlOutput() throws Exception {
20.29 - TestNGSuite reports = parseResultXML(new File(getDataDir(), "results/testng-results_1.xml"));
20.30 + XmlResult reports = parseResultXML(new File(getDataDir(), "results/testng-results_1.xml"));
20.31 assertEquals(22, reports.getTestNGTests().size());
20.32 List<TestNGTestSuite> testSuites = reports.getTestSuites();
20.33 assertEquals(71, testSuites.size());
20.34 }
20.35
20.36 public void testParseXmlOutput2() throws Exception {
20.37 - TestNGSuite reports = parseResultXML(new File(getDataDir(), "results/testng-results_2.xml"));
20.38 + XmlResult reports = parseResultXML(new File(getDataDir(), "results/testng-results_2.xml"));
20.39 List<TestNGTestSuite> testSuites = reports.getTestSuites();
20.40 assertEquals(1, testSuites.size());
20.41 int tc = 0;
20.42 @@ -126,7 +122,7 @@
20.43 assertEquals(6, tc);
20.44 }
20.45
20.46 - TestNGSuite parseResultXML(File f) throws IOException, SAXException {
20.47 + XmlResult parseResultXML(File f) throws IOException, SAXException {
20.48 Reader reader = new BufferedReader(new FileReader(f));
20.49 TestSession ts = new TestSession("test", new P(), SessionType.TEST);
20.50 return XmlOutputParser.parseXmlOutput(reader, ts);