KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ant > IvyCachePathTest


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.ant;
7
8 import java.io.File JavaDoc;
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 JavaDoc _cache;
19     private IvyCachePath _path;
20     private Project _project;
21     
22     protected void setUp() throws Exception JavaDoc {
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 JavaDoc("build/cache");
34         _cache.mkdirs();
35     }
36     
37     protected void tearDown() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc 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 JavaDoc(p.list()[0]).getAbsolutePath());
59     }
60
61     public void testInline1() throws Exception JavaDoc {
62         // we first resolve another ivy file
63
IvyResolve resolve = new IvyResolve();
64         resolve.setProject(_project);
65         resolve.setFile(new File JavaDoc("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         // then we resolve a dependency directly
71
_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 JavaDoc 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 JavaDoc(p.list()[0]).getAbsolutePath());
84     }
85
86     public void testInline2() throws Exception JavaDoc {
87         // we first resolve a dependency directly
88
_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 JavaDoc 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 JavaDoc(p.list()[0]).getAbsolutePath());
101
102         // we then resolve another ivy file
103
IvyResolve resolve = new IvyResolve();
104         resolve.setProject(_project);
105         resolve.setFile(new File JavaDoc("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 JavaDoc {
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 JavaDoc 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 JavaDoc {
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             // ok => should raised an exception
132
}
133     }
134
135     public void testHaltOnFailure() throws Exception JavaDoc {
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