Author: dfabulich
Date: Fri Nov 23 16:59:03 2007
New Revision: 597777
URL: http://svn.apache.org/viewvc?rev=597777&view=rev
Log:
Test for forkMode settings
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ForkModeTest.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/
(with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/pom.xml
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test2.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test3.java
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ForkModeTest.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ForkModeTest.java?rev=597777&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ForkModeTest.java
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ForkModeTest.java
Fri Nov 23 16:59:03 2007
@@ -0,0 +1,117 @@
+package org.apache.maven.surefire.its;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * Test forkMode
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Dan Fabulich</a>
+ *
+ */
+public class ForkModeTest
+ extends AbstractMavenIntegrationTestCase
+{
+ public void testForkModeAlways () throws Exception
+ {
+ String[] pids = doTest("always");
+
+ assertDifferentPids( pids );
+ }
+
+ public void testForkModePerTest() throws Exception
+ {
+ String[] pids = doTest( "pertest" );
+
+ assertDifferentPids( pids );
+ }
+
+ public void testForkModeNever() throws Exception
+ {
+ String[] pids = doTest( "never" );
+
+ assertSamePids( pids );
+ }
+
+ public void testForkModeNone() throws Exception
+ {
+ String[] pids = doTest( "none" );
+
+ assertSamePids( pids );
+ }
+
+ public void testForkModeOnce() throws Exception
+ {
+ String[] pids = doTest( "once" );
+ // DGF It would be nice to assert that "once" was different
+ // from "never" ... but there's no way to check the PID of
+ // Maven itself. No matter, "once" is tested by setting
+ // argLine, which can't be done except by forking.
+ assertSamePids( pids );
+ }
+
+ private void assertSamePids ( String[] pids ) {
+ assertEquals ("pid 1 didn't match pid 2", pids[0], pids[1]);
+ assertEquals ("pid 1 didn't match pid 3", pids[0], pids[2]);
+ }
+
+ private void assertDifferentPids( String[] pids )
+ {
+ if (pids[0].equals( pids[1] )) {
+ fail ("pid 1 matched pid 2: " + pids[0]);
+ }
+
+ if (pids[0].equals( pids[2] )) {
+ fail ("pid 1 matched pid 3: " + pids[0]);
+ }
+
+ if (pids[1].equals( pids[2] )) {
+ fail ("pid 2 matched pid 3: " + pids[0]);
+ }
+ }
+
+ private String[] doTest(String forkMode)
+ throws IOException, VerificationException, MavenReportException
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(),
"/fork-mode" );
+
+ Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+ List goals = new ArrayList();
+ goals.add( "test" );
+ goals.add( "-DforkMode=" + forkMode );
+ verifier.executeGoals( goals );
+ verifier.verifyErrorFreeLog();
+ verifier.resetStreams();
+
+ HelperAssertions.assertTestSuiteResults( 3, 0, 0, 0, testDir );
+
+ File targetDir = new File(testDir, "target" );
+ String[] pids = new String[3];
+ for (int i = 1; i <= pids.length; i++) {
+ File pidFile = new File(targetDir, "test" + i + "-pid");
+ String pid = slurpFile( pidFile );
+ pids[i-1] = pid;
+ }
+ return pids;
+ }
+
+ private String slurpFile(File textFile) throws IOException {
+ StringBuffer sb = new StringBuffer();
+ BufferedReader reader = new BufferedReader(new FileReader(textFile));
+ for (String line = reader.readLine(); line != null; line =
reader.readLine()) {
+ sb.append( line );
+ }
+ reader.close();
+ return sb.toString();
+ }
+}
Propchange:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov 23 16:59:03 2007
@@ -0,0 +1,5 @@
+.classpath
+.project
+target
+.settings
+log.txt
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/pom.xml?rev=597777&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/pom.xml
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/pom.xml
Fri Nov 23 16:59:03 2007
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.surefire</groupId>
+ <artifactId>fork-mode</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Test for forkMode</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>${forkMode}</forkMode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java?rev=597777&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java
Fri Nov 23 16:59:03 2007
@@ -0,0 +1,34 @@
+package forkMode;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+
+import junit.framework.TestCase;
+
+public class Test1
+ extends TestCase
+{
+
+ public void test1() throws IOException {
+ dumpPidFile(this);
+ }
+
+ public static void dumpPidFile(TestCase test) throws IOException {
+ String fileName = test.getName() + "-pid";
+ File target = new File("target");
+ if (! (target.exists() && target.isDirectory()) ) {
+ target = new File (".");
+ }
+ File pidFile = new File(target, fileName);
+ FileWriter fw = new FileWriter(pidFile);
+ // DGF little known trick... this is guaranteed to be unique to the PID
+ // In fact, it usually contains the pid and the local host name!
+ String pid = ManagementFactory.getRuntimeMXBean().getName();
+ fw.write( pid );
+ fw.flush();
+ fw.close();
+ }
+
+}
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test2.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test2.java?rev=597777&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test2.java
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test2.java
Fri Nov 23 16:59:03 2007
@@ -0,0 +1,15 @@
+package forkMode;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class Test2
+ extends TestCase
+{
+
+ public void test2() throws IOException {
+ Test1.dumpPidFile(this);
+ }
+
+}
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test3.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test3.java?rev=597777&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test3.java
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test3.java
Fri Nov 23 16:59:03 2007
@@ -0,0 +1,15 @@
+package forkMode;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class Test3
+ extends TestCase
+{
+
+ public void test3() throws IOException {
+ Test1.dumpPidFile(this);
+ }
+
+}