krysalis-update/src/test/java/org/apache/depot/update/artifact ArtifactTests.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:20 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/test/java/org/apache/depot/update/artifact
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/test/java/org/apache/depot/update/artifact

Added Files:
	ArtifactTests.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: ArtifactTests.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.apache.depot.update.artifact;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.apache.depot.common.log.Logger;
import org.apache.depot.update.Artifact;
import org.apache.depot.update.ArtifactInstanceTest;
import org.apache.depot.version.Version;
import org.apache.depot.version.specification.formatting.VersionFormatException;


/**
 * @author arb_jack
 */
public class ArtifactTests extends TestCase {

	static {
		Logger.testInit();
	}

	public ArtifactTests(String name) {
		super(name);
	}

	public void setUp() throws Exception {

	}

//	public void testArtifactEquality1() throws Exception {
//		ArtifactInstance i1 = ArtifactInstance.getTestArtifact();
//		ArtifactInstance i2 = ArtifactInstance.getTestArtifact();
//
//		assertEquals("Same are equal", i1, i2);
//		assertTrue("Same are equal", i1.equals(i2));
//		assertEquals("Same are same hash", i1.hashCode(), i2.hashCode());
//	}
//
//	public void testArtifactEquality2() throws Exception {
//		ArtifactInstance i1 = ArtifactInstance.getTestArtifact();
//		ArtifactInstance i2 = ArtifactInstance.getTestArtifact("bogus");
//
//		assertFalse("Different are NOT equal", i1.equals(i2));
//		assertFalse(
//			"Different are NOT equal hash",
//			i1.hashCode() == i2.hashCode());
//	}
//
//	public void testArtifactEquality3() throws Exception {
//		ArtifactInstance i1 = ArtifactInstance.getTestArtifact();
//		ArtifactInstance i2 = (ArtifactInstance)i1.clone();
//
//		assertEquals("Clones are equal", i1, i2);
//		assertTrue("Clones are equal", i1.equals(i2));
//		assertEquals("Clones are same hash", i1.hashCode(), i2.hashCode());
//	}
//
//	public void testArtifactEquality4() throws Exception {
//		ArtifactInstance i1 = ArtifactInstance.getTestArtifact();
//		ArtifactInstance i2 = (ArtifactInstance)i1.clone(); 
//		
//		i2.getLocator().setExtension("bogus");
//
//		assertFalse("Different are NOT equal", i1.equals(i2));
//		assertFalse(
//			"Different are NOT equal hash",
//			i1.hashCode() == i2.hashCode());
//	}

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

	//
	//	-----------------------------------------------------------------
	//
	public static List getTestArtifactList(String group, int count) throws VersionFormatException {
		List ArtifactList = new ArrayList();
	
		// Populate with some test Artifacts...
		for (int i = 0; i < count; ++i) {
			String name = group + Integer.toString(1 + i);
			ArtifactList.add(ArtifactTests.getTestArtifact(name,
					ArtifactInstanceTest.getTestVersion(1, i),
					ArtifactType.JAVA_BINARY));
			ArtifactList.add(ArtifactTests.getTestArtifact(name,
					ArtifactInstanceTest.getTestVersion(1, i),
					ArtifactType.SOURCE_CODE));
	
			// :TODO: Add some randomness
		}
	
		return ArtifactList;
	}

	public static Artifact getTestArtifact() throws VersionFormatException {
		return getTestArtifact("test");
	}

	public static Artifact getTestArtifact(String name) throws VersionFormatException {
		return getTestArtifact(name, ArtifactType.JAVA_BINARY);
	}

	public static Artifact getTestArtifact(String name, ArtifactType type) throws VersionFormatException {
		return getTestArtifact(name, ArtifactInstanceTest.getTestVersion(1, 1), type);
	}

	public static Artifact getTestArtifact(String name, Version version,
			ArtifactType type) {
		return new Artifact(name, name, type.toString(), version);
	}
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/