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

Nick Chalko <[email protected]> Tue, 09 Nov 2004 08:04:50 +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-serv4217/src/test/java/org/krysalis/version/impl/apache

Added Files:
	ApacheVersionTest.java ApacheVersionSpecTest.java 
Log Message:
More test work.

--- NEW FILE: ApacheVersionSpecTest.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 java.util.Iterator;


import junit.framework.TestCase;

import org.krysalis.version.VersionException;
import org.krysalis.version.VersionSpecification;
import org.krysalis.version.VersionSpecificationFactory;
import org.krysalis.version.impl.apache.ApacheVersionSpecification;



/**
 * @version $Revision: 1.1 $
 */
public class ApacheVersionSpecTest extends TestCase {

    /*
     * Class under test for void ApacheVersion(String)
     */
    public void testSpecs1() throws VersionException {
        //Logger.testInit();
        
		
		checkVersionSpecification(
				VersionImplementationConstants.APACHE_VERSION_ID,
				ApacheVersionSpecification.class);
    }

    
    public void testSpecs2()  throws VersionException{
    	int count = 0;
    
    	for (Iterator i =
			VersionSpecificationFactory.getRegisteredSpecificationIds().iterator();
			i.hasNext();
			) {    	
    		VersionSpecification spec = VersionSpecificationFactory.createVersionSpecificationFromId((String)i.next());
    		count ++;
    		// Logger.getLogger().debug("Spec: " + spec);
    	}
    	
    	assertEquals("Registered Versions", count,6);
    }
    private void checkVersionSpecification(String id, Class clazz) throws VersionException
    {
    	assertEquals(clazz.getName(), 
    			VersionSpecificationFactory.createVersionSpecificationFromId(id).getClass(), clazz);
    }
}
--- NEW FILE: ApacheVersionTest.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 org.krysalis.version.VersionException;
import org.krysalis.version.VersionFormatException;
import org.krysalis.version.VersionTestCase;
import org.krysalis.version.impl.CompoundVersion;
import org.krysalis.version.impl.data.ReleaseLevel;

/**
 * @version $Revision: 1.1 $
 */
public class ApacheVersionTest extends VersionTestCase {

	/**
	 * @param specification
	 */
	public ApacheVersionTest() {
		super(ApacheVersion.UNKNOWN.getSpecification());
	}

	/*
	 * Class under test for void ApacheVersion(String)
	 */
	public void testApacheVersionString() throws VersionException {
		//Logger.testInit();

		assertApacheVersion("1.2.1", 1, 2, 1, ReleaseLevel.DEFAULT);
		assertApacheVersion("1.2.1-dev", 1, 2, 1, ReleaseLevel.DEVELOPMENT);
		assertApacheVersion("1.2", 1, 2, -1, ReleaseLevel.DEFAULT);
		assertApacheVersion("1.2.99-b", 1, 2, 99, ReleaseLevel.BETA);
	}

	// :TODO: 1.0.0 ! 1.0.-1 == UNSET
	// Maybe it should be....
	// :TODO: final != rel 
	// Maybe it should be....
	
	
	public void testEquals() throws VersionFormatException {
		assertAllEqual(new String[] { "1","1", "1.0", "1.0","1.0-rel" });
	}

	public void testNonCompatible() throws VersionFormatException {
		assertVersionInOrder(new String[] { "1", "2" }, INCOMPATIBLE);
	}

	// :TODO:
	// "1.1.0", "1.1.2" has same problem as above 0 != UNSET
	// :TODO:
	// "1.1" is 1.1 release, that is not compatible with 1.1 < release
	public void testCompatible() throws VersionFormatException {
		assertVersionInOrder(new String[] { "1.1-a7","1.1-beta1","1.1-rc2"}, FORWARD);
	}

	/**
	 * @param versionString
	 * @param expectedMajor
	 * @param expectedMinor
	 * @param expectedPoint
	 * @param expectedReleaseLevel
	 * @throws VersionException
	 */
	private void assertApacheVersion(final String versionString,
			int expectedMajor, int expectedMinor, int expectedPoint,
			ReleaseLevel expectedReleaseLevel) throws VersionException {
		ApacheVersion av = new ApacheVersion(versionString);
		assertVersion(versionString, av, expectedMajor, expectedMinor,
				expectedPoint, expectedReleaseLevel);
	}

	/**
	 * @param versionString
	 * @param av
	 * @param expectedMajor
	 * @param expectedMinor
	 * @param expectedPoint
	 * @param expectedReleaseLevel
	 */
	private void assertVersion(final String versionString, ApacheVersion av,
			int expectedMajor, int expectedMinor, int expectedPoint,
			ReleaseLevel expectedReleaseLevel) {
		assertCompondVersion(versionString, av, expectedMajor, expectedMinor,
				expectedPoint);
		assertEquals(versionString + ".releaseLevel", expectedReleaseLevel, av
				.getReleaseLevelObject());
	}

	/**
	 * @param versionString
	 * @param av
	 * @param expectedMajor
	 * @param expectedMinor
	 * @param expectedPoint
	 */
	private void assertCompondVersion(final String versionString,
			CompoundVersion av, int expectedMajor, int expectedMinor,
			int expectedPoint) {
		assertEquals(versionString + ".major", expectedMajor, av.getMajor());
		assertEquals(versionString + ".minor", expectedMinor, av.getMinor());
		assertEquals(versionString + ".point", expectedPoint, av.getPoint());
	}
}


-------------------------------------------------------
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