001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.plugins.parser;
019:
020: import java.util.Arrays;
021:
022: import junit.framework.TestCase;
023:
024: import org.apache.ivy.core.module.descriptor.Artifact;
025: import org.apache.ivy.core.module.descriptor.Configuration;
026: import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor;
027: import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
028: import org.apache.ivy.core.module.descriptor.ExcludeRule;
029: import org.apache.ivy.core.module.descriptor.IncludeRule;
030: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
031: import org.apache.ivy.core.module.descriptor.Configuration.Visibility;
032:
033: public abstract class AbstractModuleDescriptorParserTester extends
034: TestCase {
035: protected DependencyDescriptor getDependency(
036: DependencyDescriptor[] dependencies, String name) {
037: for (int i = 0; i < dependencies.length; i++) {
038: assertNotNull(dependencies[i]);
039: assertNotNull(dependencies[i].getDependencyId());
040: if (name
041: .equals(dependencies[i].getDependencyId().getName())) {
042: return dependencies[i];
043: }
044: }
045: return null;
046: }
047:
048: protected void assertArtifacts(Artifact[] artifacts,
049: String[] artifactsNames) {
050: assertNotNull(artifacts);
051: assertEquals(artifactsNames.length, artifacts.length);
052: for (int i = 0; i < artifactsNames.length; i++) {
053: boolean found = false;
054: for (int j = 0; j < artifacts.length; j++) {
055: assertNotNull(artifacts[j]);
056: if (artifacts[j].getName().equals(artifactsNames[i])) {
057: found = true;
058: break;
059: }
060: }
061: assertTrue("artifact not found: " + artifactsNames[i],
062: found);
063: }
064: }
065:
066: protected void assertDependencyArtifacts(DependencyDescriptor dd,
067: String[] confs, String[] artifactsNames) {
068: DependencyArtifactDescriptor[] dads = dd
069: .getDependencyArtifacts(confs);
070: assertNotNull(dads);
071: assertEquals(artifactsNames.length, dads.length);
072: for (int i = 0; i < artifactsNames.length; i++) {
073: boolean found = false;
074: for (int j = 0; j < dads.length; j++) {
075: assertNotNull(dads[j]);
076: if (dads[j].getName().equals(artifactsNames[i])) {
077: found = true;
078: break;
079: }
080: }
081: assertTrue("dependency artifact not found: "
082: + artifactsNames[i], found);
083: }
084: }
085:
086: protected void assertDependencyArtifactIncludeRules(
087: DependencyDescriptor dd, String[] confs,
088: String[] artifactsNames) {
089: IncludeRule[] dads = dd.getIncludeRules(confs);
090: assertNotNull(dads);
091: assertEquals(artifactsNames.length, dads.length);
092: for (int i = 0; i < artifactsNames.length; i++) {
093: boolean found = false;
094: for (int j = 0; j < dads.length; j++) {
095: assertNotNull(dads[j]);
096: if (dads[j].getId().getName().equals(artifactsNames[i])) {
097: found = true;
098: break;
099: }
100: }
101: assertTrue("dependency include not found: "
102: + artifactsNames[i], found);
103: }
104: }
105:
106: protected void assertDependencyArtifactExcludeRules(
107: DependencyDescriptor dd, String[] confs,
108: String[] artifactsNames) {
109: ExcludeRule[] rules = dd.getExcludeRules(confs);
110: assertNotNull(rules);
111: assertEquals(artifactsNames.length, rules.length);
112: for (int i = 0; i < artifactsNames.length; i++) {
113: boolean found = false;
114: for (int j = 0; j < rules.length; j++) {
115: assertNotNull(rules[j]);
116: if (rules[j].getId().getName()
117: .equals(artifactsNames[i])) {
118: found = true;
119: break;
120: }
121: }
122: assertTrue("dependency exclude not found: "
123: + artifactsNames[i], found);
124: }
125: }
126:
127: protected void assertDependencyModulesExcludes(
128: DependencyDescriptor dd, String[] confs,
129: String[] moduleNames) {
130: ExcludeRule[] rules = dd.getExcludeRules(confs);
131: assertNotNull(rules);
132: assertEquals(moduleNames.length, rules.length);
133: for (int i = 0; i < moduleNames.length; i++) {
134: boolean found = false;
135: for (int j = 0; j < rules.length; j++) {
136: assertNotNull(rules[j]);
137: if (rules[j].getId().getModuleId().getName().equals(
138: moduleNames[i])) {
139: found = true;
140: break;
141: }
142: }
143: assertTrue("dependency module exclude not found: "
144: + moduleNames[i], found);
145: }
146: }
147:
148: protected void assertConf(ModuleDescriptor md, String name,
149: String desc, Visibility visibility, String[] exts) {
150: Configuration conf = md.getConfiguration(name);
151: assertNotNull("configuration not found: " + name, conf);
152: assertEquals(name, conf.getName());
153: assertEquals(desc, conf.getDescription());
154: assertEquals(visibility, conf.getVisibility());
155: assertEquals(Arrays.asList(exts), Arrays.asList(conf
156: .getExtends()));
157: }
158:
159: }
|