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:
022: import junit.framework.TestCase;
023:
024: import org.apache.tools.ant.BuildException;
025: import org.apache.tools.ant.Project;
026: import org.apache.tools.ant.taskdefs.Delete;
027:
028: public class IvyInstallTest extends TestCase {
029: private File cache;
030:
031: private IvyInstall install;
032:
033: private Project project;
034:
035: protected void setUp() throws Exception {
036: createCache();
037: cleanTestLib();
038: project = new Project();
039: project.setProperty("ivy.settings.file",
040: "test/repositories/ivysettings.xml");
041:
042: install = new IvyInstall();
043: install.setProject(project);
044: System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
045: }
046:
047: private void createCache() {
048: cache = new File("build/cache");
049: cache.mkdirs();
050: }
051:
052: protected void tearDown() throws Exception {
053: cleanCache();
054: cleanTestLib();
055: }
056:
057: private void cleanCache() {
058: Delete del = new Delete();
059: del.setProject(new Project());
060: del.setDir(cache);
061: del.execute();
062: }
063:
064: private void cleanTestLib() {
065: Delete del = new Delete();
066: del.setProject(new Project());
067: del.setDir(new File("build/test/lib"));
068: del.execute();
069: }
070:
071: public void testDependencyNotFoundFailure() {
072: install.setOrganisation("xxx");
073: install.setModule("yyy");
074: install.setRevision("zzz");
075: install.setFrom("test");
076: install.setTo("1");
077:
078: try {
079: install.execute();
080: fail("unknown dependency, failure expected (haltunresolved=true)");
081: } catch (BuildException be) {
082: // success
083: }
084: }
085:
086: public void testDependencyNotFoundSuccess() {
087: install.setOrganisation("xxx");
088: install.setModule("yyy");
089: install.setRevision("zzz");
090: install.setFrom("test");
091: install.setTo("1");
092: install.setHaltonfailure(false);
093:
094: try {
095: install.execute();
096: } catch (BuildException be) {
097: fail("unknown dependency, failure unexepected (haltunresolved=false)");
098: }
099: }
100: }
|