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.report;
19:
20: import java.io.File;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.ivy.Ivy;
25: import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
26: import org.apache.ivy.core.module.id.ModuleRevisionId;
27: import org.apache.ivy.core.report.ResolveReport;
28: import org.apache.ivy.core.resolve.ResolveOptions;
29: import org.apache.tools.ant.Project;
30: import org.apache.tools.ant.taskdefs.Delete;
31:
32: public class XmlReportParserTest extends TestCase {
33: private Ivy _ivy;
34:
35: private File _cache;
36:
37: protected void setUp() throws Exception {
38: _ivy = new Ivy();
39: _ivy.configure(new File("test/repositories/ivysettings.xml"));
40: createCache();
41: }
42:
43: private void createCache() {
44: _cache = new File("build/cache");
45: _cache.mkdirs();
46: }
47:
48: protected void tearDown() throws Exception {
49: cleanCache();
50: }
51:
52: private void cleanCache() {
53: Delete del = new Delete();
54: del.setProject(new Project());
55: del.setDir(_cache);
56: del.execute();
57: }
58:
59: public void testGetResolvedModule() throws Exception {
60: ResolveReport report = _ivy
61: .resolve(
62: new File(
63: "test/java/org/apache/ivy/plugins/report/ivy-with-info.xml")
64: .toURL(), getResolveOptions(
65: new String[] { "default" })
66: .setValidate(false).setResolveId(
67: "testGetResolvedModule"));
68: assertNotNull(report);
69:
70: ModuleRevisionId modRevId = report.getModuleDescriptor()
71: .getModuleRevisionId();
72:
73: XmlReportParser parser = new XmlReportParser();
74: parser.parse(_ivy.getResolutionCacheManager()
75: .getConfigurationResolveReportInCache(
76: "testGetResolvedModule", "default"));
77: ModuleRevisionId parsedModRevId = parser.getResolvedModule();
78:
79: assertEquals("Resolved module doesn't equals parsed module",
80: modRevId, parsedModRevId);
81: }
82:
83: private ResolveOptions getResolveOptions(String[] confs) {
84: return new ResolveOptions().setConfs(confs);
85: }
86: }
|