FileDocCategorySizeDatePackage
ImportTest.javaAPI DocApache Ant 1.706340Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

ImportTest

public class ImportTest extends org.apache.tools.ant.BuildFileTest

Fields Summary
Constructors Summary
public ImportTest(String name)

        super(name);
    
Methods Summary
public voidnotTestImportInTargetWithEffect()

        configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
        expectPropertySet("do-import", "foo", "bar");
        assertNotNull(getProject().getReference("baz"));
    
public voidsetUp()

    
public voidtearDown()

    
public voidtestImportError()

        try {
            configureProject(
                "src/etc/testcases/taskdefs/import/import_bad_import.xml");
        } catch (BuildException ex) {
            Location lo = ex.getLocation();
            assertTrue(
                "expected location of build exception to be set",
                (lo != null));
            assertTrue(
                "expected location to contain calling file",
                lo.getFileName().indexOf("import_bad_import.xml") != -1);
            assertTrue(
                "expected message of ex to contain called file",
                ex.getMessage().indexOf("bad.xml") != -1);
            return;
        }
        assertTrue(
            "Did not see build exception",
            false);
    
public voidtestImportInSequential()

        configureProject(
            "src/etc/testcases/taskdefs/import/subdir/importinsequential.xml");
        expectPropertySet("within-imported", "foo", "bar");
        assertNotNull(getProject().getReference("baz"));
    
public voidtestImportInTargetNoEffect()

        configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
        expectPropertyUnset("no-import", "foo");
        assertTrue(null == getProject().getReference("baz"));
    
public voidtestImportInTargetNotAllowed()

        configureProject(
            "src/etc/testcases/taskdefs/import/subdir/importintarget.xml");
        expectBuildExceptionContaining(
            "do-import", "not a top level task",
            "import only allowed as a top-level task");
    
public voidtestImportSameTargets()

        try {
            configureProject(
                "src/etc/testcases/taskdefs/import/same_target.xml");
        } catch (BuildException ex) {
            String message = ex.getMessage();
            if (message.indexOf("Duplicate target") == -1) {
                assertTrue("Did not see 'Duplicate target' in '" + message +"'", false);
            }
            return;
        }
        assertTrue(
            "Did not see build exception",
            false);
    
public voidtestSerial()

        configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml");
        assertLogContaining("Unnamed2.xmlUnnamed1.xml");
        String fullLog = getFullLog();
        String substring = "Skipped already imported file";
        assertTrue("expecting full log to contain \"" + substring
            + "\" full log was \"" + fullLog + "\"",
            fullLog.indexOf(substring) >= 0);
    
public voidtestSimpleImport()

        configureProject("src/etc/testcases/taskdefs/import/import.xml");
        assertLogContaining("Before importIn imported topAfter import");
    
public voidtestSymlinkedImports()

        String ln = "/usr/bin/ln";
        if (!new File(ln).exists()) {
            ln = "/bin/ln";
        }
        if (!new File(ln).exists()) {
            // Running on Windows or something, so skip it.
            return;
        }
        String symlink = "src/etc/testcases/taskdefs/import/symlinks/d3b";
        File symlinkFile = new File(System.getProperty("root"), symlink);
        if (Runtime.getRuntime().exec(new String[] {ln, "-s", "d3a", symlinkFile.getAbsolutePath()}).waitFor() != 0) {
            throw new IOException("'" + ln + " -s d3a " + symlink + "' failed");
        }
        try {
            configureProject(
                "src/etc/testcases/taskdefs/import/symlinks/d1/p1.xml");
            assertPropertyEquals(
                "ant.file.p2",
                new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d2/p2.xml")
                .getAbsolutePath());
            assertPropertyEquals(
                "ant.file.p3",
                new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d3b/p3.xml")
                .getAbsolutePath());
        } finally {
            symlinkFile.delete();
        }
    
public voidtestTargetFirst()

        configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml");
        assertLogContaining("Importing targetfirstAfter target firstAfter importing");
    
public voidtestTargetName()

        configureProject("src/etc/testcases/taskdefs/import/c.xml");
    
public voidtestUnnamedNesting()

        configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml",
                         Project.MSG_WARN);
        String log = getLog();
        assertTrue("Warnings logged when not expected: " + log,
                    log.length() == 0);