1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.File ; 9 10 import junit.framework.TestCase; 11 12 import org.apache.tools.ant.BuildException; 13 import org.apache.tools.ant.DirectoryScanner; 14 import org.apache.tools.ant.Project; 15 import org.apache.tools.ant.taskdefs.Delete; 16 import org.apache.tools.ant.types.FileSet; 17 18 public class IvyCacheFilesetTest extends TestCase { 19 private File _cache; 20 private IvyCacheFileset _fileset; 21 private Project _project; 22 23 protected void setUp() throws Exception { 24 createCache(); 25 _project = new Project(); 26 _project.setProperty("ivy.conf.file", "test/repositories/ivyconf.xml"); 27 28 _fileset = new IvyCacheFileset(); 29 _fileset.setProject(_project); 30 _fileset.setCache(_cache); 31 } 32 33 private void createCache() { 34 _cache = new File ("build/cache"); 35 _cache.mkdirs(); 36 } 37 38 protected void tearDown() throws Exception { 39 cleanCache(); 40 } 41 42 private void cleanCache() { 43 Delete del = new Delete(); 44 del.setProject(new Project()); 45 del.setDir(_cache); 46 del.execute(); 47 } 48 49 public void testSimple() throws Exception { 50 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-simple.xml"); 51 _fileset.setSetid("simple-setid"); 52 _fileset.execute(); 53 Object ref = _project.getReference("simple-setid"); 54 assertNotNull(ref); 55 assertTrue(ref instanceof FileSet); 56 FileSet fs = (FileSet)ref; 57 DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); 58 assertEquals(1, directoryScanner.getIncludedFiles().length); 59 assertEquals(_fileset.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), 60 new File ("build/cache/"+directoryScanner.getIncludedFiles()[0]).getAbsolutePath()); 61 } 62 63 public void testEmptyConf() throws Exception { 64 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-108.xml"); 65 _fileset.setSetid("emptyconf-setid"); 66 _fileset.setConf("empty"); 67 _fileset.execute(); 68 Object ref = _project.getReference("emptyconf-setid"); 69 assertNotNull(ref); 70 assertTrue(ref instanceof FileSet); 71 FileSet fs = (FileSet)ref; 72 DirectoryScanner directoryScanner = fs.getDirectoryScanner(_project); 73 assertEquals(0, directoryScanner.getIncludedFiles().length); 74 } 75 76 public void testFailure() throws Exception { 77 try { 78 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-failure.xml"); 79 _fileset.setSetid("failure-setid"); 80 _fileset.execute(); 81 fail("failure didn't raised an exception with default haltonfailure setting"); 82 } catch (BuildException ex) { 83 } 85 } 86 87 public void testHaltOnFailure() throws Exception { 88 try { 89 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-failure.xml"); 90 _fileset.setSetid("haltfailure-setid"); 91 _fileset.setHaltonfailure(false); 92 _fileset.execute(); 93 } catch (BuildException ex) { 94 fail("failure raised an exception with haltonfailure set to false"); 95 } 96 } 97 } 98 | Popular Tags |