| 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.Project; 14 import org.apache.tools.ant.taskdefs.Delete; 15 import org.apache.tools.ant.types.Path; 16 17 public class IvyCachePathTest extends TestCase { 18 private File _cache; 19 private IvyCachePath _path; 20 private Project _project; 21 22 protected void setUp() throws Exception { 23 createCache(); 24 _project = new Project(); 25 _project.setProperty("ivy.conf.file", "test/repositories/ivyconf.xml"); 26 27 _path = new IvyCachePath(); 28 _path.setProject(_project); 29 _path.setCache(_cache); 30 } 31 32 private void createCache() { 33 _cache = new File ("build/cache"); 34 _cache.mkdirs(); 35 } 36 37 protected void tearDown() throws Exception { 38 cleanCache(); 39 } 40 41 private void cleanCache() { 42 Delete del = new Delete(); 43 del.setProject(new Project()); 44 del.setDir(_cache); 45 del.execute(); 46 } 47 48 public void testSimple() throws Exception { 49 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-simple.xml"); 50 _path.setPathid("simple-pathid"); 51 _path.execute(); 52 Object ref = _project.getReference("simple-pathid"); 53 assertNotNull(ref); 54 assertTrue(ref instanceof Path); 55 Path p = (Path)ref; 56 assertEquals(1, p.size()); 57 assertEquals(_path.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), 58 new File (p.list()[0]).getAbsolutePath()); 59 } 60 61 public void testInline1() throws Exception { 62 IvyResolve resolve = new IvyResolve(); 64 resolve.setProject(_project); 65 resolve.setFile(new File ("test/java/fr/jayasoft/ivy/ant/ivy-latest.xml")); 66 resolve.execute(); 67 68 assertTrue(_path.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); 69 70 _path.setOrganisation("org1"); 72 _path.setModule("mod1.2"); 73 _path.setRevision("2.0"); 74 _path.setInline(true); 75 _path.setPathid("simple-pathid"); 76 _path.execute(); 77 Object ref = _project.getReference("simple-pathid"); 78 assertNotNull(ref); 79 assertTrue(ref instanceof Path); 80 Path p = (Path)ref; 81 assertEquals(1, p.size()); 82 assertEquals(_path.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), 83 new File (p.list()[0]).getAbsolutePath()); 84 } 85 86 public void testInline2() throws Exception { 87 _path.setOrganisation("org1"); 89 _path.setModule("mod1.2"); 90 _path.setRevision("2.0"); 91 _path.setInline(true); 92 _path.setPathid("simple-pathid"); 93 _path.execute(); 94 Object ref = _project.getReference("simple-pathid"); 95 assertNotNull(ref); 96 assertTrue(ref instanceof Path); 97 Path p = (Path)ref; 98 assertEquals(1, p.size()); 99 assertEquals(_path.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), 100 new File (p.list()[0]).getAbsolutePath()); 101 102 IvyResolve resolve = new IvyResolve(); 104 resolve.setProject(_project); 105 resolve.setFile(new File ("test/java/fr/jayasoft/ivy/ant/ivy-latest.xml")); 106 resolve.execute(); 107 108 assertTrue(_path.getIvyInstance().getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists()); 109 } 110 111 112 public void testEmptyConf() throws Exception { 113 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-108.xml"); 114 _path.setPathid("emptyconf-pathid"); 115 _path.setConf("empty"); 116 _path.execute(); 117 Object ref = _project.getReference("emptyconf-pathid"); 118 assertNotNull(ref); 119 assertTrue(ref instanceof Path); 120 Path p = (Path)ref; 121 assertEquals(0, p.size()); 122 } 123 124 public void testFailure() throws Exception { 125 try { 126 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-failure.xml"); 127 _path.setPathid("failure-pathid"); 128 _path.execute(); 129 fail("failure didn't raised an exception with default haltonfailure setting"); 130 } catch (BuildException ex) { 131 } 133 } 134 135 public void testHaltOnFailure() throws Exception { 136 try { 137 _project.setProperty("ivy.dep.file", "test/java/fr/jayasoft/ivy/ant/ivy-failure.xml"); 138 _path.setPathid("haltfailure-pathid"); 139 _path.setHaltonfailure(false); 140 _path.execute(); 141 } catch (BuildException ex) { 142 fail("failure raised an exception with haltonfailure set to false"); 143 } 144 } 145 } 146 | Popular Tags |