KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > InstallTest


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy;
8
9 import java.io.File JavaDoc;
10
11 import org.apache.tools.ant.Project;
12 import org.apache.tools.ant.taskdefs.Delete;
13
14 import fr.jayasoft.ivy.matcher.PatternMatcher;
15
16 import junit.framework.TestCase;
17
18 public class InstallTest extends TestCase {
19
20     public void testSimple() throws Exception JavaDoc {
21         Ivy ivy = new Ivy();
22         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
23         
24         ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
25                 ivy.getDefaultResolver().getName(),
26                 "install", true, true, true, null, _cache, PatternMatcher.EXACT);
27         
28         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
29         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
30     }
31
32     public void testDependencies() throws Exception JavaDoc {
33         Ivy ivy = new Ivy();
34         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
35         
36         ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
37                 ivy.getDefaultResolver().getName(),
38                 "install", true, true, true, null, _cache, PatternMatcher.EXACT);
39         
40         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
41         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());
42         
43         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
44         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
45     }
46
47     public void testNotTransitive() throws Exception JavaDoc {
48         Ivy ivy = new Ivy();
49         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
50         
51         ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
52                 ivy.getDefaultResolver().getName(),
53                 "install", false, true, true, null, _cache, PatternMatcher.EXACT);
54         
55         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
56         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());
57         
58         assertFalse(new File JavaDoc("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
59         assertFalse(new File JavaDoc("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
60     }
61
62     public void testRegexpMatcher() throws Exception JavaDoc {
63         Ivy ivy = new Ivy();
64         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
65         
66         ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"),
67                 "1",
68                 "install", false, true, true, null, _cache, PatternMatcher.REGEXP);
69         
70         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
71         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());
72         
73         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/ivy-1.1.xml").exists());
74         assertTrue(new File JavaDoc("build/test/install/org1/mod1.1/mod1.1-1.1.jar").exists());
75         
76         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
77         assertTrue(new File JavaDoc("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
78         
79         // mod1.3 is split because Ivy thinks there are two versions of the module:
80
// this is the normal behaviour in this case
81
assertTrue(new File JavaDoc("build/test/install/org1/mod1.3/ivy-B-3.0.xml").exists());
82         assertTrue(new File JavaDoc("build/test/install/org1/mod1.3/ivy-A-3.0.xml").exists());
83         assertTrue(new File JavaDoc("build/test/install/org1/mod1.3/mod1.3-A-3.0.jar").exists());
84         assertTrue(new File JavaDoc("build/test/install/org1/mod1.3/mod1.3-B-3.0.jar").exists());
85         
86         assertTrue(new File JavaDoc("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());
87     }
88
89     
90     
91     private File JavaDoc _cache;
92     protected void setUp() throws Exception JavaDoc {
93         createCache();
94     }
95
96     private void createCache() {
97         _cache = new File JavaDoc("build/cache");
98         _cache.mkdirs();
99     }
100     
101     protected void tearDown() throws Exception JavaDoc {
102         cleanCache();
103         cleanInstall();
104     }
105
106     private void cleanCache() {
107         Delete del = new Delete();
108         del.setProject(new Project());
109         del.setDir(_cache);
110         del.execute();
111     }
112     private void cleanInstall() {
113         Delete del = new Delete();
114         del.setProject(new Project());
115         del.setDir(new File JavaDoc("build/test/install"));
116         del.execute();
117     }
118 }
119
Popular Tags