1 7 package fr.jayasoft.ivy.parser; 8 9 import java.util.Arrays ; 10 11 import fr.jayasoft.ivy.Artifact; 12 import fr.jayasoft.ivy.Configuration; 13 import fr.jayasoft.ivy.DependencyArtifactDescriptor; 14 import fr.jayasoft.ivy.DependencyDescriptor; 15 import fr.jayasoft.ivy.ModuleDescriptor; 16 import fr.jayasoft.ivy.Configuration.Visibility; 17 import junit.framework.TestCase; 18 19 public abstract class AbstractModuleDescriptorParserTester extends TestCase { 20 protected DependencyDescriptor getDependency(DependencyDescriptor[] dependencies, String name) { 21 for (int i = 0; i < dependencies.length; i++) { 22 assertNotNull(dependencies[i]); 23 assertNotNull(dependencies[i].getDependencyId()); 24 if (name.equals(dependencies[i].getDependencyId().getName())) { 25 return dependencies[i]; 26 } 27 } 28 return null; 29 } 30 31 protected void assertArtifacts(Artifact[] artifacts, String [] artifactsNames) { 32 assertNotNull(artifacts); 33 assertEquals(artifactsNames.length, artifacts.length); 34 for (int i = 0; i < artifactsNames.length; i++) { 35 boolean found = false; 36 for (int j = 0; j < artifacts.length; j++) { 37 assertNotNull(artifacts[j]); 38 if (artifacts[j].getName().equals(artifactsNames[i])) { 39 found = true; 40 break; 41 } 42 } 43 assertTrue("artifact not found: "+artifactsNames[i], found); 44 } 45 } 46 47 protected void assertDependencyArtifactsIncludes(DependencyDescriptor dd, String [] confs, String [] artifactsNames) { 48 DependencyArtifactDescriptor[] dads = dd.getDependencyArtifactsIncludes(confs); 49 assertNotNull(dads); 50 assertEquals(artifactsNames.length, dads.length); 51 for (int i = 0; i < artifactsNames.length; i++) { 52 boolean found = false; 53 for (int j = 0; j < dads.length; j++) { 54 assertNotNull(dads[j]); 55 if (dads[j].getName().equals(artifactsNames[i])) { 56 found = true; 57 break; 58 } 59 } 60 assertTrue("dependency artifact include not found: "+artifactsNames[i], found); 61 } 62 } 63 64 protected void assertDependencyArtifactsExcludes(DependencyDescriptor dd, String [] confs, String [] artifactsNames) { 65 DependencyArtifactDescriptor[] dads = dd.getDependencyArtifactsExcludes(confs); 66 assertNotNull(dads); 67 assertEquals(artifactsNames.length, dads.length); 68 for (int i = 0; i < artifactsNames.length; i++) { 69 boolean found = false; 70 for (int j = 0; j < dads.length; j++) { 71 assertNotNull(dads[j]); 72 if (dads[j].getName().equals(artifactsNames[i])) { 73 found = true; 74 break; 75 } 76 } 77 assertTrue("dependency artifact exclude not found: "+artifactsNames[i], found); 78 } 79 } 80 81 protected void assertDependencyModulesExcludes(DependencyDescriptor dd, String [] confs, String [] moduleNames) { 82 DependencyArtifactDescriptor[] dads = dd.getDependencyArtifactsExcludes(confs); 83 assertNotNull(dads); 84 assertEquals(moduleNames.length, dads.length); 85 for (int i = 0; i < moduleNames.length; i++) { 86 boolean found = false; 87 for (int j = 0; j < dads.length; j++) { 88 assertNotNull(dads[j]); 89 if (dads[j].getId().getModuleId().getName().equals(moduleNames[i])) { 90 found = true; 91 break; 92 } 93 } 94 assertTrue("dependency module exclude not found: "+moduleNames[i], found); 95 } 96 } 97 98 protected void assertConf(ModuleDescriptor md, String name, String desc, Visibility visibility, String [] exts) { 99 Configuration conf = md.getConfiguration(name); 100 assertNotNull("configuration not found: "+name, conf); 101 assertEquals(name, conf.getName()); 102 assertEquals(desc, conf.getDescription()); 103 assertEquals(visibility, conf.getVisibility()); 104 assertEquals(Arrays.asList(exts), Arrays.asList(conf.getExtends())); 105 } 106 107 } 108 | Popular Tags |