001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.nbbuild;
043:
044: import org.netbeans.junit.NbTestCase;
045: import static org.netbeans.nbbuild.IncrementSpecificationVersions.*;
046:
047: /** Test for increments of spec versions.
048: *
049: * @author Jaroslav Tulach
050: */
051: public class IncrementSpecificationVersionsTest extends NbTestCase {
052:
053: public IncrementSpecificationVersionsTest(String testName) {
054: super (testName);
055: }
056:
057: protected void setUp() throws Exception {
058: }
059:
060: protected void tearDown() throws Exception {
061: }
062:
063: public void testIncrementTrunkManifest() throws Exception {
064: boolean manifest = true;
065: int sticky = 1;
066:
067: assertEquals("1.1", increment("1.0", sticky, manifest));
068: assertEquals("1.2", increment("1.1", sticky, manifest));
069: assertEquals("2.3", increment("2.2", sticky, manifest));
070: assertEquals("3.12", increment("3.11", sticky, manifest));
071: assertEquals("203.215", increment("203.214", sticky, manifest));
072:
073: assertEquals("1.9", increment("1.8.1", sticky, manifest));
074: assertEquals("1.10", increment("1.9.1", sticky, manifest));
075: assertEquals("1.1", increment("1.0", sticky, manifest));
076: assertEquals("1.7", increment("1.6", sticky, manifest));
077: assertEquals("2.4", increment("2.3.8.1", sticky, manifest));
078: assertEquals("2.4", increment("2.3.8.1.5", sticky, manifest));
079: assertEquals("2.4", increment("2.3.8.1.5.6", sticky, manifest));
080:
081: assertEquals("1.1", increment("1", sticky, manifest));
082: assertEquals("100.1", increment("100", sticky, manifest));
083:
084: }
085:
086: public void testIncrementTrunk() throws Exception {
087: boolean manifest = false;
088: int sticky = 1;
089:
090: assertEquals("1.1.0", increment("1.0.0", sticky, manifest));
091: assertEquals("1.2.0", increment("1.1.0", sticky, manifest));
092: assertEquals("2.3.0", increment("2.2.0", sticky, manifest));
093: assertEquals("3.12.0", increment("3.11.0", sticky, manifest));
094: assertEquals("203.215.0", increment("203.214.0", sticky,
095: manifest));
096:
097: assertEquals("1.9.0", increment("1.8.1", sticky, manifest));
098: assertEquals("1.10.0", increment("1.9.1", sticky, manifest));
099: assertEquals("1.1.0", increment("1.0", sticky, manifest));
100: assertEquals("1.7.0", increment("1.6", sticky, manifest));
101: assertEquals("2.4.0", increment("2.3.8.1", sticky, manifest));
102: assertEquals("2.4.0", increment("2.3.8.1.5", sticky, manifest));
103: assertEquals("2.4.0",
104: increment("2.3.8.1.5.6", sticky, manifest));
105:
106: assertEquals("1.1.0", increment("1", sticky, manifest));
107: assertEquals("100.1.0", increment("100", sticky, manifest));
108: }
109:
110: public void testIncrementBranchManifest() throws Exception {
111: boolean manifest = true;
112: int sticky = 2;
113:
114: assertEquals("1.0.1", increment("1.0", sticky, manifest));
115: assertEquals("1.1.1", increment("1.1", sticky, manifest));
116: assertEquals("2.2.1", increment("2.2", sticky, manifest));
117: assertEquals("3.11.1", increment("3.11", sticky, manifest));
118: assertEquals("203.214.1",
119: increment("203.214", sticky, manifest));
120:
121: assertEquals("1.0.5", increment("1.0.4", sticky, manifest));
122: assertEquals("1.1.7", increment("1.1.6", sticky, manifest));
123: assertEquals("2.2.8", increment("2.2.7", sticky, manifest));
124: assertEquals("3.11.10", increment("3.11.9", sticky, manifest));
125: assertEquals("203.214.1001", increment("203.214.1000", sticky,
126: manifest));
127:
128: assertEquals("2.3.9", increment("2.3.8.1", sticky, manifest));
129: assertEquals("2.3.9", increment("2.3.8.1.5", sticky, manifest));
130: assertEquals("2.3.9",
131: increment("2.3.8.1.5.6", sticky, manifest));
132:
133: assertEquals("1.0.1", increment("1", sticky, manifest));
134: assertEquals("100.0.1", increment("100", sticky, manifest));
135:
136: }
137:
138: public void testIncrementBranch() throws Exception {
139: boolean manifest = false;
140: int sticky = 2;
141:
142: assertEquals("1.0.1", increment("1.0", sticky, manifest));
143: assertEquals("1.1.1", increment("1.1", sticky, manifest));
144: assertEquals("2.2.1", increment("2.2", sticky, manifest));
145: assertEquals("3.11.1", increment("3.11", sticky, manifest));
146: assertEquals("203.214.1",
147: increment("203.214", sticky, manifest));
148:
149: assertEquals("1.0.1", increment("1.0.0", sticky, manifest));
150: assertEquals("1.1.1", increment("1.1.0", sticky, manifest));
151: assertEquals("2.2.1", increment("2.2.0", sticky, manifest));
152: assertEquals("3.11.1", increment("3.11.0", sticky, manifest));
153: assertEquals("203.214.1", increment("203.214.0", sticky,
154: manifest));
155:
156: assertEquals("2.3.9", increment("2.3.8.1", sticky, manifest));
157: assertEquals("2.3.9", increment("2.3.8.1.5", sticky, manifest));
158: assertEquals("2.3.9",
159: increment("2.3.8.1.5.6", sticky, manifest));
160:
161: assertEquals("1.0.1", increment("1", sticky, manifest));
162: assertEquals("100.0.1", increment("100", sticky, manifest));
163:
164: }
165:
166: // Old behavior
167: // public void testIncrement() {
168: // String res;
169: //
170: // assertIncrement("1.0", false, true, "1.1");
171: // assertIncrement("1.0", true, true, "1.0.1");
172: // assertIncrement("1.0", false, false, null);
173: // assertIncrement("1.0", true, false, null);
174: // assertIncrement("1.0.0", false, false, "1.1.0");
175: // assertIncrement("1.0.0", true, false, "1.0.1");
176: // }
177:
178: public void testIncrementLevel4() {
179: String res;
180:
181: assertIncrement("1.2.3.4.5.6.7", 4, true, "1.2.3.4.6");
182: assertIncrement("1.0", 4, true, "1.0.0.0.1");
183: assertIncrement("1.2.3.4.5", 4, true, "1.2.3.4.6");
184: }
185:
186: private static void assertIncrement(String old, boolean branch,
187: boolean manifest, String res) {
188: String r = IncrementSpecificationVersions.increment(old,
189: branch ? 2 : 1, manifest);
190: assertEquals("Old: " + old + " branch: " + branch
191: + " manifest: " + manifest, res, r);
192: }
193:
194: private static void assertIncrement(String old, int stickyLevel,
195: boolean manifest, String res) {
196: String r = IncrementSpecificationVersions.increment(old,
197: stickyLevel, manifest);
198: assertEquals("Old: " + old + " stickyLevel: " + stickyLevel
199: + " manifest: " + manifest, res, r);
200: }
201: }
|