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.Project;
025: import org.apache.tools.ant.taskdefs.Delete;
026:
027: public class IvyBuildNumberTest extends TestCase {
028: private File cache;
029:
030: private IvyBuildNumber buildNumber;
031:
032: protected void setUp() throws Exception {
033: createCache();
034: Project project = new Project();
035: project.setProperty("ivy.settings.file",
036: "test/repositories/ivysettings.xml");
037:
038: buildNumber = new IvyBuildNumber();
039: buildNumber.setProject(project);
040: }
041:
042: private void createCache() {
043: cache = new File("build/cache");
044: cache.mkdirs();
045: }
046:
047: protected void tearDown() throws Exception {
048: cleanCache();
049: }
050:
051: private void cleanCache() {
052: Delete del = new Delete();
053: del.setProject(new Project());
054: del.setDir(cache);
055: del.execute();
056: }
057:
058: public void testDefault() throws Exception {
059: buildNumber.setOrganisation("org1");
060: buildNumber.setModule("newmod");
061: buildNumber.execute();
062: assertEquals(null, buildNumber.getProject().getProperty(
063: "ivy.revision"));
064: assertEquals("0", buildNumber.getProject().getProperty(
065: "ivy.new.revision"));
066: assertEquals(null, buildNumber.getProject().getProperty(
067: "ivy.build.number"));
068: assertEquals("0", buildNumber.getProject().getProperty(
069: "ivy.new.build.number"));
070: }
071:
072: public void testDefault2() throws Exception {
073: buildNumber.setOrganisation("org1");
074: buildNumber.setModule("newmod");
075: buildNumber.setDefault("1.0-dev-1");
076: buildNumber.execute();
077: assertEquals(null, buildNumber.getProject().getProperty(
078: "ivy.revision"));
079: assertEquals("1.0-dev-1", buildNumber.getProject().getProperty(
080: "ivy.new.revision"));
081: assertEquals(null, buildNumber.getProject().getProperty(
082: "ivy.build.number"));
083: assertEquals("1", buildNumber.getProject().getProperty(
084: "ivy.new.build.number"));
085: }
086:
087: public void testDefault3() throws Exception {
088: buildNumber.setOrganisation("org1");
089: buildNumber.setModule("newmod");
090: buildNumber.setDefault("mydefault");
091: buildNumber.execute();
092: assertEquals(null, buildNumber.getProject().getProperty(
093: "ivy.revision"));
094: assertEquals("mydefault", buildNumber.getProject().getProperty(
095: "ivy.new.revision"));
096: assertEquals(null, buildNumber.getProject().getProperty(
097: "ivy.build.number"));
098: assertEquals(null, buildNumber.getProject().getProperty(
099: "ivy.new.build.number"));
100: }
101:
102: public void testLatest() throws Exception {
103: buildNumber.setOrganisation("org1");
104: buildNumber.setModule("mod1.1");
105: buildNumber.execute();
106: assertEquals("2.0", buildNumber.getProject().getProperty(
107: "ivy.revision"));
108: assertEquals("2.1", buildNumber.getProject().getProperty(
109: "ivy.new.revision"));
110: assertEquals("0", buildNumber.getProject().getProperty(
111: "ivy.build.number"));
112: assertEquals("1", buildNumber.getProject().getProperty(
113: "ivy.new.build.number"));
114: }
115:
116: public void testLatest2() throws Exception {
117: buildNumber.setOrganisation("orgbn");
118: buildNumber.setModule("buildnumber");
119: buildNumber.execute();
120: assertEquals("test", buildNumber.getProject().getProperty(
121: "ivy.revision"));
122: assertEquals("test.1", buildNumber.getProject().getProperty(
123: "ivy.new.revision"));
124: assertEquals(null, buildNumber.getProject().getProperty(
125: "ivy.build.number"));
126: assertEquals("1", buildNumber.getProject().getProperty(
127: "ivy.new.build.number"));
128: }
129:
130: public void testPrefix() throws Exception {
131: buildNumber.setOrganisation("org1");
132: buildNumber.setModule("mod1.1");
133: buildNumber.setPrefix("test");
134: buildNumber.execute();
135: assertEquals("2.0", buildNumber.getProject().getProperty(
136: "test.revision"));
137: assertEquals("2.1", buildNumber.getProject().getProperty(
138: "test.new.revision"));
139: assertEquals("0", buildNumber.getProject().getProperty(
140: "test.build.number"));
141: assertEquals("1", buildNumber.getProject().getProperty(
142: "test.new.build.number"));
143: }
144:
145: public void testBuildNumber() throws Exception {
146: buildNumber.setOrganisation("org1");
147: buildNumber.setModule("mod1.1");
148: buildNumber.setRevision("1.");
149: buildNumber.execute();
150: assertEquals("1.1", buildNumber.getProject().getProperty(
151: "ivy.revision"));
152: assertEquals("1.2", buildNumber.getProject().getProperty(
153: "ivy.new.revision"));
154: assertEquals("1", buildNumber.getProject().getProperty(
155: "ivy.build.number"));
156: assertEquals("2", buildNumber.getProject().getProperty(
157: "ivy.new.build.number"));
158: }
159:
160: public void testBuildNumber2() throws Exception {
161: buildNumber.setOrganisation("org1");
162: buildNumber.setModule("mod1.5");
163: buildNumber.setRevision("1.");
164: buildNumber.execute();
165: assertEquals("1.0.2", buildNumber.getProject().getProperty(
166: "ivy.revision"));
167: assertEquals("1.1", buildNumber.getProject().getProperty(
168: "ivy.new.revision"));
169: assertEquals("0", buildNumber.getProject().getProperty(
170: "ivy.build.number"));
171: assertEquals("1", buildNumber.getProject().getProperty(
172: "ivy.new.build.number"));
173: }
174:
175: public void testBuildNumber3() throws Exception {
176: buildNumber.setOrganisation("org1");
177: buildNumber.setModule("mod1.1");
178: buildNumber.setRevision("1.1");
179: buildNumber.execute();
180: assertEquals("1.1", buildNumber.getProject().getProperty(
181: "ivy.revision"));
182: assertEquals("1.1.1", buildNumber.getProject().getProperty(
183: "ivy.new.revision"));
184: assertEquals(null, buildNumber.getProject().getProperty(
185: "ivy.build.number"));
186: assertEquals("1", buildNumber.getProject().getProperty(
187: "ivy.new.build.number"));
188: }
189:
190: public void testBuildNumber4() throws Exception {
191: buildNumber.setOrganisation("org1");
192: buildNumber.setModule("mod1.1");
193: buildNumber.setRevision("3.");
194: buildNumber.execute();
195: assertEquals(null, buildNumber.getProject().getProperty(
196: "ivy.revision"));
197: assertEquals("3.0", buildNumber.getProject().getProperty(
198: "ivy.new.revision"));
199: assertEquals(null, buildNumber.getProject().getProperty(
200: "ivy.build.number"));
201: assertEquals("0", buildNumber.getProject().getProperty(
202: "ivy.new.build.number"));
203: }
204:
205: }
|