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.conflict;
019:
020: import java.io.IOException;
021: import java.text.ParseException;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.ivy.Ivy;
026: import org.apache.ivy.TestFixture;
027: import org.apache.ivy.TestHelper;
028: import org.apache.ivy.core.report.ConfigurationResolveReport;
029: import org.apache.ivy.core.report.ResolveReport;
030:
031: public class LatestCompatibleConflictManagerTest extends TestCase {
032: private TestFixture fixture;
033:
034: protected void setUp() throws Exception {
035: fixture = new TestFixture();
036: LatestCompatibleConflictManager cm = new LatestCompatibleConflictManager();
037: fixture.getSettings().addConfigured(cm);
038: fixture.getSettings().setDefaultConflictManager(cm);
039: }
040:
041: protected void tearDown() throws Exception {
042: fixture.clean();
043: }
044:
045: public void testInitFromSettings() throws Exception {
046: Ivy ivy = new Ivy();
047: ivy.configure(LatestCompatibleConflictManagerTest.class
048: .getResource("ivysettings-latest-compatible.xml"));
049: ConflictManager cm = ivy.getSettings()
050: .getDefaultConflictManager();
051: assertTrue(cm instanceof LatestCompatibleConflictManager);
052: }
053:
054: public void testCompatibilityResolve1() throws Exception {
055: fixture.addMD("#A;1-> { #B;1.4 #C;[2.0,2.5] }").addMD(
056: "#B;1.4->#D;1.5").addMD("#C;2.5->#D;[1.0,1.6]").addMD(
057: "#D;1.5").addMD("#D;1.6").init();
058: resolveAndAssert("#A;1", "#B;1.4, #C;2.5, #D;1.5");
059: }
060:
061: public void testCompatibilityResolve2() throws Exception {
062: fixture.addMD("#A;2-> { #B;[1.0,1.5] #C;[2.0,2.5] }").addMD(
063: "#B;1.4->#D;1.5").addMD("#B;1.5->#D;2.0").addMD(
064: "#C;2.5->#D;[1.0,1.6]").addMD("#D;1.5").addMD("#D;1.6")
065: .addMD("#D;2.0").init();
066: resolveAndAssert("#A;2", "#B;1.4, #C;2.5, #D;1.5");
067: }
068:
069: public void testCompatibilityResolve3() throws Exception {
070: fixture.addMD("#A;3-> { #B;[2.0,2.5] #C;[3.0,3.5] }").addMD(
071: "#B;2.3-> { #D;1.5 #E;1.0 }").addMD(
072: "#B;2.4-> { #D;1.5 #E;2.0 }").addMD(
073: "#B;2.5-> { #D;2.0 }").addMD("#B;2.5-> { #D;2.0 }")
074: .addMD("#C;3.4-> { #D;[1.0,1.6] #E;1.0 }").addMD(
075: "#C;3.5-> { #D;[1.0,1.6] #E;1.9 }").addMD(
076: "#D;1.5").addMD("#D;1.6").addMD("#D;2.0")
077: .addMD("#E;1.0").addMD("#E;1.9").addMD("#E;2.0").init();
078: resolveAndAssert("#A;3", "#B;2.3, #C;3.4, #D;1.5, #E;1.0");
079: }
080:
081: public void testCompatibilityResolve4() throws Exception {
082: fixture.addMD(
083: "#A;4-> { #B;[1.0,1.5] #C;[2.0,2.5] #F;[1.0,1.1] }")
084: .addMD("#B;1.4->#D;1.5").addMD("#B;1.5->#D;2.0").addMD(
085: "#C;2.5->#D;[1.0,1.6]").addMD("#F;1.0->#D;1.5")
086: .addMD("#F;1.1->#D;1.6").addMD("#D;1.5")
087: .addMD("#D;1.6").addMD("#D;2.0").init();
088: resolveAndAssert("#A;4", "#B;1.4, #C;2.5, #D;1.5, #F;1.0");
089: }
090:
091: public void testCompatibilityResolve5() throws Exception {
092: fixture.addMD("#A;5->{ #B;[1.0,1.5] #C;2.6 }").addMD(
093: "#B;1.3->{ }").addMD("#B;1.4->#D;1.5").addMD(
094: "#B;1.5->#D;2.0").addMD("#C;2.6->#D;1.6").addMD(
095: "#D;1.5").addMD("#D;1.6").addMD("#D;2.0").init();
096: resolveAndAssert("#A;5", "#B;1.3, #C;2.6, #D;1.6");
097: }
098:
099: public void testCompatibilityResolve6() throws Exception {
100: fixture.addMD("#A;1-> { #C;[2.0,2.5] #B;1.4 }").addMD(
101: "#B;1.4->#D;1.5").addMD("#C;2.5->#D;[1.0,1.6]").addMD(
102: "#D;1.5").addMD("#D;1.6").init();
103: resolveAndAssert("#A;1", "#B;1.4, #C;2.5, #D;1.5");
104: }
105:
106: public void testCompatibilityResolveCircularDependency1()
107: throws Exception {
108: fixture.addMD("#A;6->{ #B;[3.0,3.5] #C;4.6 }").addMD(
109: "#B;3.4->#D;2.5").addMD("#B;3.5->#D;3.0").addMD(
110: "#C;4.6->#D;2.5").addMD("#D;3.0->#B;3.5") // circular dependency
111: .addMD("#D;2.5->#B;3.4") // circular dependency
112: .addMD("#D;2.5").addMD("#D;3.0").init();
113: resolveAndAssert("#A;6", "#B;3.4, #C;4.6, #D;2.5");
114: }
115:
116: public void testCompatibilityResolveCircularDependency2()
117: throws Exception {
118: fixture.addMD("#A;1->#C;2").addMD("#C;1->#B;1").addMD(
119: "#C;2->#B;2").addMD("#C;3->#B;3").addMD(
120: "#B;1->#C;latest.integration") // circular dependency
121: .addMD("#B;2->#C;latest.integration") // circular dependency
122: .addMD("#B;3->#C;latest.integration") // circular dependency
123: .init();
124: resolveAndAssert("#A;1", "#B;2, #C;2");
125: }
126:
127: public void testCompatibilityResolveCircularDependency3()
128: throws Exception {
129: // same as 2, but A depends on B
130: fixture.addMD("#A;1->#B;2").addMD("#C;1->#B;1").addMD(
131: "#C;2->#B;2").addMD("#C;3->#B;3").addMD(
132: "#B;1->#C;latest.integration") // circular dependency
133: .addMD("#B;2->#C;latest.integration") // circular dependency
134: .addMD("#B;3->#C;latest.integration") // circular dependency
135: .init();
136: resolveAndAssert("#A;1", "#B;2, #C;2");
137: }
138:
139: public void testConflict() throws Exception {
140: try {
141: fixture.addMD("#A;conflict-> { #B;[1.5,1.6] #C;2.5 }")
142: .addMD("#B;1.5->#D;2.0").addMD("#B;1.6->#D;2.0")
143: .addMD("#C;2.5->#D;[1.0,1.6]").addMD("#D;1.5")
144: .addMD("#D;1.6").addMD("#D;2.0").init();
145: fixture.resolve("#A;conflict");
146:
147: fail("Resolve should have failed with a conflict");
148: } catch (StrictConflictException e) {
149: // this is expected
150: }
151: }
152:
153: private void resolveAndAssert(String mrid, String expectedModuleSet)
154: throws ParseException, IOException {
155: ResolveReport report = fixture.resolve(mrid);
156: assertFalse(report.hasError());
157: ConfigurationResolveReport defaultReport = report
158: .getConfigurationReport("default");
159: TestHelper.assertModuleRevisionIds(expectedModuleSet,
160: defaultReport.getModuleRevisionIds());
161: }
162: }
|