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.File;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import junit.framework.TestCase;
025:
026: import org.apache.ivy.Ivy;
027: import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
028: import org.apache.ivy.core.module.id.ModuleRevisionId;
029: import org.apache.ivy.core.report.ConfigurationResolveReport;
030: import org.apache.ivy.core.report.ResolveReport;
031: import org.apache.ivy.core.resolve.IvyNode;
032: import org.apache.ivy.core.resolve.ResolveOptions;
033: import org.apache.ivy.util.FileUtil;
034:
035: public class LatestConflictManagerTest extends TestCase {
036:
037: private Ivy ivy;
038:
039: private File _cache;
040:
041: protected void setUp() throws Exception {
042: ivy = new Ivy();
043: ivy.configure(LatestConflictManagerTest.class
044: .getResource("ivysettings-latest.xml"));
045: _cache = new File("build/cache");
046: _cache.mkdirs();
047: }
048:
049: protected void tearDown() throws Exception {
050: FileUtil.forceDelete(_cache);
051: }
052:
053: // Test case for issue IVY-388
054: public void testIvy388() throws Exception {
055: ResolveReport report = ivy.resolve(
056: LatestConflictManagerTest.class
057: .getResource("ivy-388.xml"),
058: getResolveOptions());
059:
060: List deps = report.getDependencies();
061: Iterator dependencies = deps.iterator();
062: String[] confs = report.getConfigurations();
063: while (dependencies.hasNext()) {
064: IvyNode node = (IvyNode) dependencies.next();
065: for (int i = 0; i < confs.length; i++) {
066: String conf = confs[i];
067: if (!node.isEvicted(conf)) {
068: boolean flag1 = report.getConfigurationReport(conf)
069: .getDependency(node.getResolvedId()) != null;
070: boolean flag2 = report.getConfigurationReport(conf)
071: .getModuleRevisionIds().contains(
072: node.getResolvedId());
073: assertEquals("Inconsistent data for node " + node
074: + " in conf " + conf, flag1, flag2);
075: }
076: }
077: }
078: }
079:
080: // Test case for issue IVY-383
081: public void testIvy383() throws Exception {
082: ResolveReport report = ivy.resolve(
083: LatestConflictManagerTest.class
084: .getResource("ivy-383.xml"),
085: getResolveOptions());
086: ConfigurationResolveReport defaultReport = report
087: .getConfigurationReport("default");
088: Iterator iter = defaultReport.getModuleRevisionIds().iterator();
089: while (iter.hasNext()) {
090: ModuleRevisionId mrid = (ModuleRevisionId) iter.next();
091: if (mrid.getName().equals("mod1.1")) {
092: assertEquals("1.0", mrid.getRevision());
093: } else if (mrid.getName().equals("mod1.2")) {
094: assertEquals("2.2", mrid.getRevision());
095: }
096: }
097: }
098:
099: // Test case for issue IVY-407
100: public void testLatestTime1() throws Exception {
101: ivy = new Ivy();
102: ivy.configure(LatestConflictManagerTest.class
103: .getResource("ivysettings-latest-time.xml"));
104: ivy.getSettings().setVariable("ivy.log.conflict.resolution",
105: "true", true);
106:
107: // set timestamps, because svn is not preserving this information,
108: // and the latest time strategy is relying on it
109: long time = System.currentTimeMillis() - 10000;
110: new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar")
111: .setLastModified(time);
112: new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar")
113: .setLastModified(time + 2000);
114:
115: ResolveReport report = ivy.resolve(
116: LatestConflictManagerTest.class
117: .getResource("ivy-latest-time-1.xml"),
118: getResolveOptions());
119: ConfigurationResolveReport defaultReport = report
120: .getConfigurationReport("default");
121: Iterator iter = defaultReport.getModuleRevisionIds().iterator();
122: while (iter.hasNext()) {
123: ModuleRevisionId mrid = (ModuleRevisionId) iter.next();
124: if (mrid.getName().equals("mod1.1")) {
125: assertEquals("1.0", mrid.getRevision());
126: } else if (mrid.getName().equals("mod1.2")) {
127: assertEquals("2.2", mrid.getRevision());
128: }
129: }
130: }
131:
132: public void testLatestTime2() throws Exception {
133: ivy = new Ivy();
134: ivy.configure(LatestConflictManagerTest.class
135: .getResource("ivysettings-latest-time.xml"));
136: ivy.getSettings().setVariable("ivy.log.conflict.resolution",
137: "true", true);
138:
139: // set timestamps, because svn is not preserving this information,
140: // and the latest time strategy is relying on it
141: long time = System.currentTimeMillis() - 10000;
142: new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar")
143: .setLastModified(time);
144: new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar")
145: .setLastModified(time + 2000);
146:
147: ResolveReport report = ivy.resolve(
148: LatestConflictManagerTest.class
149: .getResource("ivy-latest-time-2.xml"),
150: getResolveOptions());
151: ConfigurationResolveReport defaultReport = report
152: .getConfigurationReport("default");
153: Iterator iter = defaultReport.getModuleRevisionIds().iterator();
154: while (iter.hasNext()) {
155: ModuleRevisionId mrid = (ModuleRevisionId) iter.next();
156: if (mrid.getName().equals("mod1.1")) {
157: assertEquals("1.0", mrid.getRevision());
158: } else if (mrid.getName().equals("mod1.2")) {
159: assertEquals("2.2", mrid.getRevision());
160: }
161: }
162: }
163:
164: /*
165: * Test case for issue IVY-407 (with transitivity) There are 5 modules A, B, C, D and E. 1)
166: * publish C-1.0.0, C-1.0.1 and C-1.0.2 2) B needs C-1.0.0 : retrieve ok and publish B-1.0.0 3)
167: * A needs B-1.0.0 and C-1.0.2 : retrieve ok and publish A-1.0.0 4) D needs C-1.0.1 : retrieve
168: * ok and publish D-1.0.0 5) E needs D-1.0.0 and A-1.0.0 (D before A in ivy file) retrieve
169: * failed to get C-1.0.2 from A (get apparently C-1.0.1 from D)
170: */
171: public void testLatestTimeTransitivity() throws Exception {
172: ivy = new Ivy();
173: ivy
174: .configure(LatestConflictManagerTest.class
175: .getResource("ivysettings-latest-time-transitivity.xml"));
176: ivy.getSettings().setVariable("ivy.log.conflict.resolution",
177: "true", true);
178:
179: // set timestamps, because svn is not preserving this information,
180: // and the latest time strategy is relying on it
181: long time = System.currentTimeMillis() - 10000;
182: new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml")
183: .setLastModified(time);
184: new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml")
185: .setLastModified(time + 2000);
186: new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml")
187: .setLastModified(time + 4000);
188:
189: ResolveReport report = ivy
190: .resolve(
191: LatestConflictManagerTest.class
192: .getResource("ivy-latest-time-transitivity.xml"),
193: getResolveOptions());
194: ConfigurationResolveReport defaultReport = report
195: .getConfigurationReport("default");
196: Iterator iter = defaultReport.getModuleRevisionIds().iterator();
197: while (iter.hasNext()) {
198: ModuleRevisionId mrid = (ModuleRevisionId) iter.next();
199:
200: if (mrid.getName().equals("A")) {
201: assertEquals("A revision should be 1.0.0", "1.0.0",
202: mrid.getRevision());
203: } else if (mrid.getName().equals("D")) {
204: assertEquals("D revision should be 1.0.0", "1.0.0",
205: mrid.getRevision());
206: }
207: // by transitivity
208: else if (mrid.getName().equals("B")) {
209: assertEquals("B revision should be 1.0.0", "1.0.0",
210: mrid.getRevision());
211: } else if (mrid.getName().equals("C")) {
212: assertEquals("C revision should be 1.0.2", "1.0.2",
213: mrid.getRevision());
214: }
215: }
216: }
217:
218: private ResolveOptions getResolveOptions() {
219: return new ResolveOptions().setValidate(false);
220: }
221: }
|