krysalis-version/src/test/java/org/krysalis/version/impl/apache ApacheVersionFormatTest.java,NONE,1.1

Nick Chalko <[email protected]> Tue, 09 Nov 2004 07:54:54 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-version/src/test/java/org/krysalis/version/impl/apache
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2087/src/test/java/org/krysalis/version/impl/apache

Added Files:
	ApacheVersionFormatTest.java 
Log Message:
Coppied over a bunch of tests.

--- NEW FILE: ApacheVersionFormatTest.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.version.impl.apache;

import junit.framework.TestCase;

import org.krysalis.version.VersionFormatException;
import org.krysalis.version.impl.data.ReleaseLevel;
import org.krysalis.version.impl.data.VersionData;

/**
 * @author ajack
 */
public class ApacheVersionFormatTest extends TestCase {
    private ApacheVersionFormat m_format = null;

    public ApacheVersionFormatTest(String arg0) {
        super(arg0);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(ApacheVersionFormatTest.class);
    }

    public void setUp() {
        m_format = new ApacheVersionFormat();
    }

    public void testParseMajorMinor() throws VersionFormatException {
        testParse("5.5");
    }

	public void testParseMajorMinorRelease() throws VersionFormatException {
		VersionData version = testParse("5.5-beta");
		assertEquals(
			"ReleaseLevel ok: ",
			ReleaseLevel.BETA,version.getReleaseLevel());
	}

	public void testParseMajorMinorReleaseNoDash() throws VersionFormatException {
	   VersionData version = testParse("5.5beta");
	   assertEquals(
		   "ReleaseLevel ok: ",
		   ReleaseLevel.BETA,version.getReleaseLevel());
   }

   public void testParseMajorMinorPointReleaseNoDash() throws VersionFormatException {
	  VersionData version = testParse("5.5.5beta");
	  assertEquals(
		  "ReleaseLevel ok: ",
		  ReleaseLevel.BETA,version.getReleaseLevel());
  }

	public void testParseMajorMinorReleaseAbbrev()
		throws VersionFormatException {
		VersionData version = testParse("5.5-b");
		assertEquals(
			"ReleaseLevel ok: ",
			ReleaseLevel.BETA,version.getReleaseLevel());
	}
	
	public void testParseMajorMinorReleaseAbbrevNoDash()
			throws VersionFormatException {
			VersionData version = testParse("5.5b");
			assertEquals(
				"ReleaseLevel ok: ",
				ReleaseLevel.BETA,version.getReleaseLevel());
		}
    
    public void testParseMajorMinorPoint() throws VersionFormatException {
        VersionData version = testParse("5.5.5");

        assertTrue("Point ok: ", 5 == version.getPoint());
        assertTrue(
            "ReleaseLevel ok: ",
            ReleaseLevel.RELEASE == version.getReleaseLevel());
    }

    public void testParseMajorMinorPointRelease1()
        throws VersionFormatException {
        VersionData version = testParse("5.5.5-alpha");

        assertTrue("Point ok: ", 5 == version.getPoint());
        assertTrue(
            "ReleaseLevel ok: ",
            ReleaseLevel.ALPHA == version.getReleaseLevel());
    }

    public void testParseMajorMinorPointRelease2()
        throws VersionFormatException {
        VersionData version = testParse("5.5.5-beta");

        assertTrue("Point ok: ", 5 == version.getPoint());
        assertTrue(
            "ReleaseLevel ok: ",
            ReleaseLevel.BETA == version.getReleaseLevel());
    }

    public void testParseMajorMinorPointRelease2Abbrev()
        throws VersionFormatException {
        VersionData version = testParse("5.5.5-b");

        assertTrue("Point ok: ", 5 == version.getPoint());
        assertTrue(
            "ReleaseLevel ok: ",
            ReleaseLevel.BETA == version.getReleaseLevel());
    }
    
	public void testParseMajorMinorPointRelease3()
		   throws VersionFormatException {
		   VersionData version = testParse("5.5.5-snapshot");

		   assertTrue("Point ok: ", 5 == version.getPoint());
		   assertTrue(
			   "ReleaseLevel ok: ",
			   ReleaseLevel.SNAPSHOT == version.getReleaseLevel());
	   }

	public void testParseMajorMinorPointRelease3Upper()
			   throws VersionFormatException {
			   VersionData version = testParse("5.5.5-SNAPSHOT");

			   assertTrue("Point ok: ", 5 == version.getPoint());
			   assertTrue(
				   "ReleaseLevel ok: ",
				   ReleaseLevel.SNAPSHOT == version.getReleaseLevel());
		   }

    
    public void testParseMajorMinorPointReleaseBuild()
        throws VersionFormatException {
        VersionData version = testParse("5.5.5-beta-20030201");

        assertTrue("Point ok: ", 5 == version.getPoint());
        assertTrue(
            "ReleaseLevel ok: ",
            ReleaseLevel.BETA == version.getReleaseLevel());
        assertTrue(
            "BuildNumber ok: ",
            "20030201".equals(Integer.toString(version.getBuildNumber())));
    }

    private VersionData testParse(String input) throws VersionFormatException {
        VersionData version = m_format.parseVersionData(input);

        assertNotNull("Returned ok: " + input, version);
        assertTrue("Major ok: " + input, 5 == version.getMajor());
        assertTrue("Minor ok: " + input, 5 == version.getMinor());

        return version;
    }

    // public void testAll() throws VersionFormatException {
    //    for (Iterator i = VersionData.getAllIterator(); i.hasNext();) {
    //         VersionData version1 = (VersionData) i.next();
    //         String representation = m_format.toVersionString(version1);
    //         VersionData version2 = m_format.parseVersion(representation);
    //
    //          assertEquals("Create/Parse for : " + representation, version1, version2);
    //     }
    // }
}



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click