mirror of
https://github.com/nicolabs/ciform.git
synced 2026-05-21 12:13:25 +02:00
# jsunit-ant -> ant-jsunit
This commit is contained in:
parent
d1a51e28a5
commit
7f33a7626c
BIN
ciform/trunk/tools/ant-jsunit/lib/ant-junit.jar
Normal file
BIN
ciform/trunk/tools/ant-jsunit/lib/ant-junit.jar
Normal file
Binary file not shown.
BIN
ciform/trunk/tools/ant-jsunit/lib/ant.jar
Normal file
BIN
ciform/trunk/tools/ant-jsunit/lib/ant.jar
Normal file
Binary file not shown.
BIN
ciform/trunk/tools/ant-jsunit/lib/apache-ant-1.7.1-src.zip
Normal file
BIN
ciform/trunk/tools/ant-jsunit/lib/apache-ant-1.7.1-src.zip
Normal file
Binary file not shown.
BIN
ciform/trunk/tools/ant-jsunit/lib/jsunit.jar
Normal file
BIN
ciform/trunk/tools/ant-jsunit/lib/jsunit.jar
Normal file
Binary file not shown.
BIN
ciform/trunk/tools/ant-jsunit/lib/junit.jar
Normal file
BIN
ciform/trunk/tools/ant-jsunit/lib/junit.jar
Normal file
Binary file not shown.
|
|
@ -0,0 +1,100 @@
|
||||||
|
package net.jsunit.ant;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
|
||||||
|
import org.apache.tools.ant.types.FileSet;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* A simple class to represent a JsUnit test.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>It is composed of a set of <script> tags, represented by the included {@link FileSet}s.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||||
|
*/
|
||||||
|
public class JsUnitTestTask extends JUnitTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Known type for Javascript tags */
|
||||||
|
public static final String TYPE_JAVASCRIPT = "text/javascript";
|
||||||
|
|
||||||
|
//
|
||||||
|
// INITIALISATION
|
||||||
|
//
|
||||||
|
|
||||||
|
/** All resources to include in the test suite page */
|
||||||
|
private List filesets = new Vector();
|
||||||
|
|
||||||
|
/** Defaults to {@link #TYPE_JAVASCRIPT} */
|
||||||
|
private String type = TYPE_JAVASCRIPT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public JsUnitTestTask( String name, boolean haltOnError,
|
||||||
|
boolean haltOnFailure, boolean filtertrace, String type )
|
||||||
|
{
|
||||||
|
super( name, haltOnError, haltOnFailure, filtertrace );
|
||||||
|
setType( type );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public JsUnitTestTask( String name )
|
||||||
|
{
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public JsUnitTestTask()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public List getFilesets()
|
||||||
|
{
|
||||||
|
return filesets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setFilesets( List filesets )
|
||||||
|
{
|
||||||
|
this.filesets = filesets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// NEW ANT FIELDS
|
||||||
|
//
|
||||||
|
|
||||||
|
/** The <tt>type</tt> attribute of the <script> tag to be generated. */
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setType( String type )
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void addFileSet( FileSet fs )
|
||||||
|
{
|
||||||
|
getFilesets().add( fs );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,356 @@
|
||||||
|
package net.jsunit.ant;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import net.jsunit.GeneratedStandaloneTest;
|
||||||
|
import net.jsunit.StandaloneTest;
|
||||||
|
import net.jsunit.configuration.ConfigurationProperty;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.BuildException;
|
||||||
|
import org.apache.tools.ant.DirectoryScanner;
|
||||||
|
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask;
|
||||||
|
import org.apache.tools.ant.types.FileSet;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This task permits convenient access to the {@link GeneratedStandaloneTest}
|
||||||
|
* unit test.
|
||||||
|
*
|
||||||
|
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||||
|
*/
|
||||||
|
public class StandaloneTestTask extends JUnitTask
|
||||||
|
{
|
||||||
|
/** Name of the property pointing to the root directory of the JsUnit installation */
|
||||||
|
public static final String PROP_JSUNITROOT = "jsunit.dir";
|
||||||
|
/** Name of the property pointing to the JsUnit core library's file */
|
||||||
|
public static final String PROP_COREJS = "jsunit.coreJs";
|
||||||
|
/** Name of the property pointing to the JsUnit's <tt>testRunner.html</tt> file */
|
||||||
|
public static final String PROP_TESTRUNNER = "jsunit.testRunner";
|
||||||
|
|
||||||
|
/** Inner {@link JsUnitTestTask} elements */
|
||||||
|
private Collection scriptsList = new Vector();
|
||||||
|
private boolean runTests = true;
|
||||||
|
private boolean keepTestPage = false;
|
||||||
|
private String jsUnitRoot;
|
||||||
|
private String coreJs;
|
||||||
|
private String testRunner;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// INITIALISATION
|
||||||
|
//
|
||||||
|
|
||||||
|
public StandaloneTestTask() throws Exception
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected Collection getScriptsList()
|
||||||
|
{
|
||||||
|
return scriptsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected void setScriptsList( Collection scriptsList )
|
||||||
|
{
|
||||||
|
this.scriptsList = scriptsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// ANT Task IMPLEMENTATION
|
||||||
|
//
|
||||||
|
|
||||||
|
public void addConfiguredTest( JsUnitTestTask anInner )
|
||||||
|
{
|
||||||
|
// Simply saves the gathered inner elements
|
||||||
|
getScriptsList().add( anInner );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getJsUnitRoot()
|
||||||
|
{
|
||||||
|
return jsUnitRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setJsUnitRoot( String jsUnitRoot )
|
||||||
|
{
|
||||||
|
this.jsUnitRoot = jsUnitRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isKeepTestPage()
|
||||||
|
{
|
||||||
|
return keepTestPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setKeepTestPage( boolean keepTestPage )
|
||||||
|
{
|
||||||
|
this.keepTestPage = keepTestPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isRunTests()
|
||||||
|
{
|
||||||
|
return runTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setRunTests( boolean runTests )
|
||||||
|
{
|
||||||
|
this.runTests = runTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getCoreJs()
|
||||||
|
{
|
||||||
|
return coreJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setCoreJs( String coreJs )
|
||||||
|
{
|
||||||
|
this.coreJs = coreJs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getTestRunner()
|
||||||
|
{
|
||||||
|
return testRunner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setTestRunner( String testRunner )
|
||||||
|
{
|
||||||
|
this.testRunner = testRunner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
// A list of the URI of the files to include mapped to their type as key
|
||||||
|
Map scriptsFiles = new Hashtable();
|
||||||
|
|
||||||
|
if ( getScriptsList() == null || getScriptsList().size() == 0 )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "No <script/> element !" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Several elements of this type can be nested inside.
|
||||||
|
for ( Iterator itl = getScriptsList().iterator(); itl.hasNext(); )
|
||||||
|
{
|
||||||
|
JsUnitTestTask files = (JsUnitTestTask) itl.next();
|
||||||
|
// Adds the inner list for this type of script, indexed on the
|
||||||
|
// type's name
|
||||||
|
if ( !scriptsFiles.containsKey( files.getType() ) )
|
||||||
|
{
|
||||||
|
scriptsFiles.put( files.getType(), new Vector() );
|
||||||
|
}
|
||||||
|
// Scans and adds all given input files to their respective type's
|
||||||
|
// list
|
||||||
|
for ( Iterator itr = files.getFilesets().iterator(); itr.hasNext(); )
|
||||||
|
{
|
||||||
|
FileSet fs = (FileSet) itr.next();
|
||||||
|
DirectoryScanner ds = fs.getDirectoryScanner();
|
||||||
|
for ( int f = 0; f < ds.getIncludedFiles().length; f++ )
|
||||||
|
{
|
||||||
|
File file = new File( ds.getBasedir(), ds.getIncludedFiles()[f] );
|
||||||
|
((Collection) scriptsFiles.get( files.getType() )).add( file.toURI() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the parameters
|
||||||
|
String project = getProject().getName();
|
||||||
|
String jsUnitRoot = getJsUnitRoot() != null ? getJsUnitRoot() : getProject().getProperty( PROP_JSUNITROOT );
|
||||||
|
String coreJs = getCoreJs() != null ? getCoreJs() : getProject().getProperty( PROP_COREJS );
|
||||||
|
String testRunner = getTestRunner() != null ? getTestRunner() : getProject().getProperty( PROP_TESTRUNNER );
|
||||||
|
|
||||||
|
// Checks the parameters
|
||||||
|
if ( jsUnitRoot != null )
|
||||||
|
{
|
||||||
|
if ( coreJs == null )
|
||||||
|
{
|
||||||
|
coreJs = new File( jsUnitRoot, "app/jsUnitCore.js" ).getAbsolutePath();
|
||||||
|
}
|
||||||
|
if ( testRunner == null )
|
||||||
|
{
|
||||||
|
testRunner = new File( jsUnitRoot, "testRunner.html" ).getAbsolutePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( coreJs == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "Missing property coreJs" );
|
||||||
|
}
|
||||||
|
if ( testRunner == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "Missing property testRunner" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builds the test suite page
|
||||||
|
File testPage = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
testPage = buildTestSuitePage( project, coreJs, scriptsFiles );
|
||||||
|
String url = buildURL( testRunner, testPage );
|
||||||
|
System.setProperty( ConfigurationProperty.URL.getName(), url );
|
||||||
|
// TODO : allow fork and find a way to pass parameters without system properties
|
||||||
|
setFork( false );
|
||||||
|
}
|
||||||
|
catch ( URISyntaxException urise )
|
||||||
|
{
|
||||||
|
throw new BuildException( urise );
|
||||||
|
}
|
||||||
|
catch ( IOException ioe )
|
||||||
|
{
|
||||||
|
throw new BuildException( ioe );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lets the superclass do the job (will start the included test)
|
||||||
|
if ( isRunTests() )
|
||||||
|
{
|
||||||
|
// Adds all tests to the test suite (TODO : what implications with more than one test ?)
|
||||||
|
for ( Iterator itt = getScriptsList().iterator(); itt.hasNext(); )
|
||||||
|
{
|
||||||
|
JsUnitTestTask test = (JsUnitTestTask) itt.next();
|
||||||
|
test.setName( StandaloneTest.class.getName() );
|
||||||
|
// TODO : allow fork and find a way to pass parameters without system properties
|
||||||
|
test.setFork( false );
|
||||||
|
addTest( test );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Really starts the test
|
||||||
|
super.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !isKeepTestPage() )
|
||||||
|
{
|
||||||
|
// After execution, removes temporary files if asked
|
||||||
|
testPage.deleteOnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// UTILITY METHODS
|
||||||
|
//
|
||||||
|
|
||||||
|
/** The best effort to get a well formed URI */
|
||||||
|
private static URI buildURI( String text ) throws URISyntaxException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new URL( text ).toURI();
|
||||||
|
}
|
||||||
|
catch ( MalformedURLException murle )
|
||||||
|
{
|
||||||
|
return new File( text ).toURI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a complete JsUnit test suite page from the current environment
|
||||||
|
* into a temporary file.
|
||||||
|
*
|
||||||
|
* @return The generated test page
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if a required property is missing
|
||||||
|
*/
|
||||||
|
private static File buildTestSuitePage( String project, String JsUnitCore,
|
||||||
|
Map includes, String filename ) throws IOException,
|
||||||
|
URISyntaxException
|
||||||
|
{
|
||||||
|
// Reads the template of the test suite page to generate into a local
|
||||||
|
// buffer
|
||||||
|
InputStream is = StandaloneTest.class.getResourceAsStream( "TestSuite.html" );
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
for ( int c = is.read(); c > -1; c = is.read() )
|
||||||
|
{
|
||||||
|
buffer.append( (char) c );
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
// Replaces the variable parts of the template
|
||||||
|
String out = buffer.toString();
|
||||||
|
out = out.replaceAll( "@project@", project );
|
||||||
|
out = out.replace( "@jsUnitCore.js@", JsUnitCore );
|
||||||
|
StringBuffer includesBuffer = new StringBuffer();
|
||||||
|
// Currently only Javascript is supported
|
||||||
|
Collection javascripts = (Collection) includes.get( JsUnitTestTask.TYPE_JAVASCRIPT );
|
||||||
|
//for ( int i = 0; i < javascripts.length; i++ )
|
||||||
|
for ( Iterator itj = javascripts.iterator(); itj.hasNext(); )
|
||||||
|
{
|
||||||
|
URI javascript = (URI) itj.next();
|
||||||
|
includesBuffer.append( "<script type=\"text/javascript\" src=\"" );
|
||||||
|
includesBuffer.append( javascript/*new File( javascripts[i] ).toURI()*/);
|
||||||
|
includesBuffer.append( "\"></script>\n" );
|
||||||
|
}
|
||||||
|
out = out.replace( "@includes@", includesBuffer.toString() );
|
||||||
|
|
||||||
|
// writes the generated test suite to a temporary file
|
||||||
|
File testSuitePage = filename != null ? new File( filename ) : File.createTempFile( "jsunit-", ".tmp" );
|
||||||
|
FileWriter fw = new FileWriter( testSuitePage );
|
||||||
|
fw.write( out );
|
||||||
|
fw.close();
|
||||||
|
|
||||||
|
return testSuitePage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static File buildTestSuitePage( String project, String JsUnitCore,
|
||||||
|
Map includes ) throws IOException, URISyntaxException
|
||||||
|
{
|
||||||
|
return buildTestSuitePage( project, JsUnitCore, includes, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Before calling this method, make sure {@link #setTestSuitePage(File)} has been correctly set.
|
||||||
|
* @throws IllegalStateException if a property is missing or is incorrect
|
||||||
|
*/
|
||||||
|
private String buildURL( String testRunner, File testPage )
|
||||||
|
throws URISyntaxException, IOException
|
||||||
|
{
|
||||||
|
URI uri = buildURI( testRunner );
|
||||||
|
return new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), "testPage="
|
||||||
|
+ testPage.getPath(), uri.getFragment() ).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Test Page for @project@</title>
|
||||||
|
|
||||||
|
<!-- JsUnit requirement -->
|
||||||
|
<script type="text/javascript" src="@jsUnitCore.js@"></script>
|
||||||
|
|
||||||
|
<!-- All other requirements, including unit tests and the functions to test -->
|
||||||
|
@includes@
|
||||||
|
|
||||||
|
<!-- "Automagically" detects test functions -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
function exposeTestFunctionNames()
|
||||||
|
{
|
||||||
|
var tests = new Array();
|
||||||
|
for ( var o in window ) {
|
||||||
|
if( o.match(/^test/) && typeof(window[o]) == "function" ) {
|
||||||
|
tests.push(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tests;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!--
|
||||||
|
A minimal body to inform readers of the way to use this file.
|
||||||
|
-->
|
||||||
|
<h1>Test Page for @project@</h1>
|
||||||
|
<p>
|
||||||
|
This page is a unit test.<br/>
|
||||||
|
It must be open with <a href="http://www.jsunit.net/">JsUnit's</a> TestRunner</a>.
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -0,0 +1,232 @@
|
||||||
|
package net.jsunit;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configuration redefines {@link #url()} to point to a custom file
|
||||||
|
* and gathers automatically some more properties.
|
||||||
|
*
|
||||||
|
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||||
|
*/
|
||||||
|
public class GeneratedConfigurationSource //extends DelegatingConfigurationSource
|
||||||
|
{
|
||||||
|
// //
|
||||||
|
// // CONSTANTS
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Property name defining the Javascript files to include in the test suite
|
||||||
|
// * page.
|
||||||
|
// */
|
||||||
|
// public static final String PROP_JAVASCRIPTS = "jsunit.in.javascripts";
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Associates a type of script to the corresponding property where their
|
||||||
|
// * name is stored.
|
||||||
|
// */
|
||||||
|
// public static final String[][] TYPE_PROP = { { JsUnitTestTask.TYPE_JAVASCRIPT, PROP_JAVASCRIPTS } };
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // PRIVATE FIELDS
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// /** The generated test suite page */
|
||||||
|
// private File testSuitePage = null;
|
||||||
|
// private String project;
|
||||||
|
// private String coreJs;
|
||||||
|
// private String testRunner;
|
||||||
|
// private Map includes;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // INITIALISATION
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// public GeneratedConfigurationSource( /*ConfigurationSource source,*/
|
||||||
|
// String project, String coreJs, String testRunner )
|
||||||
|
// throws URISyntaxException
|
||||||
|
// {
|
||||||
|
// //super( source );
|
||||||
|
//
|
||||||
|
// // Checks for required parameters
|
||||||
|
// if ( System.getProperty( PROP_JAVASCRIPTS ) == null )
|
||||||
|
// {
|
||||||
|
// throw new IllegalArgumentException( "Missing required property "
|
||||||
|
// + PROP_JAVASCRIPTS );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// setProject( project );
|
||||||
|
// setCoreJs( coreJs );
|
||||||
|
// setTestRunner( testRunner );
|
||||||
|
//
|
||||||
|
// // Gathers all parameters
|
||||||
|
// // TODO Allow generic URI to be included in the generated file
|
||||||
|
// Map includes = new Hashtable();
|
||||||
|
// for ( int s = 0; s < TYPE_PROP.length; s++ )
|
||||||
|
// {
|
||||||
|
// String[] files = System.getProperty( TYPE_PROP[s][1] ).split( File.pathSeparator );
|
||||||
|
// // indexed on the property's type
|
||||||
|
// includes.put( TYPE_PROP[s][0], files );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public GeneratedConfigurationSource( /*ConfigurationSource source */)
|
||||||
|
// throws URISyntaxException
|
||||||
|
// {
|
||||||
|
// this( /*Configuration.resolveSource(),*/"a JsUnit test suite", getRequiredURISystemProperty( PROP_COREJS ), getRequiredURISystemProperty( PROP_TESTRUNNER ) );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // public GeneratedConfigurationSource() throws URISyntaxException
|
||||||
|
// // {
|
||||||
|
// // this( Configuration.resolveSource() );
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // ACCESSORS
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// public File getTestSuitePage()
|
||||||
|
// {
|
||||||
|
// return testSuitePage;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setTestSuitePage( File testSuitePage )
|
||||||
|
// {
|
||||||
|
// this.testSuitePage = testSuitePage;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public String getProject()
|
||||||
|
// {
|
||||||
|
// return project;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setProject( String project )
|
||||||
|
// {
|
||||||
|
// this.project = project;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public String getCoreJs()
|
||||||
|
// {
|
||||||
|
// return coreJs;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setCoreJs( String coreJs )
|
||||||
|
// {
|
||||||
|
// this.coreJs = coreJs;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public String getTestRunner()
|
||||||
|
// {
|
||||||
|
// return testRunner;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setTestRunner( String testRunner )
|
||||||
|
// {
|
||||||
|
// this.testRunner = testRunner;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public Map getIncludes()
|
||||||
|
// {
|
||||||
|
// return includes;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// public void setIncludes( Map includes )
|
||||||
|
// {
|
||||||
|
// this.includes = includes;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // UTILITY METHODS
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// /** The best effort to get a well formed URI */
|
||||||
|
// private static URI getURI( String text ) throws URISyntaxException
|
||||||
|
// {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// return new URL( text ).toURI();
|
||||||
|
// }
|
||||||
|
// catch ( MalformedURLException murle )
|
||||||
|
// {
|
||||||
|
// return new File( text ).toURI();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @param key
|
||||||
|
// * the name of the property to retrieve
|
||||||
|
// * @return A well formed URI based on the value of the given property
|
||||||
|
// * @throws IllegalArgumentException
|
||||||
|
// * if the given property doesn't exist.
|
||||||
|
// */
|
||||||
|
// private static String getRequiredURISystemProperty( String key )
|
||||||
|
// throws URISyntaxException
|
||||||
|
// {
|
||||||
|
// String val = System.getProperty( key );
|
||||||
|
//
|
||||||
|
// if ( val == null )
|
||||||
|
// {
|
||||||
|
// System.err.println( "Missing property : " + key );
|
||||||
|
// throw new IllegalArgumentException( "Missing property : " + key );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return getURI( val ).toString();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // ConfigurationSource IMPLEMENTATION
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Before calling this method, make sure {@link #setTestSuitePage(File)} has been correctly set.
|
||||||
|
// * @throws IllegalStateException if a property is missing or is incorrect
|
||||||
|
// */
|
||||||
|
// public String makeUrl() throws URISyntaxException, IOException
|
||||||
|
// {
|
||||||
|
// // try
|
||||||
|
// // {
|
||||||
|
// // returns the full URL to use with JsUnit
|
||||||
|
// return getRequiredURISystemProperty( PROP_TESTRUNNER ) + "?testPage="
|
||||||
|
// + getTestSuitePage().getCanonicalPath();
|
||||||
|
//
|
||||||
|
// // }
|
||||||
|
// // // URISyntaxException, IOException
|
||||||
|
// // catch ( Exception e )
|
||||||
|
// // {
|
||||||
|
// // e.printStackTrace( System.err );
|
||||||
|
// // throw new IllegalStateException( e );
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package net.jsunit;
|
||||||
|
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import net.jsunit.configuration.Configuration;
|
||||||
|
import net.jsunit.configuration.ConfigurationSource;
|
||||||
|
import net.jsunit.configuration.DelegatingConfigurationSource;
|
||||||
|
import net.jsunit.model.Browser;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a JsUnit test suite page giving resources and executes it against
|
||||||
|
* JUnit.
|
||||||
|
*
|
||||||
|
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||||
|
*/
|
||||||
|
public class GeneratedStandaloneTest extends StandaloneTest
|
||||||
|
{
|
||||||
|
|
||||||
|
//
|
||||||
|
// INITIALISATION
|
||||||
|
//
|
||||||
|
|
||||||
|
public GeneratedStandaloneTest( String name )
|
||||||
|
{
|
||||||
|
super( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public GeneratedStandaloneTest( ConfigurationSource source )
|
||||||
|
{
|
||||||
|
super( "" );//new GeneratedConfigurationSource( source ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// JUNIT SPECIFICATIONS
|
||||||
|
//
|
||||||
|
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TestSuite suite = new TestSuite();
|
||||||
|
ConfigurationSource originalSource = Configuration.resolveSource();
|
||||||
|
Configuration configuration = new Configuration( originalSource );
|
||||||
|
for ( final Browser browser : configuration.getBrowsers() )
|
||||||
|
{
|
||||||
|
suite.addTest( new GeneratedStandaloneTest( new DelegatingConfigurationSource( originalSource ) {
|
||||||
|
public String browserFileNames()
|
||||||
|
{
|
||||||
|
return browser.getFileName();
|
||||||
|
}
|
||||||
|
} ) );
|
||||||
|
}
|
||||||
|
return suite;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
e.printStackTrace( System.err );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue