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

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

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

--- NEW FILE: ArtifactInstanceTest.java ---
/*
 * Created on Jul 15, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.apache.depot.update;

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

import junit.framework.TestCase;

import org.apache.depot.update.artifact.ArtifactLocator;
import org.apache.depot.update.artifact.ArtifactType;
import org.apache.depot.update.util.net.VirtualResourceLocator;
import org.apache.depot.version.Version;
import org.apache.depot.version.impl.ApacheVersion;
import org.apache.depot.version.specification.ApacheVersionSpecification;
import org.apache.depot.version.specification.formatting.VersionFormatException;
import org.apache.depot.version.specification.formatting.format.ApacheVersionFormat;

/**
 * @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
 */
public class ArtifactInstanceTest extends TestCase {
	
	Artifact artifact;
	VirtualResourceLocator vrl;
	ArtifactLocator locator;
	
	public ArtifactInstanceTest(String name) {
		super(name);
	}
	
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();

		artifact = new Artifact("identifier");
		vrl = new VirtualResourceLocator("http://somewhere");
		locator = new ArtifactLocator("junit","jar",vrl);
		
	}
	
	public void testEquals() {		
		ArtifactInstance instance1 = new ArtifactInstance(artifact,locator);
		ArtifactInstance instance2 = new ArtifactInstance(artifact,locator);
		
		assertEquals(instance1, instance2);
	}
	
	public void testClone() {
		ArtifactInstance instance1 = new ArtifactInstance(artifact,locator);
		ArtifactInstance instance2 = (ArtifactInstance)instance1.clone();
		
		assertEquals(instance1, instance2);
	}

	public void testGetIdentifier() {
		ArtifactInstance instance1 = new ArtifactInstance(artifact,locator);

		assertEquals(artifact.getIdentifier(), instance1.getIdentifier());
	}

	public void testGetSelectionObject() {
		
	}

	public void testGetArtifact() {
	}

	public void testGetLocator() {
	}

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

	/**
	 * @param i
	 * @param i2
	 * @return
	 * @throws VersionFormatException
	 */
	public static Version getTestVersion(int major, int minor) throws VersionFormatException {
		ApacheVersionFormat format = new ApacheVersionFormat();
		return format.parseVersion(major+"."+minor);
	}

	public static ArtifactInstance getTestArtifactInstance() throws VersionFormatException {
		return getTestArtifactInstance("test");
	}

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

	public static ArtifactInstance getTestArtifactInstance(String name,
			ArtifactType type) throws VersionFormatException {
		return getTestArtifactInstance(name, getTestVersion(1, 1), type);
	}

	public static ArtifactInstance getTestArtifactInstance(String name,
			Version version, ArtifactType type) {
		return getTestArtifactInstance(name,version,type,".test");
	}

	public static ArtifactInstance getTestArtifactInstance(String name,
			Version version, ArtifactType type, String extn) {
		return new ArtifactInstance(
				new Artifact("test", name, type, version), 
				new ArtifactLocator(name,extn,
						new VirtualResourceLocator("http://somewhere/" + name)));
	}

}



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