01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.resolver;
19:
20: import java.io.File;
21: import java.net.MalformedURLException;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.ivy.core.event.EventManager;
26: import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
27: import org.apache.ivy.core.module.id.ModuleRevisionId;
28: import org.apache.ivy.core.resolve.ResolveData;
29: import org.apache.ivy.core.resolve.ResolveEngine;
30: import org.apache.ivy.core.resolve.ResolveOptions;
31: import org.apache.ivy.core.resolve.ResolvedModuleRevision;
32: import org.apache.ivy.core.settings.IvySettings;
33: import org.apache.ivy.core.sort.SortEngine;
34: import org.apache.ivy.util.CacheCleaner;
35:
36: public class Maven2LocalTest extends TestCase {
37: private IvySettings settings;
38:
39: private ResolveEngine engine;
40:
41: private ResolveData data;
42:
43: private File cache;
44:
45: protected void setUp() throws Exception {
46: settings = new IvySettings();
47: engine = new ResolveEngine(settings, new EventManager(),
48: new SortEngine(settings));
49: cache = new File("build/cache");
50: data = new ResolveData(engine, new ResolveOptions());
51: cache.mkdirs();
52: settings.setDefaultCache(cache);
53: }
54:
55: protected void tearDown() throws Exception {
56: CacheCleaner.deleteDir(cache);
57: }
58:
59: public void testUseMetadataForListing() throws Exception {
60: IBiblioResolver resolver = maven2Resolver();
61:
62: ResolvedModuleRevision m = resolver.getDependency(
63: new DefaultDependencyDescriptor(ModuleRevisionId
64: .newInstance("org.apache", "test-metadata",
65: "latest.integration"), false), data);
66:
67: assertNotNull(m);
68: // should trust the metadata (latest=1.1) instead of listing revisions (latest=1.2)
69: assertEquals(ModuleRevisionId.newInstance("org.apache",
70: "test-metadata", "1.1"), m.getId());
71: }
72:
73: public void testNotUseMetadataForListing() throws Exception {
74: IBiblioResolver resolver = maven2Resolver();
75: resolver.setUseMavenMetadata(false);
76:
77: ResolvedModuleRevision m = resolver.getDependency(
78: new DefaultDependencyDescriptor(ModuleRevisionId
79: .newInstance("org.apache", "test-metadata",
80: "latest.integration"), false), data);
81:
82: assertNotNull(m);
83: // should trust listing revisions (latest=1.2) instead of the metadata (latest=1.1)
84: assertEquals(ModuleRevisionId.newInstance("org.apache",
85: "test-metadata", "1.2"), m.getId());
86: }
87:
88: private IBiblioResolver maven2Resolver()
89: throws MalformedURLException {
90: IBiblioResolver resolver = new IBiblioResolver();
91: resolver.setSettings(settings);
92: resolver.setName("maven2");
93: resolver.setM2compatible(true);
94: resolver.setRoot(new File("test/repositories/m2").toURL()
95: .toExternalForm());
96: return resolver;
97: }
98: }
|