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.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 30 public class IvyRepResolverTest extends TestCase { 31 33 private File _cache; 34 private ResolveData _data; 35 private Ivy _ivy; 36 37 protected void setUp() throws Exception { 38 _cache = new File ("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 { 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 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 { 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 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 109 public void testIvyRepLocalURL() throws Exception { 110 IvyRepResolver resolver = new IvyRepResolver(); 111 String rootpath = new File ("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 [] {"hibernate", "apache"}, orgs); 130 131 OrganisationEntry org = ResolverTestHelper.getEntry(orgs, "apache"); 132 ModuleEntry[] mods = resolver.listModules(org); 133 ResolverTestHelper.assertModuleEntriesContains(resolver, org, new String [] {"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 [] {"1.0", "1.0.2", "1.0.3", "1.0.4"}, revs); 138 } 139 } 140 | Popular Tags |