1 6 package fr.jayasoft.ivy.resolver; 7 8 import java.io.File ; 9 import java.util.List ; 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.DefaultDependencyArtifactDescriptor; 19 import fr.jayasoft.ivy.DefaultDependencyDescriptor; 20 import fr.jayasoft.ivy.Ivy; 21 import fr.jayasoft.ivy.ModuleRevisionId; 22 import fr.jayasoft.ivy.ResolveData; 23 import fr.jayasoft.ivy.ResolvedModuleRevision; 24 import fr.jayasoft.ivy.matcher.ExactPatternMatcher; 25 import fr.jayasoft.ivy.report.ArtifactDownloadReport; 26 import fr.jayasoft.ivy.report.DownloadReport; 27 import fr.jayasoft.ivy.report.DownloadStatus; 28 29 32 public class IBiblioResolverTest extends TestCase { 33 35 private File _cache; 36 private ResolveData _data; 37 private Ivy _ivy; 38 39 protected void setUp() throws Exception { 40 _cache = new File ("build/cache"); 41 _ivy = new Ivy(); 42 _data = new ResolveData(_ivy, _cache, null, null, true); 43 _cache.mkdirs(); 44 } 45 46 protected void tearDown() throws Exception { 47 Delete del = new Delete(); 48 del.setProject(new Project()); 49 del.setDir(_cache); 50 del.execute(); 51 } 52 53 public void testDefaults() { 54 IBiblioResolver resolver = new IBiblioResolver(); 55 Ivy ivy = new Ivy(); 56 ivy.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/mymaven/"); 57 ivy.setVariable("ivy.ibiblio.default.artifact.pattern", "[module]/jars/[artifact]-[revision].jar"); 58 resolver.setIvy(ivy); 59 List l = resolver.getArtifactPatterns(); 60 assertNotNull(l); 61 assertEquals(1, l.size()); 62 assertEquals("http://www.ibiblio.org/mymaven/[module]/jars/[artifact]-[revision].jar", l.get(0)); 63 } 64 65 public void testInitFromConf() throws Exception { 66 Ivy ivy = new Ivy(); 67 ivy.setVariable("ivy.ibiblio.default.artifact.root", "http://www.ibiblio.org/maven/"); 68 ivy.setVariable("ivy.ibiblio.default.artifact.pattern", "[module]/jars/[artifact]-[revision].jar"); 69 ivy.setVariable("my.ibiblio.root", "http://www.ibiblio.org/mymaven/"); 70 ivy.setVariable("my.ibiblio.pattern", "[module]/[artifact]-[revision].jar"); 71 ivy.configure(IBiblioResolverTest.class.getResource("ibiblioresolverconf.xml")); 72 IBiblioResolver resolver = (IBiblioResolver)ivy.getResolver("ibiblioA"); 73 assertNotNull(resolver); 74 List l = resolver.getArtifactPatterns(); 75 assertNotNull(l); 76 assertEquals(1, l.size()); 77 assertEquals("http://www.ibiblio.org/mymaven/[module]/[artifact]-[revision].jar", l.get(0)); 78 79 resolver = (IBiblioResolver)ivy.getResolver("ibiblioB"); 80 assertNotNull(resolver); 81 l = resolver.getArtifactPatterns(); 82 assertNotNull(l); 83 assertEquals(1, l.size()); 84 assertEquals("http://www.ibiblio.org/mymaven/[organisation]/jars/[artifact]-[revision].jar", l.get(0)); 85 86 resolver = (IBiblioResolver)ivy.getResolver("ibiblioC"); 87 assertTrue(resolver.isM2compatible()); 88 assertNotNull(resolver); 89 l = resolver.getArtifactPatterns(); 90 assertNotNull(l); 91 assertEquals(1, l.size()); 92 assertEquals("http://www.ibiblio.org/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]", l.get(0)); 93 94 resolver = (IBiblioResolver)ivy.getResolver("ibiblioD"); 95 assertFalse(resolver.isM2compatible()); 96 assertNotNull(resolver); 97 l = resolver.getArtifactPatterns(); 98 assertNotNull(l); 99 assertEquals(1, l.size()); 100 assertEquals("http://www.ibiblio.org/maven/[module]/jars/[artifact]-[revision].jar", l.get(0)); 101 } 102 103 public void testIBiblio() throws Exception { 104 String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); 105 if (ibiblioRoot == null) { 106 return; 107 } 108 109 IBiblioResolver resolver = new IBiblioResolver(); 110 resolver.setRoot(ibiblioRoot); 111 resolver.setName("test"); 112 resolver.setIvy(_ivy); 113 assertEquals("test", resolver.getName()); 114 115 ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "commons-fileupload", "1.0"); 116 ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), _data); 117 assertNotNull(rmr); 118 assertEquals(mrid, rmr.getId()); 119 120 DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "commons-fileupload", "jar", "jar"); 121 DownloadReport report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache); 122 assertNotNull(report); 123 124 assertEquals(1, report.getArtifactsReports().length); 125 126 ArtifactDownloadReport ar = report.getArtifactReport(artifact); 127 assertNotNull(ar); 128 129 assertEquals(artifact, ar.getArtifact()); 130 assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); 131 132 report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache); 134 assertNotNull(report); 135 136 assertEquals(1, report.getArtifactsReports().length); 137 138 ar = report.getArtifactReport(artifact); 139 assertNotNull(ar); 140 141 assertEquals(artifact, ar.getArtifact()); 142 assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); 143 } 144 145 public void testIBiblioArtifacts() throws Exception { 146 String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); 147 if (ibiblioRoot == null) { 148 return; 149 } 150 151 IBiblioResolver resolver = new IBiblioResolver(); 152 resolver.setRoot(ibiblioRoot); 153 resolver.setName("test"); 154 resolver.setIvy(_ivy); 155 assertEquals("test", resolver.getName()); 156 157 ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", "nanning", "0.9"); 158 DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false); 159 dd.addDependencyArtifactIncludes("default", new DefaultDependencyArtifactDescriptor(dd, "nanning-profiler", "jar", "jar", true, ExactPatternMatcher.getInstance())); 160 dd.addDependencyArtifactIncludes("default", new DefaultDependencyArtifactDescriptor(dd, "nanning-trace", "jar", "jar", true, ExactPatternMatcher.getInstance())); 161 ResolvedModuleRevision rmr = resolver.getDependency(dd, _data); 162 assertNotNull(rmr); 163 assertEquals(mrid, rmr.getId()); 164 165 DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "nanning-profiler", "jar", "jar"); 166 DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "nanning-trace", "jar", "jar"); 167 DownloadReport report = resolver.download(new Artifact[] {profiler, trace}, _data.getIvy(), _cache); 168 assertNotNull(report); 169 170 assertEquals(2, report.getArtifactsReports().length); 171 172 ArtifactDownloadReport ar = report.getArtifactReport(profiler); 173 assertNotNull(ar); 174 175 assertEquals(profiler, ar.getArtifact()); 176 assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); 177 178 ar = report.getArtifactReport(trace); 179 assertNotNull(ar); 180 181 assertEquals(trace, ar.getArtifact()); 182 assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus()); 183 184 report = resolver.download(new Artifact[] {profiler, trace}, _data.getIvy(), _cache); 186 assertNotNull(report); 187 188 assertEquals(2, report.getArtifactsReports().length); 189 190 ar = report.getArtifactReport(profiler); 191 assertNotNull(ar); 192 193 assertEquals(profiler, ar.getArtifact()); 194 assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); 195 196 ar = report.getArtifactReport(trace); 197 assertNotNull(ar); 198 199 assertEquals(trace, ar.getArtifact()); 200 assertEquals(DownloadStatus.NO, ar.getDownloadStatus()); 201 } 202 203 public void testUnknown() throws Exception { 204 String ibiblioRoot = IBiblioHelper.getIBiblioMirror(); 205 if (ibiblioRoot == null) { 206 return; 207 } 208 209 IBiblioResolver resolver = new IBiblioResolver(); 210 resolver.setRoot(ibiblioRoot); 211 resolver.setName("test"); 212 resolver.setIvy(_ivy); 213 214 assertNull(resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("unknown", "unknown", "1.0"), false), _data)); 215 } 216 217 } 218 | Popular Tags |