0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: *
0017: */
0018: package org.apache.ivy.plugins.parser.xml;
0019:
0020: import java.io.File;
0021: import java.io.IOException;
0022: import java.text.ParseException;
0023: import java.util.Arrays;
0024: import java.util.Collections;
0025: import java.util.Date;
0026: import java.util.GregorianCalendar;
0027: import java.util.HashSet;
0028:
0029: import org.apache.ivy.Ivy;
0030: import org.apache.ivy.core.module.descriptor.Artifact;
0031: import org.apache.ivy.core.module.descriptor.Configuration;
0032: import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
0033: import org.apache.ivy.core.module.descriptor.ExcludeRule;
0034: import org.apache.ivy.core.module.descriptor.License;
0035: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
0036: import org.apache.ivy.core.module.descriptor.Configuration.Visibility;
0037: import org.apache.ivy.core.module.id.ModuleId;
0038: import org.apache.ivy.core.module.id.ModuleRevisionId;
0039: import org.apache.ivy.core.settings.IvySettings;
0040: import org.apache.ivy.plugins.conflict.ConflictManager;
0041: import org.apache.ivy.plugins.conflict.FixedConflictManager;
0042: import org.apache.ivy.plugins.conflict.NoConflictManager;
0043: import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
0044: import org.apache.ivy.plugins.matcher.GlobPatternMatcher;
0045: import org.apache.ivy.plugins.matcher.PatternMatcher;
0046: import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester;
0047: import org.apache.ivy.util.XMLHelper;
0048:
0049: public class XmlModuleDescriptorParserTest extends
0050: AbstractModuleDescriptorParserTester {
0051: private IvySettings settings = null;
0052:
0053: protected void setUp() throws Exception {
0054: super .setUp();
0055:
0056: this .settings = new IvySettings();
0057: }
0058:
0059: public void testSimple() throws Exception {
0060: ModuleDescriptor md = XmlModuleDescriptorParser
0061: .getInstance()
0062: .parseDescriptor(settings,
0063: getClass().getResource("test-simple.xml"), true);
0064: assertNotNull(md);
0065: assertEquals("myorg", md.getModuleRevisionId()
0066: .getOrganisation());
0067: assertEquals("mymodule", md.getModuleRevisionId().getName());
0068: assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId()
0069: .getRevision());
0070: assertEquals("integration", md.getStatus());
0071:
0072: assertNotNull(md.getConfigurations());
0073: assertEquals(Arrays
0074: .asList(new Configuration[] { new Configuration(
0075: "default") }), Arrays.asList(md
0076: .getConfigurations()));
0077:
0078: assertNotNull(md.getArtifacts("default"));
0079: assertEquals(1, md.getArtifacts("default").length);
0080: assertEquals("mymodule", md.getArtifacts("default")[0]
0081: .getName());
0082: assertEquals("jar", md.getArtifacts("default")[0].getType());
0083:
0084: assertNotNull(md.getDependencies());
0085: assertEquals(0, md.getDependencies().length);
0086: }
0087:
0088: public void testNamespaces() throws Exception {
0089: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0090: .parseDescriptor(settings,
0091: getClass().getResource("test-namespaces.xml"),
0092: true);
0093: assertNotNull(md);
0094: ModuleRevisionId mrid = md.getModuleRevisionId();
0095: assertEquals("myorg", mrid.getOrganisation());
0096: assertEquals("mymodule", mrid.getName());
0097: assertEquals("myval", mrid.getExtraAttribute("e:myextra"));
0098: assertEquals(Collections.singletonMap("e:myextra", "myval"),
0099: mrid.getQualifiedExtraAttributes());
0100: assertEquals("myval", mrid.getExtraAttribute("myextra"));
0101: assertEquals(Collections.singletonMap("myextra", "myval"), mrid
0102: .getExtraAttributes());
0103: assertEquals("http://ant.apache.org/ivy/extra", md
0104: .getExtraAttributesNamespaces().get("e"));
0105: }
0106:
0107: public void testEmptyDependencies() throws Exception {
0108: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0109: .parseDescriptor(
0110: settings,
0111: getClass().getResource(
0112: "test-empty-dependencies.xml"), true);
0113: assertNotNull(md);
0114: assertEquals("myorg", md.getModuleRevisionId()
0115: .getOrganisation());
0116: assertEquals("mymodule", md.getModuleRevisionId().getName());
0117: assertEquals("myrev", md.getModuleRevisionId().getRevision());
0118: assertEquals("integration", md.getStatus());
0119:
0120: assertNotNull(md.getConfigurations());
0121: assertEquals(Arrays
0122: .asList(new Configuration[] { new Configuration(
0123: "default") }), Arrays.asList(md
0124: .getConfigurations()));
0125:
0126: assertNotNull(md.getArtifacts("default"));
0127: assertEquals(1, md.getArtifacts("default").length);
0128: assertEquals("mymodule", md.getArtifacts("default")[0]
0129: .getName());
0130: assertEquals("jar", md.getArtifacts("default")[0].getType());
0131:
0132: assertNotNull(md.getDependencies());
0133: assertEquals(0, md.getDependencies().length);
0134: }
0135:
0136: public void testBad() throws IOException {
0137: try {
0138: XmlModuleDescriptorParser.getInstance().parseDescriptor(
0139: settings, getClass().getResource("test-bad.xml"),
0140: true);
0141: fail("bad ivy file raised no error");
0142: } catch (ParseException ex) {
0143: if (XMLHelper.canUseSchemaValidation()) {
0144: assertTrue(
0145: "exception message not explicit. It should contain 'modul', but it's:"
0146: + ex.getMessage(), ex.getMessage()
0147: .indexOf("'modul'") != -1);
0148: }
0149: }
0150: }
0151:
0152: public void testBadOrg() throws IOException {
0153: try {
0154: XmlModuleDescriptorParser.getInstance().parseDescriptor(
0155: settings,
0156: getClass().getResource("test-bad-org.xml"), true);
0157: if (XMLHelper.canUseSchemaValidation()) {
0158: fail("bad ivy file raised no error");
0159: }
0160: } catch (ParseException ex) {
0161: if (XMLHelper.canUseSchemaValidation()) {
0162: assertTrue("invalid exception: " + ex.getMessage(), ex
0163: .getMessage().indexOf("organization") != -1);
0164: }
0165: }
0166: }
0167:
0168: public void testBadConfs() throws IOException {
0169: try {
0170: XmlModuleDescriptorParser.getInstance().parseDescriptor(
0171: settings,
0172: getClass().getResource("test-bad-confs.xml"), true);
0173: fail("bad ivy file raised no error");
0174: } catch (ParseException ex) {
0175: assertTrue("invalid exception: " + ex.getMessage(), ex
0176: .getMessage().indexOf("invalidConf") != -1);
0177: }
0178: }
0179:
0180: public void testNoValidate() throws IOException, ParseException {
0181: XmlModuleDescriptorParser.getInstance().parseDescriptor(
0182: settings,
0183: getClass().getResource("test-novalidate.xml"), false);
0184: }
0185:
0186: public void testBadVersion() throws IOException {
0187: try {
0188: XmlModuleDescriptorParser.getInstance().parseDescriptor(
0189: settings,
0190: getClass().getResource("test-bad-version.xml"),
0191: true);
0192: fail("bad version ivy file raised no error");
0193: } catch (ParseException ex) {
0194: // ok
0195: }
0196: }
0197:
0198: public void testFull() throws Exception {
0199: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0200: .parseDescriptor(settings,
0201: getClass().getResource("test.xml"), true);
0202: assertNotNull(md);
0203: assertEquals("myorg", md.getModuleRevisionId()
0204: .getOrganisation());
0205: assertEquals("mymodule", md.getModuleRevisionId().getName());
0206: assertEquals("myrev", md.getModuleRevisionId().getRevision());
0207: assertEquals("integration", md.getStatus());
0208: Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
0209: .getTime();
0210: assertEquals(pubdate, md.getPublicationDate());
0211:
0212: License[] licenses = md.getLicenses();
0213: assertEquals(1, licenses.length);
0214: assertEquals("MyLicense", licenses[0].getName());
0215: assertEquals("http://www.my.org/mymodule/mylicense.html",
0216: licenses[0].getUrl());
0217:
0218: assertEquals("http://www.my.org/mymodule/", md.getHomePage());
0219:
0220: Configuration[] confs = md.getConfigurations();
0221: assertNotNull(confs);
0222: assertEquals(5, confs.length);
0223:
0224: assertConf(md, "myconf1", "desc 1",
0225: Configuration.Visibility.PUBLIC, new String[0]);
0226: assertConf(md, "myconf2", "desc 2",
0227: Configuration.Visibility.PUBLIC, new String[0]);
0228: assertConf(md, "myconf3", "desc 3",
0229: Configuration.Visibility.PRIVATE, new String[0]);
0230: assertConf(md, "myconf4", "desc 4",
0231: Configuration.Visibility.PUBLIC, new String[] {
0232: "myconf1", "myconf2" });
0233: assertConf(md, "myoldconf", "my old desc",
0234: Configuration.Visibility.PUBLIC, new String[0]);
0235:
0236: assertArtifacts(md.getArtifacts("myconf1"), new String[] {
0237: "myartifact1", "myartifact2", "myartifact3",
0238: "myartifact4" });
0239: assertArtifacts(md.getArtifacts("myconf2"), new String[] {
0240: "myartifact1", "myartifact3" });
0241: assertArtifacts(md.getArtifacts("myconf3"), new String[] {
0242: "myartifact1", "myartifact3", "myartifact4" });
0243: assertArtifacts(md.getArtifacts("myconf4"),
0244: new String[] { "myartifact1" });
0245:
0246: DependencyDescriptor[] dependencies = md.getDependencies();
0247: assertNotNull(dependencies);
0248: assertEquals(13, dependencies.length);
0249:
0250: // no conf def => equivalent to *->*
0251: DependencyDescriptor dd = getDependency(dependencies,
0252: "mymodule2");
0253: assertNotNull(dd);
0254: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0255: assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
0256: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0257: .asList(dd.getModuleConfigurations()));
0258: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0259: .asList(dd.getDependencyConfigurations("myconf1")));
0260: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0261: .asList(dd.getDependencyConfigurations(new String[] {
0262: "myconf2", "myconf3", "myconf4" })));
0263: assertDependencyArtifactIncludeRules(dd, new String[] {
0264: "myconf1", "myconf2", "myconf3", "myconf4" },
0265: new String[0]);
0266: assertFalse(dd.isChanging());
0267: assertTrue(dd.isTransitive());
0268:
0269: // changing = true
0270: dd = getDependency(dependencies, "mymodule3");
0271: assertNotNull(dd);
0272: assertTrue(dd.isChanging());
0273: assertFalse(dd.isTransitive());
0274:
0275: // conf="myconf1" => equivalent to myconf1->myconf1
0276: dd = getDependency(dependencies, "yourmodule1");
0277: assertNotNull(dd);
0278: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0279: assertEquals("1.1", dd.getDependencyRevisionId().getRevision());
0280: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0281: .asList(dd.getModuleConfigurations()));
0282: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0283: .asList(dd.getDependencyConfigurations("myconf1")));
0284: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0285: .getDependencyConfigurations(new String[] { "myconf2",
0286: "myconf3", "myconf4" })));
0287: assertDependencyArtifactIncludeRules(dd, new String[] {
0288: "myconf1", "myconf2", "myconf3", "myconf4" },
0289: new String[0]);
0290:
0291: // conf="myconf1->yourconf1"
0292: dd = getDependency(dependencies, "yourmodule2");
0293: assertNotNull(dd);
0294: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0295: assertEquals("2+", dd.getDependencyRevisionId().getRevision());
0296: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0297: .asList(dd.getModuleConfigurations()));
0298: assertEquals(
0299: Arrays.asList(new String[] { "yourconf1" }),
0300: Arrays
0301: .asList(dd
0302: .getDependencyConfigurations("myconf1")));
0303: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0304: .getDependencyConfigurations(new String[] { "myconf2",
0305: "myconf3", "myconf4" })));
0306: assertDependencyArtifactIncludeRules(dd, new String[] {
0307: "myconf1", "myconf2", "myconf3", "myconf4" },
0308: new String[0]);
0309:
0310: // conf="myconf1->yourconf1, yourconf2"
0311: dd = getDependency(dependencies, "yourmodule3");
0312: assertNotNull(dd);
0313: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0314: assertEquals("3.1", dd.getDependencyRevisionId().getRevision());
0315: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0316: .asList(dd.getModuleConfigurations()));
0317: assertEquals(Arrays.asList(new String[] { "yourconf1",
0318: "yourconf2" }), Arrays.asList(dd
0319: .getDependencyConfigurations("myconf1")));
0320: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0321: .getDependencyConfigurations(new String[] { "myconf2",
0322: "myconf3", "myconf4" })));
0323: assertDependencyArtifactIncludeRules(dd, new String[] {
0324: "myconf1", "myconf2", "myconf3", "myconf4" },
0325: new String[0]);
0326:
0327: // conf="myconf1, myconf2->yourconf1, yourconf2"
0328: dd = getDependency(dependencies, "yourmodule4");
0329: assertNotNull(dd);
0330: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0331: assertEquals("4.1", dd.getDependencyRevisionId().getRevision());
0332: assertEquals(new HashSet(Arrays.asList(new String[] {
0333: "myconf1", "myconf2" })), new HashSet(Arrays.asList(dd
0334: .getModuleConfigurations())));
0335: assertEquals(Arrays.asList(new String[] { "yourconf1",
0336: "yourconf2" }), Arrays.asList(dd
0337: .getDependencyConfigurations("myconf1")));
0338: assertEquals(Arrays.asList(new String[] { "yourconf1",
0339: "yourconf2" }), Arrays.asList(dd
0340: .getDependencyConfigurations("myconf2")));
0341: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0342: .getDependencyConfigurations(new String[] { "myconf3",
0343: "myconf4" })));
0344: assertDependencyArtifactIncludeRules(dd, new String[] {
0345: "myconf1", "myconf2", "myconf3", "myconf4" },
0346: new String[0]);
0347:
0348: // conf="myconf1->yourconf1;myconf2->yourconf1, yourconf2"
0349: dd = getDependency(dependencies, "yourmodule5");
0350: assertNotNull(dd);
0351: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0352: assertEquals("5.1", dd.getDependencyRevisionId().getRevision());
0353: assertEquals(new HashSet(Arrays.asList(new String[] {
0354: "myconf1", "myconf2" })), new HashSet(Arrays.asList(dd
0355: .getModuleConfigurations())));
0356: assertEquals(
0357: Arrays.asList(new String[] { "yourconf1" }),
0358: Arrays
0359: .asList(dd
0360: .getDependencyConfigurations("myconf1")));
0361: assertEquals(Arrays.asList(new String[] { "yourconf1",
0362: "yourconf2" }), Arrays.asList(dd
0363: .getDependencyConfigurations("myconf2")));
0364: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0365: .getDependencyConfigurations(new String[] { "myconf3",
0366: "myconf4" })));
0367: assertDependencyArtifactIncludeRules(dd, new String[] {
0368: "myconf1", "myconf2", "myconf3", "myconf4" },
0369: new String[0]);
0370:
0371: // conf="*->@"
0372: dd = getDependency(dependencies, "yourmodule11");
0373: assertNotNull(dd);
0374: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0375: assertEquals("11.1", dd.getDependencyRevisionId().getRevision());
0376: assertEquals(
0377: new HashSet(Arrays.asList(new String[] { "*" })),
0378: new HashSet(Arrays.asList(dd.getModuleConfigurations())));
0379: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0380: .asList(dd.getDependencyConfigurations("myconf1")));
0381: assertEquals(Arrays.asList(new String[] { "myconf2" }), Arrays
0382: .asList(dd.getDependencyConfigurations("myconf2")));
0383: assertEquals(Arrays.asList(new String[] { "myconf3" }), Arrays
0384: .asList(dd.getDependencyConfigurations("myconf3")));
0385: assertEquals(Arrays.asList(new String[] { "myconf4" }), Arrays
0386: .asList(dd.getDependencyConfigurations("myconf4")));
0387:
0388: dd = getDependency(dependencies, "yourmodule6");
0389: assertNotNull(dd);
0390: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0391: assertEquals("latest.integration", dd.getDependencyRevisionId()
0392: .getRevision());
0393: assertEquals(new HashSet(Arrays.asList(new String[] {
0394: "myconf1", "myconf2" })), new HashSet(Arrays.asList(dd
0395: .getModuleConfigurations())));
0396: assertEquals(
0397: Arrays.asList(new String[] { "yourconf1" }),
0398: Arrays
0399: .asList(dd
0400: .getDependencyConfigurations("myconf1")));
0401: assertEquals(Arrays.asList(new String[] { "yourconf1",
0402: "yourconf2" }), Arrays.asList(dd
0403: .getDependencyConfigurations("myconf2")));
0404: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0405: .getDependencyConfigurations(new String[] { "myconf3",
0406: "myconf4" })));
0407: assertDependencyArtifactIncludeRules(dd, new String[] {
0408: "myconf1", "myconf2", "myconf3", "myconf4" },
0409: new String[0]);
0410:
0411: dd = getDependency(dependencies, "yourmodule7");
0412: assertNotNull(dd);
0413: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0414: assertEquals("7.1", dd.getDependencyRevisionId().getRevision());
0415: assertEquals(new HashSet(Arrays.asList(new String[] {
0416: "myconf1", "myconf2" })), new HashSet(Arrays.asList(dd
0417: .getModuleConfigurations())));
0418: assertEquals(
0419: Arrays.asList(new String[] { "yourconf1" }),
0420: Arrays
0421: .asList(dd
0422: .getDependencyConfigurations("myconf1")));
0423: assertEquals(Arrays.asList(new String[] { "yourconf1",
0424: "yourconf2" }), Arrays.asList(dd
0425: .getDependencyConfigurations("myconf2")));
0426: assertEquals(Arrays.asList(new String[] {}), Arrays.asList(dd
0427: .getDependencyConfigurations(new String[] { "myconf3",
0428: "myconf4" })));
0429: assertDependencyArtifactIncludeRules(dd, new String[] {
0430: "myconf1", "myconf2", "myconf3", "myconf4" },
0431: new String[0]);
0432:
0433: dd = getDependency(dependencies, "yourmodule8");
0434: assertNotNull(dd);
0435: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0436: assertEquals("8.1", dd.getDependencyRevisionId().getRevision());
0437: assertEquals(
0438: new HashSet(Arrays.asList(new String[] { "*" })),
0439: new HashSet(Arrays.asList(dd.getModuleConfigurations())));
0440: assertDependencyArtifacts(dd, new String[] { "myconf1" },
0441: new String[] { "yourartifact8-1", "yourartifact8-2" });
0442: assertDependencyArtifacts(dd, new String[] { "myconf2" },
0443: new String[] { "yourartifact8-1", "yourartifact8-2" });
0444: assertDependencyArtifacts(dd, new String[] { "myconf3" },
0445: new String[] { "yourartifact8-1", "yourartifact8-2" });
0446: assertDependencyArtifacts(dd, new String[] { "myconf4" },
0447: new String[] { "yourartifact8-1", "yourartifact8-2" });
0448:
0449: dd = getDependency(dependencies, "yourmodule9");
0450: assertNotNull(dd);
0451: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0452: assertEquals("9.1", dd.getDependencyRevisionId().getRevision());
0453: assertEquals(new HashSet(Arrays.asList(new String[] {
0454: "myconf1", "myconf2", "myconf3" })), new HashSet(Arrays
0455: .asList(dd.getModuleConfigurations())));
0456: assertDependencyArtifacts(dd, new String[] { "myconf1" },
0457: new String[] { "yourartifact9-1" });
0458: assertDependencyArtifacts(dd, new String[] { "myconf2" },
0459: new String[] { "yourartifact9-1", "yourartifact9-2" });
0460: assertDependencyArtifacts(dd, new String[] { "myconf3" },
0461: new String[] { "yourartifact9-2" });
0462: assertDependencyArtifacts(dd, new String[] { "myconf4" },
0463: new String[] {});
0464: assertDependencyArtifactExcludeRules(dd,
0465: new String[] { "myconf1" }, new String[] {});
0466: assertDependencyArtifactExcludeRules(dd,
0467: new String[] { "myconf2" }, new String[] {});
0468: assertDependencyArtifactExcludeRules(dd,
0469: new String[] { "myconf3" }, new String[] {});
0470: assertDependencyArtifactExcludeRules(dd,
0471: new String[] { "myconf4" }, new String[] {});
0472:
0473: dd = getDependency(dependencies, "yourmodule10");
0474: assertNotNull(dd);
0475: assertEquals("yourorg", dd.getDependencyId().getOrganisation());
0476: assertEquals("10.1", dd.getDependencyRevisionId().getRevision());
0477: assertEquals(
0478: new HashSet(Arrays.asList(new String[] { "*" })),
0479: new HashSet(Arrays.asList(dd.getModuleConfigurations())));
0480: assertDependencyArtifactIncludeRules(dd,
0481: new String[] { "myconf1" }, new String[] { "your.*",
0482: PatternMatcher.ANY_EXPRESSION });
0483: assertDependencyArtifactIncludeRules(dd,
0484: new String[] { "myconf2" }, new String[] { "your.*",
0485: PatternMatcher.ANY_EXPRESSION });
0486: assertDependencyArtifactIncludeRules(dd,
0487: new String[] { "myconf3" }, new String[] { "your.*",
0488: PatternMatcher.ANY_EXPRESSION });
0489: assertDependencyArtifactIncludeRules(dd,
0490: new String[] { "myconf4" }, new String[] { "your.*",
0491: PatternMatcher.ANY_EXPRESSION });
0492: assertDependencyArtifactExcludeRules(dd,
0493: new String[] { "myconf1" },
0494: new String[] { "toexclude" });
0495: assertDependencyArtifactExcludeRules(dd,
0496: new String[] { "myconf2" },
0497: new String[] { "toexclude" });
0498: assertDependencyArtifactExcludeRules(dd,
0499: new String[] { "myconf3" },
0500: new String[] { "toexclude" });
0501: assertDependencyArtifactExcludeRules(dd,
0502: new String[] { "myconf4" },
0503: new String[] { "toexclude" });
0504:
0505: ConflictManager cm = md.getConflictManager(new ModuleId(
0506: "yourorg", "yourmodule1"));
0507: assertNotNull(cm);
0508: assertTrue(cm instanceof NoConflictManager);
0509:
0510: cm = md.getConflictManager(new ModuleId("yourorg",
0511: "yourmodule2"));
0512: assertNotNull(cm);
0513: assertTrue(cm instanceof NoConflictManager);
0514:
0515: cm = md.getConflictManager(new ModuleId("theirorg",
0516: "theirmodule1"));
0517: assertNotNull(cm);
0518: assertTrue(cm instanceof FixedConflictManager);
0519: FixedConflictManager fcm = (FixedConflictManager) cm;
0520: assertEquals(2, fcm.getRevs().size());
0521: assertTrue(fcm.getRevs().contains("1.0"));
0522: assertTrue(fcm.getRevs().contains("1.1"));
0523:
0524: cm = md.getConflictManager(new ModuleId("theirorg",
0525: "theirmodule2"));
0526: assertNull(cm);
0527:
0528: ExcludeRule[] rules = md.getAllExcludeRules();
0529: assertNotNull(rules);
0530: assertEquals(2, rules.length);
0531: assertEquals(GlobPatternMatcher.INSTANCE, rules[0].getMatcher());
0532: assertEquals(ExactPatternMatcher.INSTANCE, rules[1]
0533: .getMatcher());
0534: assertEquals(Arrays.asList(new String[] { "myconf1" }), Arrays
0535: .asList(rules[0].getConfigurations()));
0536: assertEquals(Arrays.asList(new String[] { "myconf1", "myconf2",
0537: "myconf3", "myconf4", "myoldconf" }), Arrays
0538: .asList(rules[1].getConfigurations()));
0539: }
0540:
0541: public void testBug60() throws Exception {
0542: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0543: .parseDescriptor(settings,
0544: getClass().getResource("test-bug60.xml"), true);
0545: assertNotNull(md);
0546: assertEquals("myorg", md.getModuleRevisionId()
0547: .getOrganisation());
0548: assertEquals("mymodule", md.getModuleRevisionId().getName());
0549: assertEquals("myrev", md.getModuleRevisionId().getRevision());
0550: assertEquals("integration", md.getStatus());
0551: Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
0552: .getTime();
0553: assertEquals(pubdate, md.getPublicationDate());
0554:
0555: assertEquals(Arrays
0556: .asList(new Configuration[] { new Configuration(
0557: "default") }), Arrays.asList(md
0558: .getConfigurations()));
0559:
0560: assertArtifacts(md.getArtifacts("default"), new String[] {
0561: "myartifact1", "myartifact2" });
0562: }
0563:
0564: public void testNoArtifact() throws Exception {
0565: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0566: .parseDescriptor(settings,
0567: getClass().getResource("test-noartifact.xml"),
0568: true);
0569: assertNotNull(md);
0570: assertEquals("myorg", md.getModuleRevisionId()
0571: .getOrganisation());
0572: assertEquals("mymodule", md.getModuleRevisionId().getName());
0573: assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId()
0574: .getRevision());
0575: assertEquals("integration", md.getStatus());
0576:
0577: assertNotNull(md.getConfigurations());
0578: assertEquals(Arrays
0579: .asList(new Configuration[] { new Configuration(
0580: "default") }), Arrays.asList(md
0581: .getConfigurations()));
0582:
0583: assertNotNull(md.getArtifacts("default"));
0584: assertEquals(0, md.getArtifacts("default").length);
0585:
0586: assertNotNull(md.getDependencies());
0587: assertEquals(0, md.getDependencies().length);
0588: }
0589:
0590: public void testNoPublication() throws Exception {
0591: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0592: .parseDescriptor(
0593: settings,
0594: getClass()
0595: .getResource("test-nopublication.xml"),
0596: true);
0597: assertNotNull(md);
0598: assertEquals("myorg", md.getModuleRevisionId()
0599: .getOrganisation());
0600: assertEquals("mymodule", md.getModuleRevisionId().getName());
0601: assertEquals("myrev", md.getModuleRevisionId().getRevision());
0602: assertEquals("integration", md.getStatus());
0603: Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
0604: .getTime();
0605: assertEquals(pubdate, md.getPublicationDate());
0606:
0607: assertNotNull(md.getConfigurations());
0608: assertEquals(Arrays
0609: .asList(new Configuration[] { new Configuration(
0610: "default") }), Arrays.asList(md
0611: .getConfigurations()));
0612:
0613: assertNotNull(md.getArtifacts("default"));
0614: assertEquals(1, md.getArtifacts("default").length);
0615:
0616: assertNotNull(md.getDependencies());
0617: assertEquals(1, md.getDependencies().length);
0618: }
0619:
0620: public void testArtifactsDefaults() throws Exception {
0621: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0622: .parseDescriptor(
0623: settings,
0624: getClass().getResource(
0625: "test-artifacts-defaults.xml"), true);
0626: assertNotNull(md);
0627:
0628: Artifact[] artifacts = md.getArtifacts("default");
0629: assertNotNull(artifacts);
0630: assertEquals(3, artifacts.length);
0631: assertArtifactEquals("mymodule", "jar", "jar", artifacts[0]);
0632: assertArtifactEquals("myartifact", "jar", "jar", artifacts[1]);
0633: assertArtifactEquals("mymodule", "dll", "dll", artifacts[2]);
0634: }
0635:
0636: private void assertArtifactEquals(String name, String type,
0637: String ext, Artifact artifact) {
0638: assertEquals(name + "/" + type + "/" + ext, artifact.getName()
0639: + "/" + artifact.getType() + "/" + artifact.getExt());
0640: }
0641:
0642: public void testDefaultConf() throws Exception {
0643: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0644: .parseDescriptor(settings,
0645: getClass().getResource("test-defaultconf.xml"),
0646: true);
0647: assertNotNull(md);
0648:
0649: DependencyDescriptor[] dependencies = md.getDependencies();
0650: assertNotNull(dependencies);
0651: assertEquals(2, dependencies.length);
0652:
0653: // no conf def => defaults to defaultConf: default
0654: DependencyDescriptor dd = getDependency(dependencies,
0655: "mymodule1");
0656: assertNotNull(dd);
0657: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0658: assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
0659: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0660: .asList(dd.getModuleConfigurations()));
0661: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0662: .asList(dd.getDependencyConfigurations("default")));
0663:
0664: // confs def: *->*
0665: dd = getDependency(dependencies, "mymodule2");
0666: assertNotNull(dd);
0667: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0668: assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
0669: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0670: .asList(dd.getModuleConfigurations()));
0671: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0672: .asList(dd.getDependencyConfigurations("default")));
0673: }
0674:
0675: public void testDefaultConf2() throws Exception {
0676: ModuleDescriptor md = XmlModuleDescriptorParser
0677: .getInstance()
0678: .parseDescriptor(
0679: settings,
0680: getClass().getResource("test-defaultconf2.xml"),
0681: true);
0682: assertNotNull(md);
0683:
0684: DependencyDescriptor[] dependencies = md.getDependencies();
0685: assertNotNull(dependencies);
0686: assertEquals(2, dependencies.length);
0687:
0688: // no conf def => defaults to defaultConf: *->default
0689: DependencyDescriptor dd = getDependency(dependencies,
0690: "mymodule1");
0691: assertNotNull(dd);
0692: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0693: assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
0694: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0695: .asList(dd.getModuleConfigurations()));
0696: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0697: .asList(dd.getDependencyConfigurations("default")));
0698: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0699: .asList(dd.getDependencyConfigurations("test")));
0700:
0701: // confs def: test: should not use default conf for the right side (use of
0702: // defaultconfmapping is required for that) => test->test
0703: dd = getDependency(dependencies, "mymodule2");
0704: assertNotNull(dd);
0705: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0706: assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
0707: assertEquals(Arrays.asList(new String[] { "test" }), Arrays
0708: .asList(dd.getModuleConfigurations()));
0709: assertEquals(Arrays.asList(new String[] { "test" }), Arrays
0710: .asList(dd.getDependencyConfigurations("test")));
0711: }
0712:
0713: public void testDefaultConfMapping() throws Exception {
0714: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0715: .parseDescriptor(
0716: settings,
0717: getClass().getResource(
0718: "test-defaultconfmapping.xml"), true);
0719: assertNotNull(md);
0720:
0721: DependencyDescriptor[] dependencies = md.getDependencies();
0722: assertNotNull(dependencies);
0723: assertEquals(2, dependencies.length);
0724:
0725: // no conf def => defaults to defaultConf: *->default
0726: DependencyDescriptor dd = getDependency(dependencies,
0727: "mymodule1");
0728: assertNotNull(dd);
0729: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0730: assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
0731: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0732: .asList(dd.getModuleConfigurations()));
0733: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0734: .asList(dd.getDependencyConfigurations("default")));
0735: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0736: .asList(dd.getDependencyConfigurations("test")));
0737:
0738: // confs def: test: should use default conf mapping for the right side => test->default
0739: dd = getDependency(dependencies, "mymodule2");
0740: assertNotNull(dd);
0741: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0742: assertEquals("2.0", dd.getDependencyRevisionId().getRevision());
0743: assertEquals(Arrays.asList(new String[] { "test" }), Arrays
0744: .asList(dd.getModuleConfigurations()));
0745: assertEquals(Arrays.asList(new String[] { "default" }), Arrays
0746: .asList(dd.getDependencyConfigurations("test")));
0747: }
0748:
0749: public void testExtraAttributes() throws Exception {
0750: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0751: .parseDescriptor(
0752: settings,
0753: getClass().getResource(
0754: "test-extra-attributes.xml"), false);
0755: assertNotNull(md);
0756:
0757: assertEquals("infoextravalue", md.getAttribute("infoextra"));
0758: assertEquals("infoextravalue", md.getModuleRevisionId()
0759: .getAttribute("infoextra"));
0760:
0761: assertEquals("confextravalue", md.getConfiguration("default")
0762: .getAttribute("confextra"));
0763:
0764: Artifact[] artifacts = md.getArtifacts("default");
0765: assertEquals(1, artifacts.length);
0766: Artifact art = artifacts[0];
0767: assertEquals("art1", art.getName());
0768: assertEquals("artextravalue", art.getAttribute("artextra"));
0769:
0770: DependencyDescriptor[] dependencies = md.getDependencies();
0771: assertNotNull(dependencies);
0772: assertEquals(1, dependencies.length);
0773:
0774: DependencyDescriptor dd = getDependency(dependencies,
0775: "mymodule1");
0776: assertNotNull(dd);
0777: assertEquals("myorg", dd.getDependencyId().getOrganisation());
0778: assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
0779: assertEquals("depextravalue", dd.getAttribute("depextra"));
0780: assertEquals("depextravalue", dd.getDependencyRevisionId()
0781: .getAttribute("depextra"));
0782: }
0783:
0784: public void testImportConfigurations1() throws Exception {
0785: // import configurations
0786: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0787: .parseDescriptor(
0788: settings,
0789: getClass().getResource(
0790: "test-configurations-import1.xml"),
0791: true);
0792: assertNotNull(md);
0793:
0794: // should have imported configurations
0795: assertNotNull(md.getConfigurations());
0796: assertEquals(Arrays.asList(new Configuration[] {
0797: new Configuration("conf1", Visibility.PUBLIC, "",
0798: new String[0], true, null),
0799: new Configuration("conf2", Visibility.PRIVATE, "",
0800: new String[0], true, null) }), Arrays.asList(md
0801: .getConfigurations()));
0802:
0803: DependencyDescriptor[] dependencies = md.getDependencies();
0804: assertNotNull(dependencies);
0805: assertEquals(2, dependencies.length);
0806:
0807: // no conf def => defaults to defaultConf: *->*
0808: DependencyDescriptor dd = getDependency(dependencies,
0809: "mymodule1");
0810: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0811: .asList(dd.getModuleConfigurations()));
0812: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0813: .asList(dd.getDependencyConfigurations("conf1")));
0814:
0815: // confs def: conf1->*
0816: dd = getDependency(dependencies, "mymodule2");
0817: assertEquals(Arrays.asList(new String[] { "conf1" }), Arrays
0818: .asList(dd.getModuleConfigurations()));
0819: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0820: .asList(dd.getDependencyConfigurations("conf1")));
0821: }
0822:
0823: public void testImportConfigurations2() throws Exception {
0824: // import configurations and add another one
0825: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0826: .parseDescriptor(
0827: settings,
0828: getClass().getResource(
0829: "test-configurations-import2.xml"),
0830: true);
0831: assertNotNull(md);
0832:
0833: // should have imported configurations and added the one defined in the file itself
0834: assertNotNull(md.getConfigurations());
0835: assertEquals(Arrays.asList(new Configuration[] {
0836: new Configuration("conf1", Visibility.PUBLIC, "",
0837: new String[0], true, null),
0838: new Configuration("conf2", Visibility.PRIVATE, "",
0839: new String[0], true, null),
0840: new Configuration("conf3", Visibility.PUBLIC, "",
0841: new String[0], true, null) }), Arrays.asList(md
0842: .getConfigurations()));
0843:
0844: DependencyDescriptor[] dependencies = md.getDependencies();
0845: assertNotNull(dependencies);
0846: assertEquals(2, dependencies.length);
0847:
0848: // no conf def => defaults to defaultConf: *->*
0849: DependencyDescriptor dd = getDependency(dependencies,
0850: "mymodule1");
0851: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0852: .asList(dd.getModuleConfigurations()));
0853: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0854: .asList(dd.getDependencyConfigurations("conf1")));
0855:
0856: // confs def: conf2,conf3->*
0857: dd = getDependency(dependencies, "mymodule2");
0858: assertEquals(new HashSet(Arrays.asList(new String[] { "conf2",
0859: "conf3" })), new HashSet(Arrays.asList(dd
0860: .getModuleConfigurations())));
0861: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0862: .asList(dd.getDependencyConfigurations("conf2")));
0863: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0864: .asList(dd.getDependencyConfigurations("conf3")));
0865: }
0866:
0867: public void testImportConfigurations3() throws Exception {
0868: // import configurations and default mapping
0869: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0870: .parseDescriptor(
0871: settings,
0872: getClass().getResource(
0873: "test-configurations-import3.xml"),
0874: true);
0875: assertNotNull(md);
0876:
0877: // should have imported configurations
0878: assertNotNull(md.getConfigurations());
0879: assertEquals(Arrays.asList(new Configuration[] {
0880: new Configuration("conf1", Visibility.PUBLIC, "",
0881: new String[0], true, null),
0882: new Configuration("conf2", Visibility.PRIVATE, "",
0883: new String[0], true, null) }), Arrays.asList(md
0884: .getConfigurations()));
0885:
0886: DependencyDescriptor[] dependencies = md.getDependencies();
0887: assertNotNull(dependencies);
0888: assertEquals(2, dependencies.length);
0889:
0890: // no conf def => defaults to defaultConf defined in imported file: *->@
0891: DependencyDescriptor dd = getDependency(dependencies,
0892: "mymodule1");
0893: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0894: .asList(dd.getModuleConfigurations()));
0895: assertEquals(Arrays.asList(new String[] { "conf1" }), Arrays
0896: .asList(dd.getDependencyConfigurations("conf1")));
0897: assertEquals(Arrays.asList(new String[] { "conf2" }), Arrays
0898: .asList(dd.getDependencyConfigurations("conf2")));
0899:
0900: // confs def: conf1->*
0901: dd = getDependency(dependencies, "mymodule2");
0902: assertEquals(Arrays.asList(new String[] { "conf1" }), Arrays
0903: .asList(dd.getModuleConfigurations()));
0904: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0905: .asList(dd.getDependencyConfigurations("conf1")));
0906: }
0907:
0908: public void testImportConfigurations5() throws Exception {
0909: // import configurations
0910: settings.setVariable("base.dir", new File(".")
0911: .getAbsolutePath());
0912: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0913: .parseDescriptor(
0914: settings,
0915: getClass().getResource(
0916: "test-configurations-import5.xml"),
0917: true);
0918: assertNotNull(md);
0919:
0920: // should have imported configurations
0921: assertNotNull(md.getConfigurations());
0922: assertEquals(Arrays.asList(new Configuration[] {
0923: new Configuration("conf1", Visibility.PUBLIC, "",
0924: new String[0], true, null),
0925: new Configuration("conf2", Visibility.PRIVATE, "",
0926: new String[0], true, null) }), Arrays.asList(md
0927: .getConfigurations()));
0928:
0929: DependencyDescriptor[] dependencies = md.getDependencies();
0930: assertNotNull(dependencies);
0931: assertEquals(2, dependencies.length);
0932:
0933: // no conf def => defaults to defaultConf: *->*
0934: DependencyDescriptor dd = getDependency(dependencies,
0935: "mymodule1");
0936: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0937: .asList(dd.getModuleConfigurations()));
0938: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0939: .asList(dd.getDependencyConfigurations("conf1")));
0940:
0941: // confs def: conf1->*
0942: dd = getDependency(dependencies, "mymodule2");
0943: assertEquals(Arrays.asList(new String[] { "conf1" }), Arrays
0944: .asList(dd.getModuleConfigurations()));
0945: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
0946: .asList(dd.getDependencyConfigurations("conf1")));
0947: }
0948:
0949: public void testExtendOtherConfigs() throws Exception {
0950: // import configurations and default mapping
0951: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0952: .parseDescriptor(
0953: settings,
0954: getClass().getResource(
0955: "test-configextendsothers1.xml"), true);
0956: assertNotNull(md);
0957:
0958: // has an 'all-public' configuration
0959: Configuration allPublic = md.getConfiguration("all-public");
0960: assertNotNull(allPublic);
0961:
0962: // 'all-public' extends all other public configurations
0963: String[] allPublicExt = allPublic.getExtends();
0964: assertEquals(Arrays.asList(new String[] { "default", "test" }),
0965: Arrays.asList(allPublicExt));
0966: }
0967:
0968: public void testImportConfigurationsWithExtendOtherConfigs()
0969: throws Exception {
0970: // import configurations and default mapping
0971: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0972: .parseDescriptor(
0973: settings,
0974: getClass().getResource(
0975: "test-configextendsothers2.xml"), true);
0976: assertNotNull(md);
0977:
0978: // has an 'all-public' configuration
0979: Configuration allPublic = md.getConfiguration("all-public");
0980: assertNotNull(allPublic);
0981:
0982: // 'all-public' extends all other public configurations
0983: String[] allPublicExt = allPublic.getExtends();
0984: assertEquals(Arrays.asList(new String[] { "default", "test",
0985: "extra" }), Arrays.asList(allPublicExt));
0986: }
0987:
0988: public void testImportConfigurationsWithMappingOverride()
0989: throws Exception {
0990: // import configurations and default mapping
0991: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
0992: .parseDescriptor(
0993: settings,
0994: getClass().getResource(
0995: "test-configurations-import4.xml"),
0996: true);
0997: assertNotNull(md);
0998:
0999: // has 2 dependencies
1000: DependencyDescriptor[] dependencies = md.getDependencies();
1001: assertNotNull(dependencies);
1002: assertEquals(2, dependencies.length);
1003:
1004: // confs dep1: conf1->A;conf2->B (mappingoverride = true)
1005: DependencyDescriptor dd = getDependency(dependencies,
1006: "mymodule1");
1007: assertEquals(Arrays.asList(new String[] { "conf1", "conf2" }),
1008: Arrays.asList(dd.getModuleConfigurations()));
1009: assertEquals(Arrays.asList(new String[] { "A" }), Arrays
1010: .asList(dd.getDependencyConfigurations("conf1")));
1011: assertEquals(Arrays.asList(new String[] { "B" }), Arrays
1012: .asList(dd.getDependencyConfigurations("conf2")));
1013:
1014: // confs dep2: conf2->B
1015: dd = getDependency(dependencies, "mymodule2");
1016: assertEquals(Arrays.asList(new String[] { "conf2" }), Arrays
1017: .asList(dd.getModuleConfigurations()));
1018: assertEquals(Arrays.asList(new String[] { "B" }), Arrays
1019: .asList(dd.getDependencyConfigurations("conf2")));
1020: }
1021:
1022: public void testImportConfigurationsWithWildcardAndMappingOverride()
1023: throws Exception {
1024: // import configurations and default mapping
1025: ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
1026: .parseDescriptor(
1027: settings,
1028: getClass().getResource(
1029: "test-configextendsothers3.xml"), true);
1030: assertNotNull(md);
1031:
1032: // has 2 dependencies
1033: DependencyDescriptor[] dependencies = md.getDependencies();
1034: assertNotNull(dependencies);
1035: assertEquals(2, dependencies.length);
1036:
1037: // confs dep1: all-public->all-public (mappingoverride = true)
1038: DependencyDescriptor dd = getDependency(dependencies,
1039: "mymodule1");
1040: assertEquals(Arrays.asList(new String[] { "all-public" }),
1041: Arrays.asList(dd.getModuleConfigurations()));
1042: assertEquals(Arrays.asList(new String[] { "all-public" }),
1043: Arrays.asList(dd
1044: .getDependencyConfigurations("all-public")));
1045:
1046: // confs dep2: extra->extra;all-public->all-public (mappingoverride = true)
1047: dd = getDependency(dependencies, "mymodule2");
1048: assertEquals(Arrays
1049: .asList(new String[] { "extra", "all-public" }), Arrays
1050: .asList(dd.getModuleConfigurations()));
1051: assertEquals(Arrays.asList(new String[] { "extra" }), Arrays
1052: .asList(dd.getDependencyConfigurations("extra")));
1053: assertEquals(Arrays.asList(new String[] { "all-public" }),
1054: Arrays.asList(dd
1055: .getDependencyConfigurations("all-public")));
1056: }
1057:
1058: public void testDefaultConfMappingWithSelectors() throws Exception {
1059: // import configurations and default mapping
1060: ModuleDescriptor md = XmlModuleDescriptorParser
1061: .getInstance()
1062: .parseDescriptor(
1063: settings,
1064: getClass()
1065: .getResource(
1066: "test-defaultconfmapping-withselectors.xml"),
1067: true);
1068: assertNotNull(md);
1069:
1070: // has 3 dependencies
1071: DependencyDescriptor[] dependencies = md.getDependencies();
1072: assertNotNull(dependencies);
1073: assertEquals(3, dependencies.length);
1074:
1075: // confs dep1: *->default1,default3
1076: DependencyDescriptor dd = getDependency(dependencies,
1077: "mymodule1");
1078: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
1079: .asList(dd.getModuleConfigurations()));
1080: assertEquals(Arrays.asList(new String[] { "default1",
1081: "default3" }), Arrays.asList(dd
1082: .getDependencyConfigurations("default")));
1083:
1084: // confs dep2: test->default2,default3
1085: dd = getDependency(dependencies, "mymodule2");
1086: assertEquals(Arrays.asList(new String[] { "test" }), Arrays
1087: .asList(dd.getModuleConfigurations()));
1088: assertEquals(Arrays.asList(new String[] { "default2",
1089: "default3" }), Arrays.asList(dd
1090: .getDependencyConfigurations("test")));
1091:
1092: // confs dep3: *->default4
1093: dd = getDependency(dependencies, "mymodule3");
1094: assertEquals(Arrays.asList(new String[] { "*" }), Arrays
1095: .asList(dd.getModuleConfigurations()));
1096: assertEquals(Arrays.asList(new String[] { "default4" }), Arrays
1097: .asList(dd.getDependencyConfigurations("bla")));
1098: }
1099:
1100: public void testWithNonExistingConfigInDependency()
1101: throws Exception {
1102: // IVY-442
1103: try {
1104: XmlModuleDescriptorParser.getInstance().parseDescriptor(
1105: settings,
1106: getClass().getResource("test-incorrectconf1.xml"),
1107: true);
1108: fail("ParseException hasn't been thrown");
1109: } catch (ParseException e) {
1110: // expected
1111: }
1112: }
1113:
1114: public void testWithNonExistingConfigInPublications()
1115: throws Exception {
1116: try {
1117: XmlModuleDescriptorParser.getInstance().parseDescriptor(
1118: settings,
1119: getClass().getResource("test-incorrectconf2.xml"),
1120: true);
1121: fail("ParseException hasn't been thrown");
1122: } catch (ParseException e) {
1123: // expected
1124: }
1125: }
1126:
1127: public void testWithExistingConfigsInPublicationsSeparatedBySemiColon()
1128: throws Exception {
1129: // IVY-441
1130: try {
1131: XmlModuleDescriptorParser.getInstance().parseDescriptor(
1132: settings,
1133: getClass().getResource("test-incorrectconf3.xml"),
1134: true);
1135: fail("ParseException hasn't been thrown");
1136: } catch (ParseException e) {
1137: // expected
1138: }
1139: }
1140: }
|