FileDocCategorySizeDatePackage
JavaTest.javaAPI DocApache Ant 1.7010283Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

JavaTest

public class JavaTest extends org.apache.tools.ant.BuildFileTest
stress out java task

Fields Summary
private static final int
TIME_TO_WAIT
private static final int
SECURITY_MARGIN
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
private boolean
runFatalTests
Constructors Summary
public JavaTest(String name)


       
        super(name);
    
Methods Summary
public voidsetUp()
configure the project. if the property junit.run.fatal.tests is set we run the fatal tests

        configureProject("src/etc/testcases/taskdefs/java.xml");

        //final String propname="tests-classpath.value";
        //String testClasspath=System.getProperty(propname);
        //System.out.println("Test cp="+testClasspath);
        String propname="tests-classpath.value";
        String runFatal=System.getProperty("junit.run.fatal.tests");
        if(runFatal!=null)
            runFatalTests=true;
    
public voidtearDown()

        // remove log file from testSpawn
        project.executeTarget("cleanup");
    
public voidtestClassnameAndJar()

        expectBuildException("testClassnameAndJar",
            "Should not be able to set both classname AND jar");
    
public voidtestExcepting()

        expectLogContaining("testExcepting",
                            "Exception raised inside called program");
    
public voidtestExceptingFoe()

        expectBuildExceptionContaining("testExceptingFoe",
            "passes exception through",
            "Exception raised inside called program");
    
public voidtestExceptingFoeFork()

        expectBuildExceptionContaining("testExceptingFoeFork",
            "exceptions turned into error codes",
            "Java returned:");
    
public voidtestExceptingFork()

        expectLogContaining("testExceptingFork",
                            "Java Result:");
    
public voidtestJarAndClassName()

        expectBuildException("testJarAndClassName",
            "Should not be able to set both classname AND jar");
    
public voidtestJarNoFork()

        expectBuildExceptionContaining("testJarNoFork",
            "parameter validation",
            "Cannot execute a jar in non-forked mode. "
                + "Please set fork='true'. ");
    
public voidtestNoJarNoClassname()

        expectBuildExceptionContaining("testNoJarNoClassname",
            "parameter validation",
            "Classname must not be null.");
    
public voidtestRedirect1()

        executeTarget("redirect1");
    
public voidtestRedirect2()

        executeTarget("redirect2");
    
public voidtestRedirect3()

        executeTarget("redirect3");
    
public voidtestRedirector1()

        executeTarget("redirector1");
    
public voidtestRedirector2()

        executeTarget("redirector2");
    
public voidtestResultPropertyNonZero()

        executeTarget("testResultPropertyNonZero");
        assertEquals("2",project.getProperty("exitcode"));
    
public voidtestResultPropertyNonZeroNoFork()

        executeTarget("testResultPropertyNonZeroNoFork");
         assertEquals("-1",project.getProperty("exitcode"));
     
public voidtestResultPropertyZero()

        executeTarget("testResultPropertyZero");
        assertEquals("0",project.getProperty("exitcode"));
    
public voidtestResultPropertyZeroNoFork()

        executeTarget("testResultPropertyZeroNoFork");
        assertEquals("0",project.getProperty("exitcode"));
    
public voidtestRun()

        executeTarget("testRun");
    
public voidtestRunFail()
this test fails but we ignore the return value; we verify that failure only matters when failonerror is set

        if(runFatalTests) {
            executeTarget("testRunFail");
        }
    
public voidtestRunFailFoe()

        if(runFatalTests) {
            expectBuildExceptionContaining("testRunFailFoe",
                "java failures being propagated",
                "Java returned:");
        }
public voidtestRunFailFoeFork()

        expectBuildExceptionContaining("testRunFailFoeFork",
            "java failures being propagated",
            "Java returned:");
    
public voidtestRunFailWithFailOnError()

        expectBuildExceptionContaining("testRunFailWithFailOnError",
            "non zero return code",
            "Java returned:");
    
public voidtestRunSuccessWithFailOnError()

        executeTarget("testRunSuccessWithFailOnError");
    
public voidtestSpawn()

        File logFile = FILE_UTILS.createTempFile("spawn","log", project.getBaseDir());
        // this is guaranteed by FileUtils#createTempFile
        assertTrue("log file not existing", !logFile.exists());
        project.setProperty("logFile", logFile.getAbsolutePath());
        project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT));
        project.executeTarget("testSpawn");
        try {
            Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN);
        } catch (Exception ex) {
            System.out.println("my sleep was interrupted");
        }
        // let's be nice with the next generation of developers
        if (!logFile.exists()) {
            System.out.println("suggestion: increase the constant"
            + " SECURITY_MARGIN to give more time for java to start.");
        }
        assertTrue("log file exists", logFile.exists());