001    /**
002     * Copyright 2010-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.common.util;
017    
018    import org.junit.Assert;
019    import org.junit.Test;
020    
021    public class VersionUtilsTest {
022    
023            @Test
024            public void testIsSnapshot() {
025                    Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-SNAPSHOT"));
026                    Assert.assertTrue(VersionUtils.isSnapshot("1.0-SNAPSHOT"));
027                    Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-sNAPSHOt"));
028                    Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-snapshot"));
029                    Assert.assertFalse(VersionUtils.isSnapshot("1.0.0SNAPSHOT"));
030                    Assert.assertFalse(VersionUtils.isSnapshot("SNAPSHOT"));
031            }
032    
033            @Test
034            public void testTrimSnapshot() {
035                    Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0-SNAPSHOT"));
036                    Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0"));
037                    Assert.assertEquals("1.0.0-SNAPSHO", VersionUtils.trimSnapshot("1.0.0-SNAPSHO"));
038            }
039    
040            @Test
041            public void testGetVersionNormal() {
042                    Version version = VersionUtils.getVersion("1.0.0-SNAPSHOT");
043                    Assert.assertTrue(version.isSnapshot());
044                    Assert.assertEquals("1", version.getMajor());
045                    Assert.assertEquals("0", version.getMinor());
046                    Assert.assertEquals("0", version.getIncremental());
047                    Assert.assertEquals("1.0.0", version.getTrimmed());
048                    Assert.assertNull(version.getQualifier());
049            }
050    
051            @Test
052            public void testGetVersion2Digits() {
053                    Version version = VersionUtils.getVersion("1.0-SNAPSHOT");
054                    Assert.assertTrue(version.isSnapshot());
055                    Assert.assertEquals("1", version.getMajor());
056                    Assert.assertEquals("0", version.getMinor());
057                    Assert.assertNull(version.getIncremental());
058                    Assert.assertEquals("1.0", version.getTrimmed());
059                    Assert.assertNull(version.getQualifier());
060            }
061    
062            @Test
063            public void testGetVersion1Digit() {
064                    Version version = VersionUtils.getVersion("1-SNAPSHOT");
065                    Assert.assertTrue(version.isSnapshot());
066                    Assert.assertEquals("1", version.getMajor());
067                    Assert.assertNull(version.getMinor());
068                    Assert.assertNull(version.getIncremental());
069                    Assert.assertEquals("1", version.getTrimmed());
070                    Assert.assertNull(version.getQualifier());
071            }
072    
073            @Test
074            public void testGetVersionSpring() {
075                    Version version = VersionUtils.getVersion("3.1.3.RELEASE");
076                    Assert.assertFalse(version.isSnapshot());
077                    Assert.assertEquals("3", version.getMajor());
078                    Assert.assertEquals("1", version.getMinor());
079                    Assert.assertEquals("3", version.getIncremental());
080                    Assert.assertEquals("3.1.3.RELEASE", version.getTrimmed());
081                    Assert.assertEquals("RELEASE", version.getQualifier());
082            }
083    
084            @Test
085            public void testGetVersionWithQualifier() {
086                    Version version = VersionUtils.getVersion("1.0.0-M4-SNAPSHOT");
087                    Assert.assertTrue(version.isSnapshot());
088                    Assert.assertEquals("1", version.getMajor());
089                    Assert.assertEquals("0", version.getMinor());
090                    Assert.assertEquals("0", version.getIncremental());
091                    Assert.assertEquals("1.0.0-M4", version.getTrimmed());
092                    Assert.assertEquals("M4", version.getQualifier());
093            }
094    
095            @Test
096            public void testGetVersionWithDoubleQualifier() {
097                    Version version = VersionUtils.getVersion("1.0.0-beta-1-SNAPSHOT");
098                    Assert.assertTrue(version.isSnapshot());
099                    Assert.assertEquals("1", version.getMajor());
100                    Assert.assertEquals("0", version.getMinor());
101                    Assert.assertEquals("0", version.getIncremental());
102                    Assert.assertEquals("1.0.0-beta-1", version.getTrimmed());
103                    Assert.assertEquals("beta-1", version.getQualifier());
104            }
105    
106    }