]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1172]
authorMaria Odea B. Ching <oching@apache.org>
Wed, 6 May 2009 11:20:06 +0000 (11:20 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Wed, 6 May 2009 11:20:06 +0000 (11:20 +0000)
submitted by Jan Ancajas
o loosen version validation rule in VersionUtil
o added test cases

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@772151 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/VersionUtil.java
archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/VersionUtilTest.java [new file with mode: 0644]

index 7e192162d7efaa70202c66b7bef25dd738ac690a..3cbcb8d8fbb564da25e68d82588465035a5fd5f3 100644 (file)
@@ -95,6 +95,10 @@ public class VersionUtil
 
             if ( mat.matches() )
             {
+                if ( i == 0 ) // loosen rule to return true if first token matches
+                {
+                    return true;
+                }
                 countValidParts++;
             }
         }
diff --git a/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/VersionUtilTest.java b/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/VersionUtilTest.java
new file mode 100644 (file)
index 0000000..b945738
--- /dev/null
@@ -0,0 +1,75 @@
+package org.apache.maven.archiva.common.utils;
+
+import junit.framework.TestCase;
+
+public class VersionUtilTest extends TestCase
+{
+
+    public void testIsVersion()
+    {
+        // 0%
+        assertFalse( VersionUtil.isVersion( "project" ) );
+        
+        // 0%
+        assertFalse( VersionUtil.isVersion( "project-not-version" ) );
+        
+        // 50%
+        assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) );
+        
+        // > 75%
+        assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) );
+        
+        // 75%
+        assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) );
+        
+        // >75%
+        assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) );
+      
+        //only first token matches
+        assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) );
+        
+    }
+    
+    public void testIsSimpleVersionKeyword()
+    {
+        assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) );
+        
+        assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) );
+        
+        assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) );
+    }
+   
+    public void testIsSnapshot()
+    {
+        assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) );
+        
+        assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) );
+        
+        assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) );
+    }
+    
+    public void testGetBaseVersion()
+    {
+        assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" );
+    }
+    
+    public void testGetReleaseVersion()
+    {
+        assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" );
+    }
+    
+    public void testIsUniqueSnapshot()
+    {
+        assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) );
+        
+        assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) );
+    }
+    
+    public void testIsGenericSnapshot()
+    {
+        assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) );
+        
+        assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) );
+    }
+    
+}