KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > resolver > IvyRepResolverTest


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.resolver;
7
8 import java.io.File JavaDoc;
9 import java.util.List JavaDoc;
10
11 import junit.framework.TestCase;
12
13 import org.apache.tools.ant.Project;
14 import org.apache.tools.ant.taskdefs.Delete;
15
16 import fr.jayasoft.ivy.Artifact;
17 import fr.jayasoft.ivy.DefaultArtifact;
18 import fr.jayasoft.ivy.DefaultDependencyDescriptor;
19 import fr.jayasoft.ivy.Ivy;
20 import fr.jayasoft.ivy.ModuleRevisionId;
21 import fr.jayasoft.ivy.ResolveData;
22 import fr.jayasoft.ivy.ResolvedModuleRevision;
23 import fr.jayasoft.ivy.report.ArtifactDownloadReport;
24 import fr.jayasoft.ivy.report.DownloadReport;
25 import fr.jayasoft.ivy.report.DownloadStatus;
26
27 /**
28  *
29  */

30 public class IvyRepResolverTest extends TestCase {
31     // remote.test
32

33     private File JavaDoc _cache;
34     private ResolveData _data;
35     private Ivy _ivy;
36     
37     protected void setUp() throws Exception JavaDoc {
38         _cache = new File JavaDoc("build/cache");
39         _ivy = new Ivy();
40         _data = new ResolveData(_ivy, _cache, null, null, false);
41         _cache.mkdirs();
42     }
43     
44     protected void tearDown() throws Exception JavaDoc {
45         Delete del = new Delete();
46         del.setProject(new Project());
47         del.setDir(_cache);
48         del.execute();
49     }
50
51     public void testDefaults() {
52         IvyRepResolver resolver = new IvyRepResolver();
53         Ivy ivy = new Ivy();
54         ivy.setVariable("ivy.ivyrep.default.ivy.root", "http://www.jayasoft.fr/myivyrep/");
55         ivy.setVariable("ivy.ivyrep.default.ivy.pattern", "[organisation]/[module]/ivy-[revision].[ext]");
56         ivy.setVariable("ivy.ivyrep.default.artifact.root", "http://www.ibiblio.org/mymaven/");
57         ivy.setVariable("ivy.ivyrep.default.artifact.pattern", "[module]/jars/[artifact]-[revision].jar");
58         resolver.setIvy(ivy);
59         List JavaDoc l = resolver.getIvyPatterns();
60         assertNotNull(l);
61         assertEquals(1, l.size());
62         assertEquals("http://www.jayasoft.fr/myivyrep/[organisation]/[module]/ivy-[revision].[ext]", l.get(0));
63         l = resolver.getArtifactPatterns();
64         assertNotNull(l);
65         assertEquals(1, l.size());
66         assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l.get(0));
67     }
68
69     public void testIvyRep() throws Exception JavaDoc {
70         IvyRepResolver resolver = new IvyRepResolver();
71         resolver.setName("test");
72         resolver.setIvy(_ivy);
73         assertEquals("test", resolver.getName());
74         
75         ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-cli", "1.0");
76         ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data);
77         assertNotNull(rmr);
78         assertEquals(mrid, rmr.getId());
79         assertEquals(2, rmr.getDescriptor().getDependencies().length);
80
81         DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "commons-cli", "jar", "jar");
82         DownloadReport report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache);
83         assertNotNull(report);
84         
85         assertEquals(1, report.getArtifactsReports().length);
86         
87         ArtifactDownloadReport ar = report.getArtifactReport(artifact);
88         assertNotNull(ar);
89         
90         assertEquals(artifact, ar.getArtifact());
91         assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
92
93         // test to ask to download again, should use cache
94
report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache);
95         assertNotNull(report);
96         
97         assertEquals(1, report.getArtifactsReports().length);
98         
99         ar = report.getArtifactReport(artifact);
100         assertNotNull(ar);
101         
102         assertEquals(artifact, ar.getArtifact());
103         assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
104     }
105     
106     /*
107      * Tests IvyRepResolver with a root path given as 'file:/path_to_root'
108      */

109     public void testIvyRepLocalURL() throws Exception JavaDoc {
110         IvyRepResolver resolver = new IvyRepResolver();
111         String JavaDoc rootpath = new File JavaDoc("test/repositories/1").getAbsolutePath();
112
113         resolver.setName("testLocal");
114         resolver.setIvyroot("file:" + rootpath);
115         resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml");
116         resolver.setIvy(_ivy);
117         
118         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
119         ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data);
120         assertNotNull(rmr);
121     }
122     
123     public void testListing() {
124         IvyRepResolver resolver = new IvyRepResolver();
125         resolver.setName("test");
126         resolver.setIvy(_ivy);
127         
128         OrganisationEntry[] orgs = resolver.listOrganisations();
129         ResolverTestHelper.assertOrganisationEntriesContains(resolver, new String JavaDoc[] {"hibernate", "apache"}, orgs);
130         
131         OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "apache");
132         ModuleEntry[] mods = resolver.listModules(org);
133         ResolverTestHelper.assertModuleEntriesContains(resolver, org, new String JavaDoc[] {"commons-logging", "commons-lang"}, mods);
134
135         ModuleEntry mod = ResolverTestHelper.getEntry(mods, "commons-logging");
136         RevisionEntry[] revs = resolver.listRevisions(mod);
137         ResolverTestHelper.assertRevisionEntriesContains(resolver, mod, new String JavaDoc[] {"1.0", "1.0.2", "1.0.3", "1.0.4"}, revs);
138     }
139 }
140
Popular Tags