View Javadoc
1   package org.apache.archiva.common.utils;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  public class VersionUtilTest
25      extends TestCase
26  {
27  
28      public void testIsVersion()
29      {
30          // 0%
31          assertFalse( VersionUtil.isVersion( "project" ) );
32  
33          // 0%
34          assertFalse( VersionUtil.isVersion( "project-not-version" ) );
35  
36          // 50%
37          assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) );
38  
39          // > 75%
40          assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) );
41  
42          // 75%
43          assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) );
44  
45          // >75%
46          assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) );
47  
48          //only first token matches
49          assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) );
50  
51      }
52  
53      public void testIsSimpleVersionKeyword()
54      {
55          assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) );
56  
57          assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) );
58  
59          assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) );
60      }
61  
62      public void testIsSnapshot()
63      {
64          assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) );
65  
66          assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) );
67  
68          assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) );
69      }
70  
71      public void testGetBaseVersion()
72      {
73          assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" );
74      }
75  
76      public void testGetReleaseVersion()
77      {
78          assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" );
79      }
80  
81      public void testIsUniqueSnapshot()
82      {
83          assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) );
84  
85          assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) );
86      }
87  
88      public void testIsGenericSnapshot()
89      {
90          assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) );
91  
92          assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) );
93      }
94  
95      public void testGetVersionFromGenericSnapshot()
96      {
97          assertEquals( "3.0", VersionUtil.getVersionFromGenericSnapshot( "3.0-SNAPSHOT" ) );
98  
99      }
100 
101 }