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.ant;
019:
020: import java.io.File;
021: import java.net.MalformedURLException;
022:
023: import junit.framework.TestCase;
024:
025: import org.apache.ivy.Ivy;
026: import org.apache.ivy.core.settings.IvySettings;
027: import org.apache.tools.ant.BuildException;
028: import org.apache.tools.ant.Project;
029: import org.apache.tools.ant.types.Reference;
030:
031: public class IvyTaskTest extends TestCase {
032:
033: public void testDefaultSettings() throws MalformedURLException {
034: Project p = new Project();
035: p.setBasedir("test/repositories");
036: // p.setProperty("ivy.settings.file" , "ivysettings.xml");
037: p.setProperty("myproperty", "myvalue");
038: IvyTask task = new IvyTask() {
039: public void doExecute() throws BuildException {
040: }
041: };
042: task.setProject(p);
043:
044: Ivy ivy = task.getIvyInstance();
045: assertNotNull(ivy);
046: IvySettings settings = ivy.getSettings();
047: assertNotNull(settings);
048:
049: assertEquals(new File("build/cache"), settings
050: .getDefaultCache());
051: // The next test doesn't always works on windows (mix C: and c: drive)
052: assertEquals(new File("test/repositories/ivysettings.xml")
053: .getAbsolutePath().toUpperCase(), new File(
054: (String) settings.getVariables().getVariable(
055: "ivy.settings.file")).getAbsolutePath()
056: .toUpperCase());
057: assertEquals(new File("test/repositories/ivysettings.xml")
058: .toURL().toExternalForm().toUpperCase(),
059: ((String) settings.getVariables().getVariable(
060: "ivy.settings.url")).toUpperCase());
061: assertEquals(new File("test/repositories").getAbsolutePath()
062: .toUpperCase(), ((String) settings.getVariables()
063: .getVariable("ivy.settings.dir")).toUpperCase());
064: assertEquals("myvalue", settings.getVariables().getVariable(
065: "myproperty"));
066: }
067:
068: public void testReferencedSettings() throws MalformedURLException {
069: Project p = new Project();
070: // p.setBasedir("test/repositories");
071: // p.setProperty("ivy.settings.file" , "ivysettings.xml");
072: p.setProperty("myproperty", "myvalue");
073:
074: IvyAntSettings antSettings = new IvyAntSettings();
075: antSettings.setProject(p);
076: // antSettings.setId("mySettings");
077: antSettings.setFile(new File(
078: "test/repositories/ivysettings.xml"));
079: p.addReference("mySettings", antSettings);
080:
081: IvyTask task = new IvyTask() {
082: public void doExecute() throws BuildException {
083: }
084: };
085: task.setProject(p);
086: task.setSettingsRef(new Reference("mySettings"));
087: Ivy ivy = task.getIvyInstance();
088: assertNotNull(ivy);
089: IvySettings settings = ivy.getSettings();
090: assertNotNull(settings);
091:
092: assertEquals(new File("build/cache"), settings
093: .getDefaultCache());
094: assertEquals(new File("test/repositories/ivysettings.xml")
095: .getAbsolutePath(), settings.getVariables()
096: .getVariable("ivy.settings.file"));
097: assertEquals(new File("test/repositories/ivysettings.xml")
098: .toURL().toExternalForm(), settings.getVariables()
099: .getVariable("ivy.settings.url"));
100: assertEquals(new File("test/repositories").getAbsolutePath(),
101: settings.getVariables().getVariable("ivy.settings.dir"));
102: assertEquals("myvalue", settings.getVariables().getVariable(
103: "myproperty"));
104:
105: }
106:
107: }
|