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.Project; 13 14 import fr.jayasoft.ivy.Ivy; 15 16 public class IvyConfigureTest extends TestCase { 17 private File _cache; 18 private IvyConfigure _configure; 19 20 protected void setUp() throws Exception { 21 Project project = new Project(); 22 project.setProperty("myproperty", "myvalue"); 23 24 _configure = new IvyConfigure(); 25 _configure.setProject(project); 26 } 27 28 public void testFile() throws Exception { 29 _configure.setFile(new File ("test/repositories/ivyconf.xml")); 30 31 _configure.execute(); 32 33 Ivy ivy = getIvyInstance(); 34 assertNotNull(ivy); 35 36 assertEquals(new File ("build/cache"), ivy.getDefaultCache()); 37 assertEquals(new File ("test/repositories/ivyconf.xml").getAbsolutePath(), ivy.getVariables().get("ivy.conf.file")); 38 assertEquals(new File ("test/repositories/ivyconf.xml").toURL().toExternalForm(), ivy.getVariables().get("ivy.conf.url")); 39 assertEquals(new File ("test/repositories").getAbsolutePath(), ivy.getVariables().get("ivy.conf.dir")); 40 assertEquals("myvalue", ivy.getVariables().get("myproperty")); 41 } 42 43 public void testURL() throws Exception { 44 String confUrl = new File ("test/repositories/ivyconf.xml").toURL().toExternalForm(); 45 String confDirUrl = new File ("test/repositories").toURL().toExternalForm(); 46 if (confDirUrl.endsWith("/")) { 47 confDirUrl = confDirUrl.substring(0, confDirUrl.length() - 1); 48 } 49 _configure.setUrl(confUrl); 50 51 _configure.execute(); 52 53 Ivy ivy = getIvyInstance(); 54 assertNotNull(ivy); 55 56 assertEquals(new File ("build/cache"), ivy.getDefaultCache()); 57 assertEquals(confUrl, ivy.getVariables().get("ivy.conf.url")); 58 assertEquals(confDirUrl, ivy.getVariables().get("ivy.conf.dir")); 59 assertEquals("myvalue", ivy.getVariables().get("myproperty")); 60 } 61 62 public void testAntProperties() throws Exception { 63 String confUrl = IvyConfigureTest.class.getResource("ivyconf-test.xml").toExternalForm(); 64 _configure.setUrl(confUrl); 65 66 _configure.execute(); 67 68 Ivy ivy = getIvyInstance(); 69 assertNotNull(ivy); 70 71 assertEquals("myvalue", ivy.getVariables().get("myproperty")); 72 assertEquals("myvalue", ivy.getDefaultCache().getName()); 73 } 74 75 public void testOverrideVariables() throws Exception { 76 String confUrl = IvyConfigureTest.class.getResource("ivyconf-props.xml").toExternalForm(); 77 _configure.setUrl(confUrl); 78 79 _configure.execute(); 80 81 Ivy ivy = getIvyInstance(); 82 assertNotNull(ivy); 83 84 assertEquals("lib/test/[artifact]-[revision].[ext]", ivy.getVariables().get("ivy.retrieve.pattern")); 85 } 86 87 private Ivy getIvyInstance() { 88 return (Ivy)_configure.getProject().getReference("ivy.instance"); 89 } 90 91 } 92 | Popular Tags |