You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by kr...@apache.org on 2011/04/27 23:20:16 UTC
svn commit: r1097246 [2/5] - in /maven/surefire/trunk:
maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/
maven-surefire-common/src/main/java/org/apache/maven/plug...
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java Wed Apr 27 21:20:12 2011
@@ -19,6 +19,13 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
import org.apache.maven.surefire.booter.BooterDeserializer;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
@@ -30,14 +37,6 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.testset.TestArtifactInfo;
import org.apache.maven.surefire.testset.TestRequest;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -53,7 +52,7 @@ public class BooterDeserializerProviderC
private final String aTest = "aTest";
private final String aUserRequestedTest = "aUserRequestedTest";
-
+
private final String aUserRequestedTestMethod = "aUserRequestedTestMethod";
public static ClassLoaderConfiguration getForkConfiguration()
@@ -77,7 +76,7 @@ public class BooterDeserializerProviderC
ClassLoaderConfiguration forkConfiguration = getForkConfiguration();
final StartupConfiguration testStartupConfiguration = getTestStartupConfiguration( forkConfiguration );
- ProviderConfiguration providerConfiguration = getReloadedProviderConfiguration( new ArrayList() );
+ ProviderConfiguration providerConfiguration = getReloadedProviderConfiguration();
ProviderConfiguration read = saveAndReload( providerConfiguration, testStartupConfiguration );
Assert.assertEquals( aDir, read.getBaseDir() );
@@ -93,34 +92,20 @@ public class BooterDeserializerProviderC
{
DirectoryScannerParameters directoryScannerParameters = getDirectoryScannerParameters();
ClassLoaderConfiguration forkConfiguration = getForkConfiguration();
- List reports = new ArrayList();
- final String first = "abc";
- final String second = "cde";
- final String third = "efg";
- reports.add( first );
- reports.add( second );
- reports.add( third );
-
- ProviderConfiguration providerConfiguration =
- getTestProviderConfiguration( directoryScannerParameters, reports );
-
- final ReporterConfiguration reporterConfiguration = providerConfiguration.getReporterConfiguration();
- reporterConfiguration.getReports().add( first );
- reporterConfiguration.getReports().add( second );
- reporterConfiguration.getReports().add( third );
+
+ ProviderConfiguration providerConfiguration = getTestProviderConfiguration( directoryScannerParameters );
final StartupConfiguration testProviderConfiguration = getTestStartupConfiguration( forkConfiguration );
ProviderConfiguration reloaded = saveAndReload( providerConfiguration, testProviderConfiguration );
- Assert.assertEquals( first, reloaded.getReporterConfiguration().getReports().get( 0 ) );
- Assert.assertEquals( second, reloaded.getReporterConfiguration().getReports().get( 1 ) );
- Assert.assertEquals( third, reloaded.getReporterConfiguration().getReports().get( 2 ) );
+ assertTrue( reloaded.getReporterConfiguration().isTrimStackTrace().booleanValue() );
+ assertNotNull( reloaded.getReporterConfiguration().getReportsDirectory() );
}
public void testTestArtifact()
throws IOException
{
- ProviderConfiguration reloaded = getReloadedProviderConfiguration( new ArrayList() );
+ ProviderConfiguration reloaded = getReloadedProviderConfiguration();
Assert.assertEquals( "5.0", reloaded.getTestArtifact().getVersion() );
Assert.assertEquals( "ABC", reloaded.getTestArtifact().getClassifier() );
@@ -129,7 +114,7 @@ public class BooterDeserializerProviderC
public void testTestRequest()
throws IOException
{
- ProviderConfiguration reloaded = getReloadedProviderConfiguration( new ArrayList() );
+ ProviderConfiguration reloaded = getReloadedProviderConfiguration();
TestRequest testSuiteDefinition = reloaded.getTestSuiteDefinition();
List suiteXmlFiles = testSuiteDefinition.getSuiteXmlFiles();
@@ -143,7 +128,7 @@ public class BooterDeserializerProviderC
public void testTestForFork()
throws IOException
{
- final ProviderConfiguration reloaded = getReloadedProviderConfiguration( new ArrayList() );
+ final ProviderConfiguration reloaded = getReloadedProviderConfiguration();
Assert.assertEquals( aTest, reloaded.getTestForForkString() );
}
@@ -151,17 +136,17 @@ public class BooterDeserializerProviderC
public void testFailIfNoTests()
throws IOException
{
- ProviderConfiguration reloaded = getReloadedProviderConfiguration( new ArrayList() );
+ ProviderConfiguration reloaded = getReloadedProviderConfiguration();
assertTrue( reloaded.isFailIfNoTests().booleanValue() );
}
- private ProviderConfiguration getReloadedProviderConfiguration( ArrayList reports )
+ private ProviderConfiguration getReloadedProviderConfiguration()
throws IOException
{
DirectoryScannerParameters directoryScannerParameters = getDirectoryScannerParameters();
ClassLoaderConfiguration forkConfiguration = getForkConfiguration();
- ProviderConfiguration booterConfiguration = getTestProviderConfiguration( directoryScannerParameters, reports );
+ ProviderConfiguration booterConfiguration = getTestProviderConfiguration( directoryScannerParameters );
final StartupConfiguration testProviderConfiguration = getTestStartupConfiguration( forkConfiguration );
return saveAndReload( booterConfiguration, testProviderConfiguration );
}
@@ -186,34 +171,34 @@ public class BooterDeserializerProviderC
final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration();
Properties props = new Properties();
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
- booterSerializer.serialize( booterConfiguration, testProviderConfiguration, aTest );
+ booterSerializer.serialize( booterConfiguration, testProviderConfiguration, aTest, "never" );
final File propsTest =
SystemPropertyManager.writePropertiesFile( props, forkConfiguration.getTempDirectory(), "propsTest", true );
BooterDeserializer booterDeserializer = new BooterDeserializer( new FileInputStream( propsTest ) );
return booterDeserializer.deserialize();
}
- private ProviderConfiguration getTestProviderConfiguration( DirectoryScannerParameters directoryScannerParameters,
- List reports )
+ private ProviderConfiguration getTestProviderConfiguration( DirectoryScannerParameters directoryScannerParameters )
throws IOException
{
File cwd = new File( "." );
ReporterConfiguration reporterConfiguration =
- new ReporterConfiguration( reports, cwd, Boolean.TRUE, null );
+ new ReporterConfiguration( cwd, Boolean.TRUE, "abc", "cde", "efg", "hij" );
TestRequest testSuiteDefinition =
- new TestRequest( getSuiteXmlFileStrings(), getTestSourceDirectory(), aUserRequestedTest, aUserRequestedTestMethod );
+ new TestRequest( getSuiteXmlFileStrings(), getTestSourceDirectory(), aUserRequestedTest,
+ aUserRequestedTestMethod );
return new ProviderConfiguration( directoryScannerParameters, true, reporterConfiguration,
new TestArtifactInfo( "5.0", "ABC" ), testSuiteDefinition, new Properties(),
- aTest );
+ aTest, "never" );
}
private StartupConfiguration getTestStartupConfiguration( ClassLoaderConfiguration classLoaderConfiguration )
{
ClasspathConfiguration classpathConfiguration = new ClasspathConfiguration( true, true );
- return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration, false, false,
- false );
+ return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration, "never",
+ false, false );
}
private File getTestSourceDirectory()
Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java Wed Apr 27 21:20:12 2011
@@ -19,6 +19,12 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Properties;
import org.apache.maven.surefire.booter.BooterDeserializer;
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
@@ -32,13 +38,6 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.testset.TestArtifactInfo;
import org.apache.maven.surefire.testset.TestRequest;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Properties;
-
import junit.framework.TestCase;
/**
@@ -67,7 +66,8 @@ public class BooterDeserializerStartupCo
assertEquals( classpathConfiguration, reloadedClasspathConfiguration );
}
- private void assertEquals( ClasspathConfiguration expectedConfiguration, ClasspathConfiguration actualConfiguration )
+ private void assertEquals( ClasspathConfiguration expectedConfiguration,
+ ClasspathConfiguration actualConfiguration )
{
assertEquals( expectedConfiguration.getTestClasspath().getClassPath(),
actualConfiguration.getTestClasspath().getClassPath() );
@@ -79,7 +79,7 @@ public class BooterDeserializerStartupCo
private Properties getPropertiesForClasspathConfiguration( ClasspathConfiguration configuration )
{
Properties properties = new Properties();
- configuration.setForkProperties( new PropertiesWrapper( properties ));
+ configuration.setForkProperties( new PropertiesWrapper( properties ) );
return properties;
}
@@ -100,8 +100,8 @@ public class BooterDeserializerStartupCo
private ClasspathConfiguration createClasspathConfiguration()
{
- Classpath testClassPath = new Classpath( Arrays.asList( new String[]{"CP1" , "CP2" } ) );
- Classpath providerClasspath = new Classpath( Arrays.asList( new String[]{"SP1" , "SP2" } ) );
+ Classpath testClassPath = new Classpath( Arrays.asList( new String[]{ "CP1", "CP2" } ) );
+ Classpath providerClasspath = new Classpath( Arrays.asList( new String[]{ "SP1", "SP2" } ) );
return new ClasspathConfiguration( testClassPath, providerClasspath, true, true );
}
@@ -131,7 +131,7 @@ public class BooterDeserializerStartupCo
final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration();
Properties props = new Properties();
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
- booterSerializer.serialize( getProviderConfiguration(), startupConfiguration, aTest );
+ booterSerializer.serialize( getProviderConfiguration(), startupConfiguration, aTest, "never" );
final File propsTest =
SystemPropertyManager.writePropertiesFile( props, forkConfiguration.getTempDirectory(), "propsTest", true );
BooterDeserializer booterDeserializer = new BooterDeserializer( new FileInputStream( propsTest ) );
@@ -145,8 +145,7 @@ public class BooterDeserializerStartupCo
File cwd = new File( "." );
DirectoryScannerParameters directoryScannerParameters =
new DirectoryScannerParameters( cwd, new ArrayList(), new ArrayList(), Boolean.TRUE, "hourly" );
- ReporterConfiguration reporterConfiguration =
- new ReporterConfiguration( new ArrayList(), cwd, Boolean.TRUE, null );
+ ReporterConfiguration reporterConfiguration = new ReporterConfiguration( cwd, Boolean.TRUE );
String aUserRequestedTest = "aUserRequestedTest";
String aUserRequestedTestMethod = "aUserRequestedTestMethod";
TestRequest testSuiteDefinition =
@@ -154,13 +153,13 @@ public class BooterDeserializerStartupCo
aUserRequestedTestMethod );
return new ProviderConfiguration( directoryScannerParameters, true, reporterConfiguration,
new TestArtifactInfo( "5.0", "ABC" ), testSuiteDefinition, new Properties(),
- aTest );
+ aTest, "never" );
}
private StartupConfiguration getTestStartupConfiguration( ClassLoaderConfiguration classLoaderConfiguration )
{
- return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration, false, false,
- false );
+ return new StartupConfiguration( "com.provider", classpathConfiguration, classLoaderConfiguration, "never",
+ false, false );
}
private File getTestSourceDirectory()
Added: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java?rev=1097246&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java Wed Apr 27 21:20:12 2011
@@ -0,0 +1,376 @@
+package org.apache.maven.plugin.surefire.booterclient;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.Properties;
+import org.apache.maven.plugin.surefire.booterclient.output.ForkClient;
+import org.apache.maven.surefire.booter.ForkingRunListener;
+import org.apache.maven.surefire.report.CategorizedReportEntry;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.apache.maven.surefire.report.DirectConsoleReporter;
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ForkingRunListenerTest
+ extends TestCase
+{
+
+ private final ByteArrayOutputStream content;
+
+ private final PrintStream printStream;
+
+ final Integer defaultChannel = new Integer( 17 );
+
+ final Integer anotherChannel = new Integer( 18 );
+
+ public ForkingRunListenerTest()
+ {
+ this.content = new ByteArrayOutputStream();
+ printStream = new PrintStream( content );
+ }
+
+ private void reset()
+ {
+ printStream.flush();
+ content.reset();
+ }
+
+
+ public void testHeaderCreation()
+ {
+ final byte[] header = ForkingRunListener.createHeader( (byte) 'F', 0xCAFE );
+ String asString = new String( header );
+ assertEquals( "F,cafe,", asString );
+ }
+
+ public void testHeaderCreationShort()
+ {
+ final byte[] header = ForkingRunListener.createHeader( (byte) 'F', 0xE );
+ String asString = new String( header );
+ assertEquals( "F,000e,", asString );
+ }
+
+ public void testSetStarting()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testSetStarting( expected );
+ standardTestRun.assertExpected( MockReporter.SET_STARTING, expected );
+ }
+
+ public void testSetCompleted()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testSetCompleted( expected );
+ standardTestRun.assertExpected( MockReporter.SET_COMPLETED, expected );
+ }
+
+ public void testStarting()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testStarting( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_STARTING, expected );
+ }
+
+ public void testSucceded()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testSucceeded( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_SUCCEEDED, expected );
+ }
+
+ public void testFailed()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createReportEntryWithStackTrace();
+ standardTestRun.run().testFailed( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_FAILED, expected );
+ }
+
+ public void testFailedWithCommaInMessage()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createReportEntryWithSpecialMessage( "We, the people" );
+ standardTestRun.run().testFailed( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_FAILED, expected );
+ }
+
+ public void testFailedWithUnicodeEscapeInMessage()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createReportEntryWithSpecialMessage( "We, \\u0177 people" );
+ standardTestRun.run().testFailed( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_FAILED, expected );
+ }
+
+ public void testFailure()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testError( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_ERROR, expected );
+ }
+
+ public void testSkipped()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testSkipped( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_SKIPPED, expected );
+ }
+
+ public void testAssumptionFailure()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ReportEntry expected = createDefaultReportEntry();
+ standardTestRun.run().testAssumptionFailure( expected );
+ standardTestRun.assertExpected( MockReporter.TEST_ASSUMPTION_FAIL, expected );
+ }
+
+ public void testConsole()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ DirectConsoleReporter directConsoleReporter = (DirectConsoleReporter) standardTestRun.run();
+ directConsoleReporter.writeMessage( "HeyYou" );
+ standardTestRun.assertExpected( MockReporter.CONSOLE_OUTPUT, "HeyYou" );
+ }
+
+ public void testConsoleOutput()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ ConsoleOutputReceiver directConsoleReporter = (ConsoleOutputReceiver) standardTestRun.run();
+ directConsoleReporter.writeTestOutput( "HeyYou".getBytes(), 0, 6, true );
+ standardTestRun.assertExpected( MockReporter.STDOUT, "HeyYou" );
+ }
+
+ public void testSystemProperties()
+ throws ReporterException, IOException
+ {
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ standardTestRun.run();
+
+ reset();
+ RunListener forkingReporter = createForkingRunListener( defaultChannel );
+
+ TestSetMockReporterFactory providerReporterFactory = new TestSetMockReporterFactory();
+ ForkClient forkStreamClient = new ForkClient( providerReporterFactory, new Properties() );
+
+ forkStreamClient.consumeMultiLineContent( content.toString( "utf-8" ) );
+
+ Properties props = forkStreamClient.getTestVmSystemProperties();
+ assert ( props.size() > 1 );
+ }
+
+ public void testMultipleEntries()
+ throws ReporterException, IOException
+ {
+
+ final StandardTestRun standardTestRun = new StandardTestRun();
+ standardTestRun.run();
+
+ reset();
+ RunListener forkingReporter = createForkingRunListener( defaultChannel );
+
+ ReportEntry reportEntry = createDefaultReportEntry();
+ forkingReporter.testSetStarting( reportEntry );
+ forkingReporter.testStarting( reportEntry );
+ forkingReporter.testSucceeded( reportEntry );
+ forkingReporter.testSetCompleted( reportEntry );
+
+ TestSetMockReporterFactory providerReporterFactory = new TestSetMockReporterFactory();
+ ForkClient forkStreamClient = new ForkClient( providerReporterFactory, new Properties() );
+
+ forkStreamClient.consumeMultiLineContent( content.toString( "utf-8" ) );
+
+ final MockReporter reporter = (MockReporter) forkStreamClient.getReporter( defaultChannel );
+ final List events = reporter.getEvents();
+ assertEquals( MockReporter.SET_STARTING, events.get( 0 ) );
+ assertEquals( MockReporter.TEST_STARTING, events.get( 1 ) );
+ assertEquals( MockReporter.TEST_SUCCEEDED, events.get( 2 ) );
+ assertEquals( MockReporter.SET_COMPLETED, events.get( 3 ) );
+ }
+
+ public void test2DifferentChannels()
+ throws ReporterException, IOException
+ {
+ reset();
+ ReportEntry expected = createDefaultReportEntry();
+ final SimpleReportEntry secondExpected = createAnotherDefaultReportEntry();
+
+ new ForkingRunListener( printStream, defaultChannel.intValue() ).testStarting( expected );
+ new ForkingRunListener( printStream, anotherChannel.intValue() ).testSkipped( secondExpected );
+
+ TestSetMockReporterFactory providerReporterFactory = new TestSetMockReporterFactory();
+ final ForkClient forkStreamClient = new ForkClient( providerReporterFactory, new Properties() );
+ forkStreamClient.consumeMultiLineContent( content.toString( "utf-8" ) );
+
+ MockReporter reporter = (MockReporter) forkStreamClient.getReporter( defaultChannel );
+ Assert.assertEquals( MockReporter.TEST_STARTING, reporter.getFirstEvent() );
+ Assert.assertEquals( expected, reporter.getFirstData() );
+ Assert.assertEquals( 1, reporter.getEvents().size() );
+
+ MockReporter reporter2 = (MockReporter) forkStreamClient.getReporter( anotherChannel );
+ Assert.assertEquals( MockReporter.TEST_SKIPPED, reporter2.getFirstEvent() );
+ Assert.assertEquals( secondExpected, reporter2.getFirstData() );
+ Assert.assertEquals( 1, reporter2.getEvents().size() );
+ }
+
+ // Todo: Test weird characters
+
+ private SimpleReportEntry createDefaultReportEntry()
+ {
+ return new SimpleReportEntry( "com.abc.TestClass", "testMethod", new Integer( 22 ) );
+ }
+
+ private SimpleReportEntry createAnotherDefaultReportEntry()
+ {
+ return new SimpleReportEntry( "com.abc.AnotherTestClass", "testAnotherMethod", new Integer( 42 ) );
+ }
+
+ private SimpleReportEntry createReportEntryWithStackTrace()
+ {
+ try
+ {
+ throw new RuntimeException();
+ }
+ catch ( RuntimeException e )
+ {
+ StackTraceWriter stackTraceWriter =
+ new PojoStackTraceWriter( "org.apache.tests.TestClass", "testMethod11", e );
+ return new CategorizedReportEntry( "com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter,
+ new Integer( 77 ) );
+ }
+ }
+
+ private SimpleReportEntry createReportEntryWithSpecialMessage( String message )
+ {
+ try
+ {
+ throw new RuntimeException( message );
+ }
+ catch ( RuntimeException e )
+ {
+ StackTraceWriter stackTraceWriter =
+ new PojoStackTraceWriter( "org.apache.tests.TestClass", "testMethod11", e );
+ return new CategorizedReportEntry( "com.abc.TestClass", "testMethod", "aGroup", stackTraceWriter,
+ new Integer( 77 ) );
+ }
+ }
+
+ private RunListener createForkingRunListener( Integer testSetCHannel )
+ {
+ return new ForkingRunListener( printStream, testSetCHannel.intValue() );
+ }
+
+ private class StandardTestRun
+ {
+ private MockReporter reporter;
+
+ public RunListener run()
+ throws ReporterException, IOException
+ {
+ reset();
+ return createForkingRunListener( defaultChannel );
+ }
+
+ public void clientReceiveContent()
+ throws ReporterException, IOException
+ {
+ TestSetMockReporterFactory providerReporterFactory = new TestSetMockReporterFactory();
+ final ForkClient forkStreamClient = new ForkClient( providerReporterFactory, new Properties() );
+ forkStreamClient.consumeMultiLineContent( content.toString( "utf-8" ) );
+ reporter = (MockReporter) forkStreamClient.getReporter( defaultChannel );
+ }
+
+
+ public String getFirstEvent()
+ {
+ return (String) reporter.getEvents().get( 0 );
+ }
+
+ public ReportEntry getFirstData()
+ {
+ return (ReportEntry) reporter.getData().get( 0 );
+ }
+
+ public String getFirstStringData()
+ {
+ return (String) reporter.getData().get( 0 );
+ }
+
+ private void assertExpected( String actionCode, ReportEntry expected )
+ throws IOException, ReporterException
+ {
+ clientReceiveContent();
+ assertEquals( actionCode, getFirstEvent() );
+ final ReportEntry firstData = getFirstData();
+ assertEquals( expected.getSourceName(), firstData.getSourceName() );
+ assertEquals( expected.getName(), firstData.getName() );
+ assertEquals( expected.getElapsed(), firstData.getElapsed() );
+ assertEquals( expected.getGroup(), firstData.getGroup() );
+ if ( expected.getStackTraceWriter() != null )
+ {
+ assertEquals( expected.getStackTraceWriter().getThrowable().getLocalizedMessage(),
+ firstData.getStackTraceWriter().getThrowable().getLocalizedMessage() );
+ assertEquals( expected.getStackTraceWriter().writeTraceToString(),
+ firstData.getStackTraceWriter().writeTraceToString() );
+ }
+ }
+
+ private void assertExpected( String actionCode, String expected )
+ throws IOException, ReporterException
+ {
+ clientReceiveContent();
+ assertEquals( actionCode, getFirstEvent() );
+ final String firstData = (String) reporter.getData().get( 0 );
+ assertEquals( expected, firstData );
+ }
+
+ }
+}
Propchange: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkingRunListenerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java (original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java Wed Apr 27 21:20:12 2011
@@ -25,7 +25,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -40,6 +39,7 @@ import org.apache.maven.project.MavenPro
import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
+import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.util.StringUtils;
@@ -180,12 +180,12 @@ public class SurefirePlugin
* to run a single test called "foo/MyTest.java".<br/>
* This parameter overrides the <code>includes/excludes</code> parameters, and the TestNG
* <code>suiteXmlFiles</code> parameter.
- *
+ * <p/>
* since 2.7.3
* You can execute a limited number of method in the test with adding #myMethod or #my*ethod.
* Si type "-Dtest=MyTest#myMethod"
* <b>supported for junit 4.x and testNg</b>
- *
+ *
* @parameter expression="${test}"
*/
private String test;
@@ -296,7 +296,7 @@ public class SurefirePlugin
private boolean useFile;
/**
- * When forking, set this to "true" to redirect the unit test standard output to a file (found in
+ * Set this to "true" to redirect the unit test standard output to a file (found in
* reportsDirectory/testName-output.txt).
*
* @parameter expression="${maven.test.redirectTestOutputToFile}" default-value="false"
@@ -604,7 +604,7 @@ public class SurefirePlugin
final List providers = initialize();
Exception exception = null;
ForkConfiguration forkConfiguration = null;
- int result = 0;
+ RunResult result = null;
for ( Iterator iter = providers.iterator(); iter.hasNext(); )
{
ProviderInfo provider = (ProviderInfo) iter.next();
@@ -626,6 +626,10 @@ public class SurefirePlugin
}
}
+ if ( result.isFailureOrTimeout() )
+ {
+ throw new MojoExecutionException( "Failure or timeout" );
+ }
if ( exception != null )
{
throw new MojoExecutionException( exception.getMessage(), exception );
@@ -637,16 +641,18 @@ public class SurefirePlugin
System.setProperties( getOriginalSystemProperties() );
}
- writeSummary(result);
+ writeSummary( result );
}
- private void writeSummary(int result) throws MojoFailureException {
- SurefireHelper.reportExecution( this, result, getLog() );
- }
+ private void writeSummary( RunResult result )
+ throws MojoFailureException
+ {
+ SurefireHelper.reportExecution( this, result, getLog() );
+ }
protected boolean isSkipExecution()
{
- return isSkip() || isSkipTests() || isSkipExec();
+ return isSkip() || isSkipTests() || isSkipExec();
}
protected String getPluginName()
@@ -811,7 +817,7 @@ public class SurefirePlugin
}
return test;
}
-
+
/**
* @since 2.7.3
*/
@@ -820,15 +826,15 @@ public class SurefirePlugin
if ( StringUtils.isBlank( test ) )
{
return null;
- }
+ }
int index = this.test.indexOf( '#' );
if ( index >= 0 )
{
return this.test.substring( index + 1, this.test.length() );
}
return null;
- }
-
+ }
+
public void setTest( String test )
{
@@ -1299,5 +1305,5 @@ public class SurefirePlugin
protected void addPluginSpecificChecksumItems( ChecksumCalculator checksum )
{
}
-
+
}
Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java (from r1097226, maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java&p1=maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java&r1=1097226&r2=1097246&rev=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java Wed Apr 27 21:20:12 2011
@@ -19,18 +19,20 @@ package org.apache.maven.plugin.surefire
* under the License.
*/
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.util.NestedRuntimeException;
-
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.Reporter;
+import org.apache.maven.surefire.report.ReporterConfiguration;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.util.NestedRuntimeException;
/**
* Surefire output consumer proxy that writes test output to a {@link File} for each test suite.
- *
+ * <p/>
* This class is not threadsafe, but can be encapsulated with a SynchronizedOutputConsumer. It may still be
* accessed from different threads (serially).
*
@@ -39,7 +41,7 @@ import java.io.PrintWriter;
* @since 2.1
*/
public class FileOutputConsumerProxy
- extends OutputConsumerProxy
+ implements Reporter
{
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
@@ -52,14 +54,11 @@ public class FileOutputConsumerProxy
/**
* Create a consumer that will write to a {@link File} for each test
- *
- * @param outputConsumer the output consumer
- * @param reportsDirectory directory where files will be saved
*/
- public FileOutputConsumerProxy( OutputConsumer outputConsumer, File reportsDirectory )
+
+ public FileOutputConsumerProxy( ReporterConfiguration reporterConfiguration )
{
- super( outputConsumer );
- this.reportsDirectory = reportsDirectory;
+ this.reportsDirectory = reporterConfiguration.getReportsDirectory();
}
public void testSetStarting( ReportEntry reportEntry )
@@ -84,10 +83,10 @@ public class FileOutputConsumerProxy
{
throw new NestedRuntimeException( e );
}
- super.testSetStarting( reportEntry );
}
- public void testSetCompleted()
+ public void testSetCompleted( ReportEntry report )
+ throws ReporterException
{
if ( printWriter == null )
{
@@ -101,9 +100,53 @@ public class FileOutputConsumerProxy
}
printWriter.close();
this.printWriter = null;
- super.testSetCompleted();
}
+ public void testStarting( ReportEntry report )
+ {
+ }
+
+ public void testSucceeded( ReportEntry report )
+ {
+ }
+
+ public void testError( ReportEntry report )
+ {
+ }
+
+ public void testFailed( ReportEntry report )
+ {
+ }
+
+ public void testSkipped( ReportEntry report )
+ {
+ }
+
+ public void testError( ReportEntry report, String stdOut, String stdErr )
+ {
+ }
+
+ public void testFailed( ReportEntry report, String stdOut, String stdErr )
+ {
+ }
+
+ public void writeMessage( String message )
+ {
+ }
+
+ public void writeMessage( byte[] b, int off, int len )
+ {
+ }
+
+ public void writeDetailMessage( String message )
+ {
+ }
+
+ public void reset()
+ {
+ }
+
+
/**
* Write the output to the current test file
* <p/>
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java?rev=1097246&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java Wed Apr 27 21:20:12 2011
@@ -0,0 +1,212 @@
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.maven.surefire.report.AbstractConsoleReporter;
+import org.apache.maven.surefire.report.AbstractFileReporter;
+import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
+import org.apache.maven.surefire.report.DirectConsoleReporter;
+import org.apache.maven.surefire.report.MulticastingReporter;
+import org.apache.maven.surefire.report.Reporter;
+import org.apache.maven.surefire.report.ReporterConfiguration;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.RunStatistics;
+import org.apache.maven.surefire.report.TestSetRunListener;
+import org.apache.maven.surefire.report.XMLReporter;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.util.ReflectionUtils;
+import org.apache.maven.surefire.util.SurefireReflectionException;
+
+/**
+ * Provides RunListener implementations to the providers.
+ * <p/>
+ * Keeps a centralized count of test run results.
+ *
+ * @author Kristian Rosenvold
+ */
+public class ReporterManagerFactory
+ implements ReporterFactory
+{
+ private List reportDefinitions;
+
+ private ClassLoader surefireClassLoader;
+
+ private ReporterConfiguration reporterConfiguration;
+
+ private final RunStatistics globalStats = new RunStatistics();
+
+ private final MulticastingReporter multicastingReporter;
+
+ public ReporterManagerFactory( ClassLoader surefireClassLoader, ReporterConfiguration reporterConfiguration,
+ List reportDefinitions )
+ {
+ this.reporterConfiguration = reporterConfiguration;
+ this.reportDefinitions = reportDefinitions;
+ this.surefireClassLoader = surefireClassLoader;
+ multicastingReporter = new MulticastingReporter( instantiateReports() );
+ runStarting();
+ }
+
+ public RunListener createReporter()
+ {
+ return new TestSetRunListener( instantiateConsoleReporter(), instantiateFileReporter(),
+ instantiateXmlReporter(), instantiateConsoleOutputFileReporter(), globalStats );
+ }
+
+ private AbstractConsoleReporter instantiateConsoleReporter()
+ {
+ return (AbstractConsoleReporter) instantiateReport( reporterConfiguration.getConsoleReporter() );
+ }
+
+ private AbstractFileReporter instantiateFileReporter()
+ {
+ return (AbstractFileReporter) instantiateReport( reporterConfiguration.getFileReporter() );
+ }
+
+ private XMLReporter instantiateXmlReporter()
+ {
+ return (XMLReporter) instantiateReport( reporterConfiguration.getXmlReporter() );
+ }
+
+ private Reporter instantiateConsoleOutputFileReporter()
+ {
+ return instantiateReport( reporterConfiguration.getConsoleOutputFileReporterName() );
+ }
+
+ private List instantiateReports()
+ {
+ return instantiateReportsNewStyle( reportDefinitions, reporterConfiguration, surefireClassLoader );
+ }
+
+ public RunResult close()
+ {
+ runCompleted();
+ return globalStats.getRunResult();
+ }
+
+ private List instantiateReportsNewStyle( List reportDefinitions, ReporterConfiguration reporterConfiguration,
+ ClassLoader classLoader )
+ {
+ List reports = new ArrayList();
+
+ for ( Iterator i = reportDefinitions.iterator(); i.hasNext(); )
+ {
+
+ String className = (String) i.next();
+
+ Reporter report = instantiateReportNewStyle( className, reporterConfiguration, classLoader );
+
+ reports.add( report );
+ }
+
+ return reports;
+ }
+
+ public Reporter instantiateReport( String reportName )
+ {
+ if ( reportName == null )
+ {
+ return null;
+ }
+ return instantiateReportNewStyle( reportName, reporterConfiguration, surefireClassLoader );
+ }
+
+ private static Reporter instantiateReportNewStyle( String className, ReporterConfiguration params,
+ ClassLoader classLoader )
+ {
+ Class clazz = ReflectionUtils.loadClass( classLoader, className );
+
+ if ( params != null )
+ {
+ Class[] paramTypes = new Class[1];
+ paramTypes[0] = ReflectionUtils.loadClass( classLoader, ReporterConfiguration.class.getName() );
+ Constructor constructor = ReflectionUtils.getConstructor( clazz, paramTypes );
+ return (Reporter) ReflectionUtils.newInstance( constructor, new Object[]{ params } );
+ }
+ else
+ {
+ try
+ {
+ return (Reporter) clazz.newInstance();
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ catch ( InstantiationException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ }
+
+ }
+
+ public DirectConsoleReporter createConsoleReporter()
+ {
+ return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
+ }
+
+ public void runStarting()
+ {
+ final DirectConsoleReporter consoleReporter = createConsoleReporter();
+ consoleReporter.writeMessage( "" );
+ consoleReporter.writeMessage( "-------------------------------------------------------" );
+ consoleReporter.writeMessage( " T E S T S" );
+ consoleReporter.writeMessage( "-------------------------------------------------------" );
+ }
+
+ private void runCompleted()
+ {
+ final DirectConsoleReporter consoleReporter = createConsoleReporter();
+ consoleReporter.writeMessage( "" );
+ consoleReporter.writeMessage( "Results :" );
+ consoleReporter.writeMessage( "" );
+ if ( globalStats.hadFailures() )
+ {
+ multicastingReporter.writeMessage( "Failed tests: " );
+ for ( Iterator iterator = this.globalStats.getFailureSources().iterator(); iterator.hasNext(); )
+ {
+ consoleReporter.writeMessage( " " + iterator.next() );
+ }
+ consoleReporter.writeMessage( "" );
+ }
+ if ( globalStats.hadErrors() )
+ {
+ consoleReporter.writeMessage( "Tests in error: " );
+ for ( Iterator iterator = this.globalStats.getErrorSources().iterator(); iterator.hasNext(); )
+ {
+ consoleReporter.writeMessage( " " + iterator.next() );
+ }
+ consoleReporter.writeMessage( "" );
+ }
+ consoleReporter.writeMessage( globalStats.getSummary() );
+ consoleReporter.writeMessage( "" );
+ }
+
+ public RunStatistics getGlobalRunStatistics()
+ {
+ return globalStats;
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/plugin/surefire/report/ReporterManagerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java Wed Apr 27 21:20:12 2011
@@ -19,18 +19,17 @@ package org.apache.maven.surefire.booter
* under the License.
*/
+import java.util.Properties;
+import org.apache.maven.surefire.forking.ForkConfigurationInfo;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.ReporterManagerFactory;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
import org.apache.maven.surefire.testset.TestArtifactInfo;
import org.apache.maven.surefire.testset.TestRequest;
import org.apache.maven.surefire.util.DefaultDirectoryScanner;
import org.apache.maven.surefire.util.DirectoryScanner;
-import java.util.Properties;
-
/**
* @author Kristian Rosenvold
*/
@@ -52,6 +51,14 @@ public class BaseProviderFactory
private TestArtifactInfo testArtifactInfo;
+ private ForkConfigurationInfo forkConfigurationInfo;
+
+ private final ReporterFactory reporterFactory;
+
+ public BaseProviderFactory( ReporterFactory reporterFactory )
+ {
+ this.reporterFactory = reporterFactory;
+ }
public DirectoryScanner getDirectoryScanner()
{
@@ -62,18 +69,12 @@ public class BaseProviderFactory
return new DefaultDirectoryScanner( directoryScannerParameters.getTestClassesDirectory(),
directoryScannerParameters.getIncludes(),
directoryScannerParameters.getExcludes(),
- directoryScannerParameters.getRunOrder());
+ directoryScannerParameters.getRunOrder() );
}
public ReporterFactory getReporterFactory()
{
- ReporterFactory reporterManagerFactory =
- new ReporterManagerFactory( surefireClassLoader, reporterConfiguration );
- if ( providerProperties != null )
- {
- reporterManagerFactory.getGlobalRunStatistics().initResultsFromProperties( providerProperties );
- }
- return reporterManagerFactory;
+ return reporterFactory;
}
public void setDirectoryScannerParameters( DirectoryScannerParameters directoryScannerParameters )
@@ -136,4 +137,15 @@ public class BaseProviderFactory
{
this.testArtifactInfo = testArtifactInfo;
}
+
+ public void setForkConfigurationInfo( ForkConfigurationInfo forkConfigurationInfo )
+ {
+ this.forkConfigurationInfo = forkConfigurationInfo;
+ }
+
+
+ public ForkConfigurationInfo getForkConfiguration()
+ {
+ return forkConfigurationInfo;
+ }
}
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingReporterFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingReporterFactory.java?rev=1097246&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingReporterFactory.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingReporterFactory.java Wed Apr 27 21:20:12 2011
@@ -0,0 +1,74 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.PrintStream;
+import org.apache.maven.surefire.report.DirectConsoleReporter;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.RunStatistics;
+import org.apache.maven.surefire.suite.RunResult;
+
+/**
+ * Creates ForkingReporters, which are typically one instance per TestSet or thread.
+ * This factory is only used inside forks.
+ *
+ * @author Kristian Rosenvold
+ * @noinspection UnusedDeclaration
+ */
+
+public class ForkingReporterFactory
+ implements ReporterFactory
+{
+
+ private final Boolean isTrimstackTrace;
+
+ private final PrintStream originalSystemOut;
+
+ private volatile int testSetChannelId = 1;
+
+ private static final Integer ROOT_CHANNEl = new Integer( 0 );
+
+ public ForkingReporterFactory( Boolean trimstackTrace, PrintStream originalSystemOut )
+ {
+ isTrimstackTrace = trimstackTrace;
+ this.originalSystemOut = originalSystemOut;
+ }
+
+ public synchronized RunListener createReporter()
+ {
+ return new ForkingRunListener( originalSystemOut, testSetChannelId++, isTrimstackTrace.booleanValue() );
+ }
+
+ public RunResult close()
+ {
+ return new RunResult( 17, 17, 17, 17 );
+ }
+
+ public RunStatistics getGlobalRunStatistics()
+ {
+ return new RunStatistics();
+ }
+
+ public DirectConsoleReporter createConsoleReporter()
+ {
+ return new ForkingRunListener( originalSystemOut, ROOT_CHANNEl.intValue(), isTrimstackTrace.booleanValue() );
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingReporterFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java?rev=1097246&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java Wed Apr 27 21:20:12 2011
@@ -0,0 +1,331 @@
+package org.apache.maven.surefire.booter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.PrintStream;
+import java.util.Enumeration;
+import java.util.Properties;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.apache.maven.surefire.report.DirectConsoleReporter;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.apache.maven.surefire.util.internal.ByteBuffer;
+import org.apache.maven.surefire.util.internal.StringUtils;
+
+/**
+ * Encodes the full output of the test run to the stdout stream
+ *
+ * @author Kristian Rosenvold
+ */
+public class ForkingRunListener
+ implements RunListener, DirectConsoleReporter, ConsoleOutputReceiver
+{
+ public static final byte BOOTERCODE_TESTSET_STARTING = (byte) '1';
+
+ public static final byte BOOTERCODE_TESTSET_COMPLETED = (byte) '2';
+
+ public static final byte BOOTERCODE_STDOUT = (byte) '3';
+
+ public static final byte BOOTERCODE_STDERR = (byte) '4';
+
+ public static final byte BOOTERCODE_TEST_STARTING = (byte) '5';
+
+ public static final byte BOOTERCODE_TEST_SUCCEEDED = (byte) '6';
+
+ public static final byte BOOTERCODE_TEST_ERROR = (byte) '7';
+
+ public static final byte BOOTERCODE_TEST_FAILED = (byte) '8';
+
+ public static final byte BOOTERCODE_TEST_SKIPPED = (byte) '9';
+
+ public static final byte BOOTERCODE_TEST_ASSUMPTIONFAILURE = (byte) 'G';
+
+ public static final byte BOOTERCODE_CONSOLE = (byte) 'H';
+
+ public static final byte BOOTERCODE_SYSPROPS = (byte) 'I';
+
+ private final PrintStream target;
+
+ private final Integer testSetChannelId;
+
+ private final boolean trimStackTraces;
+
+ private final byte[] stdOutHeader;
+
+ private final byte[] stdErrHeader;
+
+ public ForkingRunListener( PrintStream target, int testSetChannelId )
+ {
+ this( target, testSetChannelId, false );
+ }
+
+ public ForkingRunListener( PrintStream target, int testSetChannelId, boolean trimStackTraces )
+ {
+ this.target = target;
+ this.testSetChannelId = new Integer( testSetChannelId );
+ this.trimStackTraces = trimStackTraces;
+ stdOutHeader = createHeader( BOOTERCODE_STDOUT, testSetChannelId );
+ stdErrHeader = createHeader( BOOTERCODE_STDERR, testSetChannelId );
+ sendProps();
+
+ }
+
+ public void testSetStarting( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TESTSET_STARTING, report, testSetChannelId ) );
+ }
+
+ public void testSetCompleted( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TESTSET_COMPLETED, report, testSetChannelId ) );
+ }
+
+ public void testStarting( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_STARTING, report, testSetChannelId ) );
+ }
+
+ public void testSucceeded( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_SUCCEEDED, report, testSetChannelId ) );
+ }
+
+ public void testAssumptionFailure( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_ASSUMPTIONFAILURE, report, testSetChannelId ) );
+ }
+
+ public void testAssumptionFailure( Integer channel, ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_ASSUMPTIONFAILURE, report, channel ) );
+ }
+
+ public void testError( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_ERROR, report, testSetChannelId ) );
+ }
+
+
+ public void testFailed( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_FAILED, report, testSetChannelId ) );
+ }
+
+ public void testSkipped( ReportEntry report )
+ {
+ target.print( toString( BOOTERCODE_TEST_SKIPPED, report, testSetChannelId ) );
+ }
+
+ public void writeTestOutputA( byte[] buf, int off, int len, boolean stdout )
+ {
+ ByteBuffer byteBuffer = new ByteBuffer( buf.length + 20 );
+ byteBuffer.append( stdout ? BOOTERCODE_STDOUT : BOOTERCODE_STDERR );
+ byteBuffer.comma();
+ byteBuffer.append( testSetChannelId );
+ byteBuffer.comma();
+ final int i = StringUtils.escapeJavaStyleString( byteBuffer.getData(), byteBuffer.getlength(), buf, off, len );
+ byteBuffer.advance( i );
+ byteBuffer.append( '\n' );
+ target.write( byteBuffer.getData(), 0, byteBuffer.getlength() );
+ }
+
+ public synchronized void sendProps()
+ {
+ Properties systemProperties = System.getProperties();
+
+ if ( systemProperties != null )
+ {
+ Enumeration propertyKeys = systemProperties.propertyNames();
+
+ while ( propertyKeys.hasMoreElements() )
+ {
+ String key = (String) propertyKeys.nextElement();
+
+ String value = systemProperties.getProperty( key );
+
+ if ( value == null )
+ {
+ value = "null";
+ }
+ target.print( toPropertyString( key, value ) );
+ }
+ }
+ }
+
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ byte[] header = stdout ? stdOutHeader : stdErrHeader;
+ byte[] content = new byte[buf.length * 2];
+ int i = StringUtils.escapeJavaStyleString( content, 0, buf, off, len );
+ content[i++] = (byte) '\n';
+
+ synchronized ( target )
+ {
+ target.write( header, 0, header.length );
+ target.write( content, 0, i );
+ }
+ }
+
+ public static byte[] createHeader( byte booterCode, int testSetChannel )
+ {
+ byte[] header = new byte[7];
+ header[0] = booterCode;
+ header[1] = (byte) ',';
+ header[6] = (byte) ',';
+
+ int i = testSetChannel;
+ int charPos = 6;
+ int radix = 1 << 4;
+ int mask = radix - 1;
+ do
+ {
+ header[--charPos] = (byte) digits[i & mask];
+ i >>>= 4;
+ }
+ while ( i != 0 );
+
+ while ( charPos > 2 )
+ {
+ header[--charPos] = (byte) '0';
+ }
+ return header;
+ }
+
+ final static char[] digits =
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
+
+
+ public void writeMessage( String message )
+ {
+ byte[] buf = message.getBytes();
+ ByteBuffer byteBuffer = new ByteBuffer( buf.length * 2 );
+ byteBuffer.append( BOOTERCODE_CONSOLE );
+ byteBuffer.comma();
+ byteBuffer.append( testSetChannelId );
+ byteBuffer.comma();
+ final int i =
+ StringUtils.escapeJavaStyleString( byteBuffer.getData(), byteBuffer.getlength(), buf, 0, buf.length );
+ byteBuffer.advance( i );
+ byteBuffer.append( '\n' );
+ target.write( byteBuffer.getData(), 0, byteBuffer.getlength() );
+ target.flush();
+ }
+
+ private String toPropertyString( String key, String value )
+ {
+ StringBuffer stringBuffer = new StringBuffer();
+ append( stringBuffer, BOOTERCODE_SYSPROPS ).comma( stringBuffer );
+ append( stringBuffer, Integer.toHexString( testSetChannelId.intValue() ) ).comma( stringBuffer );
+ StringUtils.escapeJavaStyleString( stringBuffer, key );
+ append( stringBuffer, "," );
+ StringUtils.escapeJavaStyleString( stringBuffer, value );
+ stringBuffer.append( "\n" );
+ return stringBuffer.toString();
+ }
+
+ private String toString( byte operationCode, ReportEntry reportEntry, Integer testSetChannelId )
+ {
+ StringBuffer stringBuffer = new StringBuffer();
+ append( stringBuffer, operationCode ).comma( stringBuffer );
+ append( stringBuffer, Integer.toHexString( testSetChannelId.intValue() ) ).comma( stringBuffer );
+ append( stringBuffer, reportEntry.getSourceName() ).comma( stringBuffer );
+ append( stringBuffer, reportEntry.getName() ).comma( stringBuffer );
+ nullableEncoding( stringBuffer, reportEntry.getGroup() );
+ comma( stringBuffer );
+ nullableEncoding( stringBuffer, reportEntry.getElapsed() );
+ comma( stringBuffer );
+ encode( stringBuffer, reportEntry.getStackTraceWriter() );
+ stringBuffer.append( "\n" );
+ return stringBuffer.toString();
+ }
+
+ private void comma( StringBuffer stringBuffer )
+ {
+ stringBuffer.append( "," );
+ }
+
+ private ForkingRunListener append( StringBuffer stringBuffer, String message )
+ {
+ stringBuffer.append( encode( message ) );
+ return this;
+ }
+
+ private ForkingRunListener append( StringBuffer stringBuffer, byte b )
+ {
+ stringBuffer.append( (char) b );
+ return this;
+ }
+
+ private void nullableEncoding( StringBuffer stringBuffer, Integer source )
+ {
+ if ( source == null )
+ {
+ stringBuffer.append( "null" );
+ }
+ else
+ {
+ stringBuffer.append( source.toString() );
+ }
+ }
+
+ private String encode( String source )
+ {
+ return source;
+ }
+
+
+ private void nullableEncoding( StringBuffer stringBuffer, String source )
+ {
+ if ( source == null )
+ {
+ stringBuffer.append( "null" );
+ }
+ else
+ {
+ StringUtils.escapeJavaStyleString( stringBuffer, source );
+ }
+ }
+
+ private void encode( StringBuffer stringBuffer, StackTraceWriter stackTraceWriter )
+ {
+ if ( stackTraceWriter != null )
+ {
+ //noinspection ThrowableResultOfMethodCallIgnored
+ final Throwable throwable = stackTraceWriter.getThrowable();
+ if ( throwable != null )
+ {
+ String message = throwable.getLocalizedMessage();
+ nullableEncoding( stringBuffer, message );
+ }
+ comma( stringBuffer );
+
+ nullableEncoding( stringBuffer, trimStackTraces
+ ? stackTraceWriter.writeTrimmedTraceToString()
+ : stackTraceWriter.writeTraceToString() );
+ }
+ else
+ {
+ comma( stringBuffer );
+ comma( stringBuffer );
+ }
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java Wed Apr 27 21:20:12 2011
@@ -19,8 +19,18 @@ package org.apache.maven.surefire.booter
* under the License.
*/
+import java.io.File;
+import java.io.PrintStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Properties;
+import org.apache.maven.plugin.surefire.report.ReporterManagerFactory;
+import org.apache.maven.surefire.forking.ForkConfigurationInfo;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ReporterConfiguration;
+import org.apache.maven.surefire.report.ReporterFactory;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
import org.apache.maven.surefire.testset.TestArtifactInfo;
@@ -28,13 +38,6 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.util.ReflectionUtils;
import org.apache.maven.surefire.util.SurefireReflectionException;
-import java.io.File;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Properties;
-
/**
* Does reflection based invocation of the surefire methods.
* <p/>
@@ -44,7 +47,7 @@ import java.util.Properties;
*/
public class SurefireReflector
{
- private final ClassLoader classLoader;
+ private final ClassLoader surefireClassLoader;
private final Class reporterConfiguration;
@@ -70,9 +73,13 @@ public class SurefireReflector
private final Class booterParameters;
+ private final Class reporterFactory;
+
+ private final Class forkConfigurationInfo;
+
public SurefireReflector( ClassLoader surefireClassLoader )
{
- this.classLoader = surefireClassLoader;
+ this.surefireClassLoader = surefireClassLoader;
try
{
reporterConfiguration = surefireClassLoader.loadClass( ReporterConfiguration.class.getName() );
@@ -86,6 +93,8 @@ public class SurefireReflector
testClassLoaderAware = surefireClassLoader.loadClass( SurefireClassLoadersAware.class.getName() );
reporterConfigurationAware = surefireClassLoader.loadClass( ReporterConfigurationAware.class.getName() );
providerPropertiesAware = surefireClassLoader.loadClass( ProviderPropertiesAware.class.getName() );
+ forkConfigurationInfo = surefireClassLoader.loadClass( ForkConfigurationInfo.class.getName() );
+ reporterFactory = surefireClassLoader.loadClass( ReporterFactory.class.getName() );
runResult = surefireClassLoader.loadClass( RunResult.class.getName() );
booterParameters = surefireClassLoader.loadClass( ProviderParameters.class.getName() );
}
@@ -145,10 +154,8 @@ public class SurefireReflector
}
Class[] arguments = { List.class, File.class, String.class, String.class };
Constructor constructor = ReflectionUtils.getConstructor( this.testRequest, arguments );
- return ReflectionUtils.newInstance( constructor, new Object[] {
- suiteDefinition.getSuiteXmlFiles(),
- suiteDefinition.getTestSourceDirectory(),
- suiteDefinition.getRequestedTest(),
+ return ReflectionUtils.newInstance( constructor, new Object[]{ suiteDefinition.getSuiteXmlFiles(),
+ suiteDefinition.getTestSourceDirectory(), suiteDefinition.getRequestedTest(),
suiteDefinition.getRequestedTestMethod() } );
}
@@ -181,24 +188,58 @@ public class SurefireReflector
testArtifactInfo.getClassifier() } );
}
+ Object createForkConfigurationInfo( ForkConfigurationInfo forkConfigurationInfo )
+ {
+ if ( forkConfigurationInfo == null )
+ {
+ return null;
+ }
+
+ final Class[] arguments = { String.class, Boolean.class };
+ Constructor constructor = ReflectionUtils.getConstructor( this.forkConfigurationInfo, arguments );
+ return ReflectionUtils.newInstance( constructor, new Object[]{ forkConfigurationInfo.getForkMode(),
+ forkConfigurationInfo.getInFork() } );
+ }
+
+
Object createReporterConfiguration( ReporterConfiguration reporterConfiguration )
{
Constructor constructor = ReflectionUtils.getConstructor( this.reporterConfiguration,
- new Class[]{ List.class, File.class, Boolean.class,
- Integer.class } );
- return ReflectionUtils.newInstance( constructor, new Object[]{ reporterConfiguration.getReports(),
- reporterConfiguration.getReportsDirectory(), reporterConfiguration.isTrimStackTrace(),
- reporterConfiguration.getForkTimeout() } );
+ new Class[]{ File.class, Boolean.class, String.class,
+ String.class, String.class, String.class } );
+ return ReflectionUtils.newInstance( constructor, new Object[]{ reporterConfiguration.getReportsDirectory(),
+ reporterConfiguration.isTrimStackTrace(), reporterConfiguration.getConsoleReporter(),
+ reporterConfiguration.getFileReporter(), reporterConfiguration.getXmlReporter(),
+ reporterConfiguration.getConsoleOutputFileReporterName() } );
+ }
+
+ public Object createForkingReporterFactory( Boolean trimStackTrace, PrintStream originalSystemOut )
+ {
+ Class[] args = new Class[]{ Boolean.class, PrintStream.class };
+ Object[] values = new Object[]{ trimStackTrace, originalSystemOut };
+ return ReflectionUtils.instantiateObject( ForkingReporterFactory.class.getName(), args, values,
+ surefireClassLoader );
+ }
+
+ public Object createReportingReporterFactory( ReporterConfiguration reporterConfiguration )
+ {
+ Class[] args = new Class[]{ ClassLoader.class, this.reporterConfiguration, List.class };
+ Object report = createReporterConfiguration( reporterConfiguration );
+ Object[] params = new Object[]{ this.surefireClassLoader, report, reporterConfiguration.getReports() };
+ return ReflectionUtils.instantiateObject( ReporterManagerFactory.class.getName(), args, params,
+ surefireClassLoader );
+
}
- public Object createBooterConfiguration()
+ public Object createBooterConfiguration( ClassLoader surefireClassLoader, Object factoryInstance )
{
- return ReflectionUtils.instantiate( classLoader, BaseProviderFactory.class.getName() );
+ return ReflectionUtils.instantiateOneArg( surefireClassLoader, BaseProviderFactory.class.getName(),
+ reporterFactory, factoryInstance );
}
public Object instantiateProvider( String providerClassName, Object booterParameters )
{
- return ReflectionUtils.instantiateOneArg( classLoader, providerClassName, this.booterParameters,
+ return ReflectionUtils.instantiateOneArg( surefireClassLoader, providerClassName, this.booterParameters,
booterParameters );
}
@@ -216,6 +257,17 @@ public class SurefireReflector
ReflectionUtils.invokeSetter( o, "setDirectoryScannerParameters", this.directoryScannerParameters, param );
}
+
+ public void setForkConfigurationInfo( Object o, ForkConfigurationInfo forkConfigurationInfo )
+ {
+ if ( forkConfigurationInfo == null )
+ {
+ throw new IllegalArgumentException( "ForkConfiguration cannot be null" );
+ }
+ final Object forkConfig = createForkConfigurationInfo( forkConfigurationInfo );
+ ReflectionUtils.invokeSetter( o, "setForkConfigurationInfo", this.forkConfigurationInfo, forkConfig );
+ }
+
public void setTestSuiteDefinitionAware( Object o, TestRequest testSuiteDefinition2 )
{
if ( testSuiteDefinitionAware.isAssignableFrom( o.getClass() ) )
Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java (from r1097226, maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/SupressHeaderOutputConsumerProxyTest.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java&p1=maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/SupressHeaderOutputConsumerProxyTest.java&r1=1097226&r2=1097246&rev=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/output/SupressHeaderOutputConsumerProxyTest.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java Wed Apr 27 21:20:12 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.plugin.surefire.booterclient.output;
+package org.apache.maven.surefire.forking;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -20,26 +20,37 @@ package org.apache.maven.plugin.surefire
*/
/**
- * Test for {@link SupressHeaderOutputConsumerProxy}
- *
- * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
- * @version $Id$
+ * @author Kristian Rosenvold
*/
-public class SupressHeaderOutputConsumerProxyTest
- extends OutputConsumerProxyTest
+public class ForkConfigurationInfo
{
+ private final String forkMode;
+
+ private final Boolean isInFork;
+
+ public ForkConfigurationInfo( String forkMode, Boolean inFork )
+ {
+ this.forkMode = forkMode;
+ isInFork = inFork;
+ }
- protected void setUp()
- throws Exception
+ public String getForkMode()
{
- super.setUp();
- setOutputConsumer( new SupressHeaderOutputConsumerProxy( (OutputConsumer) getOutputConsumerMock().proxy() ) );
+ return forkMode;
}
- public void testConsumeHeaderLine()
+ public Boolean getInFork()
{
- getOutputConsumer().consumeHeaderLine( getLine() );
- getOutputConsumerMock().verify();
+ return isInFork;
}
+ public boolean isInFork()
+ {
+ return isInFork.booleanValue();
+ }
+
+ public boolean isForking()
+ {
+ return !"never".equals( forkMode );
+ }
}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/forking/ForkConfigurationInfo.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/ProviderParameters.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/ProviderParameters.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/ProviderParameters.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/providerapi/ProviderParameters.java Wed Apr 27 21:20:12 2011
@@ -19,6 +19,8 @@ package org.apache.maven.surefire.provid
* under the License.
*/
+import java.util.Properties;
+import org.apache.maven.surefire.forking.ForkConfigurationInfo;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.ReporterFactory;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
@@ -26,14 +28,12 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.testset.TestRequest;
import org.apache.maven.surefire.util.DirectoryScanner;
-import java.util.Properties;
-
/**
* Injected into the providers upon provider construction. Allows the provider to request services and data it needs.
- *
+ * <p/>
* NOTE: This class is part of the proposed public api for surefire providers from 2.7 and up. It may
* still be subject to changes, even for minor revisions.
- *
+ * <p/>
* The api covers this interface and all the types reachable from it. And nothing else.
*
* @author Kristian Rosenvold
@@ -97,4 +97,11 @@ public interface ProviderParameters
* @return The artifactinfo, or null if autodetect was not used.
*/
TestArtifactInfo getTestArtifactInfo();
+
+ /**
+ * Information about the current fork settings.
+ *
+ * @return A forkConfigurationInfo, never null
+ */
+ ForkConfigurationInfo getForkConfiguration();
}
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java Wed Apr 27 21:20:12 2011
@@ -31,7 +31,6 @@ import java.io.PrintWriter;
*/
public abstract class AbstractConsoleReporter
extends AbstractTextReporter
- implements RunReporter
{
private static final String TEST_SET_STARTING_PREFIX = "Running ";
@@ -45,7 +44,6 @@ public abstract class AbstractConsoleRep
AbstractConsoleReporter( String format, ReporterConfiguration reporterConfiguration )
{
- // TODO: use logger
super(
new PrintWriter( new OutputStreamWriter( new BufferedOutputStream( ORIGINAL_SYSTEM_OUT, BUFFER_SIZE ) ) ),
format, reporterConfiguration );
@@ -59,20 +57,6 @@ public abstract class AbstractConsoleRep
writeMessage( getTestSetStartingMessage( report ) );
}
- public void runStarting()
- {
- writeHeading( "" );
- writeHeading( "-------------------------------------------------------" );
- writeHeading( " T E S T S" );
- writeHeading( "-------------------------------------------------------" );
- }
-
- void writeHeading( String message )
- {
- writer.println( message );
- writer.flush();
- }
-
/**
* Get the test set starting message for a report.
* eg. "Running org.foo.BarTest ( of group )"
@@ -92,6 +76,8 @@ public abstract class AbstractConsoleRep
message.append( report.getGroup() );
message.append( TEST_SET_STARTING_GROUP_SUFIX );
}
+
+ message.append( "\n" );
return message.toString();
}
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractFileReporter.java Wed Apr 27 21:20:12 2011
@@ -42,7 +42,7 @@ public abstract class AbstractFileReport
this.reportsDirectory = reporterConfiguration.getReportsDirectory();
- this.deleteOnStarting = reporterConfiguration.isForkWithTimeout();
+ this.deleteOnStarting = false;
}
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java Wed Apr 27 21:20:12 2011
@@ -75,14 +75,6 @@ public abstract class AbstractReporter
writeMessage( footer );
}
- public void runStarting()
- {
- }
-
- public void runCompleted()
- {
- }
-
public void testSetStarting( ReportEntry report )
throws ReporterException
{
@@ -211,17 +203,18 @@ public abstract class AbstractReporter
return clientSpecifiedElapsed != null ? clientSpecifiedElapsed.intValue() : endTime - startTime;
}
- // @deprecated dont use. TODO remove for 2.7.2
public void testError( ReportEntry report )
{
+ ++errors;
+ endTest();
}
- // @deprecated dont use. TODO remove for 2.7.2
public void testFailed( ReportEntry report )
{
+ ++failures;
+ endTest();
}
- // @deprecated dont use. TODO remove for 2.7.2
public void testAssumptionFailure( ReportEntry report )
{
}
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java?rev=1097246&r1=1097245&r2=1097246&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractTextReporter.java Wed Apr 27 21:20:12 2011
@@ -23,6 +23,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.maven.surefire.util.internal.ByteBuffer;
/**
* Text based reporter.
@@ -72,12 +73,21 @@ public abstract class AbstractTextReport
{
if ( writer != null )
{
- writer.println( message );
+ writer.print( message );
writer.flush();
}
}
+ public void writeMessage( byte[] b, int off, int len )
+ {
+ if ( writer != null )
+ {
+ writer.write( ByteBuffer.toChar( b, off, len ) );
+ }
+ }
+
+
public void writeDetailMessage( String message )
{
writeMessage( message );
@@ -117,6 +127,20 @@ public abstract class AbstractTextReport
testResults.add( getOutput( report, "FAILURE" ) );
}
+ public void testError( ReportEntry report )
+ {
+ super.testError( report );
+
+ testResults.add( getOutput( report, "ERROR" ) );
+ }
+
+ public void testFailed( ReportEntry report )
+ {
+ super.testFailed( report );
+
+ testResults.add( getOutput( report, "FAILURE" ) );
+ }
+
public void testSetStarting( ReportEntry report )
throws ReporterException
{
@@ -165,6 +189,8 @@ public abstract class AbstractTextReport
buf.append( " <<< FAILURE!" );
}
+ buf.append( "\n" );
+
return buf.toString();
}