ruper2/src/test/core/org/krysalis/ruper2/files DefaultResourceAnalyzerTests.java,NONE,1.1 ResourceAnalyzerTests.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/test/core/org/krysalis/ruper2/files
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/test/core/org/krysalis/ruper2/files

Added Files:
	DefaultResourceAnalyzerTests.java ResourceAnalyzerTests.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: DefaultResourceAnalyzerTests.java ---
/*
 * Created on Aug 27, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.files;

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

import junit.framework.TestCase;

import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.Resource;
import org.krysalis.ruper2.resource.ResourceType;
import org.krysalis.version.Version;
import org.krysalis.version.impl.VersionImporter;

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

	private DefaultResourceFilenameAnalyzer m_analyzer = null;
	private VirtualResourceLocator m_http = null;
	private VirtualResourceLocator m_file = null;

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

	public void setUp() throws Exception {
		m_analyzer =
			new DefaultResourceFilenameAnalyzer(
				VirtualResourceLocator.getTestVRL());
	}

	public void testSeparator() throws Exception {
		assertEquals("Found Underscore", 1, m_analyzer.findSeparator("A_B"));
		assertEquals("Found Dash", 1, m_analyzer.findSeparator("A-B"));

	}

	public void testVersionSeparator() throws Exception {
		assertEquals(
			"Found Dash Version",
			3,
			m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
		assertEquals(
			"Found Underscore Version",
			3,
			m_analyzer.findSeparatorBeforeVersionNumbers("A-B_1"));
		assertEquals(
			"Found Underscore then Dash Version",
			3,
			m_analyzer.findSeparatorBeforeVersionNumbers("A_B-1"));
		assertEquals(
			"Found Dash then Dash Version",
			3,
			m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
	}

	public void testExtensions1() throws RuperException {
		String testPattern = "mystuff-1.2.fred";
		List testList = new ArrayList();
		testList.add("fred");
		checkExtensionList(testPattern, testList);

		checkResource(
			testPattern,
			createResource(testPattern, "mystuff", "1.2", null));
	}

	public void testExtensions2()  throws RuperException{
		String testPattern = "mystuff-1.2-src.fred";
		List testList = new ArrayList();
		testList.add("fred");
		checkExtensionList(testPattern, testList);
		checkResource(
			testPattern,
			createResource(testPattern, "mystuff", "1.2", "src"));
	}

	public void testExtensions3()  throws RuperException{
		String testPattern = "mystuff-1.2-src.fred.Z";
		List testList = new ArrayList();
		testList.add("fred.Z");
		testList.add("Z");
		checkExtensionList(testPattern, testList);
		checkResource(
			testPattern,
			createResource(testPattern, "mystuff", "1.2", "src"));
	}

	private Resource createResource(
		String filename,
		String name,
		String v,
		String t)
		throws RuperException {
		Version version = null;
		if (null != v) {
			try {
				version = VersionImporter.importVersion(v);
			}
			catch (Exception e) {
			}
		}

		ResourceType resourceType = null;
		resourceType = ResourceType.getFromString(t);

		return new Resource(
			name,
			version,
			resourceType,
			filename,
			new VirtualResourceLocator(filename));
	}

	private void checkResource(String pattern, Resource expected)
		throws RuperException {
			
		//DebugUtils.printSeparator();
		//DebugUtils.dump(expected);
			
		Resource resource = m_analyzer.determineResource(pattern);

		
		assertNotNull("Determined something", resource);

		//DebugUtils.printSeparator();
		//DebugUtils.dump(resource);
		assertEquals("Same Resource", expected, resource);
	}

	private void checkExtensionList(String pattern, List extns) {
		List probableExtns = m_analyzer.extractProbableExtensions(pattern);

		assertEquals("Same Result List", extns, probableExtns);
	}

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

--- NEW FILE: ResourceAnalyzerTests.java ---
/*
 * Created on Aug 27, 2003
 */
package org.krysalis.ruper2.files;

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

import junit.framework.TestCase;

import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.Resource;
import org.krysalis.ruper2.resource.ResourceType;
import org.krysalis.version.impl.KrysalisVersion;

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

	private ResourceFilenameAnalyzer m_analyzer = null;

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

	public void setUp() throws Exception {
		m_analyzer = new DefaultResourceFilenameAnalyzer(VirtualResourceLocator.getTestVRL());
	}

	public void testResources() throws Exception {
		List testPatterns = new ArrayList();
		String filename1 = "mystuff-1.2.jar";
		testPatterns.add(filename1);
		testPatterns.add(filename1+".md5");

		// Ought be jsut one thing in the list...
		List expectedResults = new ArrayList();
		expectedResults.add(
			new Resource(
				"mystuff",
				new KrysalisVersion("1.2"),
				ResourceType.JAVA_BINARY,
				filename1,
				VirtualResourceLocator.getTestVRL()));
		expectedResults.add("mystuff-1.2.jar.md5");

		checkResourceList(testPatterns, expectedResults);
	}

	private void checkResourceList(List patterns, List resources)
		throws RuperException {
		List extractedResources = m_analyzer.determineResources(patterns);

		assertNotNull("Resources", extractedResources);
		
		assertEquals("Same Result List", resources, extractedResources);
	}

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




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.