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.resolver;
019:
020: import java.util.Arrays;
021:
022: import junit.framework.Assert;
023:
024: import org.apache.ivy.core.search.ModuleEntry;
025: import org.apache.ivy.core.search.OrganisationEntry;
026: import org.apache.ivy.core.search.RevisionEntry;
027:
028: /**
029: *
030: */
031: public class ResolverTestHelper {
032: static void assertOrganisationEntries(DependencyResolver resolver,
033: String[] orgNames, OrganisationEntry[] orgs) {
034: Assert.assertNotNull(orgs);
035: Assert.assertEquals(
036: "invalid organisation entries: unmatched number: expected: "
037: + Arrays.asList(orgNames) + " but was "
038: + Arrays.asList(orgs), orgNames.length,
039: orgs.length);
040: assertOrganisationEntriesContains(resolver, orgNames, orgs);
041: }
042:
043: static void assertOrganisationEntriesContains(
044: DependencyResolver resolver, String[] orgNames,
045: OrganisationEntry[] orgs) {
046: Assert.assertNotNull(orgs);
047: for (int i = 0; i < orgNames.length; i++) {
048: boolean found = false;
049: for (int j = 0; j < orgs.length; j++) {
050: if (orgNames[i].equals(orgs[j].getOrganisation())) {
051: found = true;
052: Assert
053: .assertEquals(resolver, orgs[j]
054: .getResolver());
055: }
056: }
057: Assert.assertTrue("organisation not found: " + orgNames[i],
058: found);
059: }
060: }
061:
062: static void assertModuleEntries(DependencyResolver resolver,
063: OrganisationEntry org, String[] names, ModuleEntry[] mods) {
064: Assert.assertNotNull(mods);
065: Assert.assertEquals(
066: "invalid module entries: unmatched number: expected: "
067: + Arrays.asList(names) + " but was "
068: + Arrays.asList(mods), names.length,
069: mods.length);
070: assertModuleEntriesContains(resolver, org, names, mods);
071: }
072:
073: static void assertModuleEntriesContains(
074: DependencyResolver resolver, OrganisationEntry org,
075: String[] names, ModuleEntry[] mods) {
076: Assert.assertNotNull(mods);
077: for (int i = 0; i < names.length; i++) {
078: boolean found = false;
079: for (int j = 0; j < mods.length; j++) {
080: if (names[i].equals(mods[j].getModule())) {
081: found = true;
082: Assert
083: .assertEquals(resolver, mods[j]
084: .getResolver());
085: Assert.assertEquals(org, mods[j]
086: .getOrganisationEntry());
087: }
088: }
089: Assert.assertTrue("module not found: " + names[i], found);
090: }
091: }
092:
093: static void assertRevisionEntries(DependencyResolver resolver,
094: ModuleEntry mod, String[] names, RevisionEntry[] revs) {
095: Assert.assertNotNull(revs);
096: Assert.assertEquals(
097: "invalid revision entries: unmatched number: expected: "
098: + Arrays.asList(names) + " but was "
099: + Arrays.asList(revs), names.length,
100: revs.length);
101: assertRevisionEntriesContains(resolver, mod, names, revs);
102: }
103:
104: static void assertRevisionEntriesContains(
105: DependencyResolver resolver, ModuleEntry mod,
106: String[] names, RevisionEntry[] revs) {
107: Assert.assertNotNull(revs);
108: for (int i = 0; i < names.length; i++) {
109: boolean found = false;
110: for (int j = 0; j < revs.length; j++) {
111: if (names[i].equals(revs[j].getRevision())) {
112: found = true;
113: Assert
114: .assertEquals(resolver, revs[j]
115: .getResolver());
116: Assert.assertEquals(mod, revs[j].getModuleEntry());
117: }
118: }
119: Assert.assertTrue("revision not found: " + names[i], found);
120: }
121: }
122:
123: static OrganisationEntry getEntry(OrganisationEntry[] orgs,
124: String name) {
125: for (int i = 0; i < orgs.length; i++) {
126: if (name.equals(orgs[i].getOrganisation())) {
127: return orgs[i];
128: }
129: }
130: Assert.fail("organisation not found: " + name);
131: return null; // for compilation only
132: }
133:
134: static ModuleEntry getEntry(ModuleEntry[] mods, String name) {
135: for (int i = 0; i < mods.length; i++) {
136: if (name.equals(mods[i].getModule())) {
137: return mods[i];
138: }
139: }
140: Assert.fail("module not found: " + name);
141: return null; // for compilation only
142: }
143:
144: }
|