krysalis-update/src/test/java/org/apache/depot/update/files DefaultArtifactAnalyzerTests.java,NONE,1.1 ArtifactAnalyzerTests.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:15 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/test/java/org/apache/depot/update/files
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/test/java/org/apache/depot/update/files
Added Files:
DefaultArtifactAnalyzerTests.java ArtifactAnalyzerTests.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: ArtifactAnalyzerTests.java ---
/*
* Copyright 2000-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.files;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.depot.common.log.Logger;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.update.Artifact;
import org.apache.depot.update.ArtifactInstance;
import org.apache.depot.update.UpdateException;
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.impl.ApacheVersion;
/**
* @author arb_jack
*/
public class ArtifactAnalyzerTests extends TestCase {
private IArtifactFilenameAnalyzer m_analyzer = null;
static {
Logger.testInit();
}
public ArtifactAnalyzerTests(String name) {
super(name);
}
public void setUp() throws Exception {
m_analyzer = new DefaultArtifactFilenameAnalyzer(VirtualResourceLocator.getTestVRL());
}
public void testArtifacts() throws Exception {
List testPatterns = new ArrayList();
String filename1 = "mystuff-1.2.jar";
testPatterns.add(filename1);
// Ought be jsut one thing in the list...
List expectedResults = new ArrayList();
expectedResults.add(
new ArtifactInstance(
new Artifact("mystuff",
"mystuff",
ArtifactType.JAVA_BINARY,
new ApacheVersion("1.2")),
new ArtifactLocator(
filename1,
"jar",
VirtualResourceLocator.getTestVRL())));
checkArtifactList(testPatterns, expectedResults);
}
public void testArtifacts1() throws Exception {
List testPatterns = new ArrayList();
String filename1 = "mystuff.jar";
testPatterns.add(filename1);
// Ought be jsut one thing in the list...
List expectedResults = new ArrayList();
expectedResults.add(
new ArtifactInstance(
new Artifact(
"mystuff",
"mystuff",
ArtifactType.JAVA_BINARY,null),
new ArtifactLocator(
filename1,
"jar",
VirtualResourceLocator.getTestVRL())));
checkArtifactList(testPatterns, expectedResults);
}
public void testArtifacts2() throws Exception {
List testPatterns = new ArrayList();
String filename1 = "mystuff-1.2.jar";
String filename2 = ".mystuff-1.2.jar";
testPatterns.add(filename1);
testPatterns.add(filename2);
// Ought be jsut one thing in the list...
List expectedResults = new ArrayList();
expectedResults.add(
new ArtifactInstance(
new Artifact(
"mystuff",
"mystuff",
ArtifactType.JAVA_BINARY,
new ApacheVersion("1.2")),
new ArtifactLocator(
filename1,
"jar",
VirtualResourceLocator.getTestVRL())));
checkArtifactList(testPatterns, expectedResults);
}
public void testArtifacts3() 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 ArtifactInstance(
new Artifact(
"mystuff",
"mystuff",
ArtifactType.JAVA_BINARY,
new ApacheVersion("1.2")),
new ArtifactLocator(
filename1,
"jar",
VirtualResourceLocator.getTestVRL())));
//expectedResults.add("mystuff-1.2.jar.md5");
checkArtifactList(testPatterns, expectedResults);
}
public void testArtifacts4() throws Exception {
List testPatterns = new ArrayList();
String filename1 = "my-stuff.jar";
testPatterns.add(filename1);
// Ought be just one thing in the list...
List expectedResults = new ArrayList();
expectedResults.add(
new ArtifactInstance(
new Artifact("my-group","my-stuff",
ArtifactType.JAVA_BINARY, null),
new ArtifactLocator(filename1,
"jar",
VirtualResourceLocator.getTestVRL())));
checkArtifactList(testPatterns, expectedResults);
}
private void checkArtifactList(List patterns, List resources)
throws UpdateException {
List extractedArtifacts = m_analyzer.determineArtifacts(patterns);
assertNotNull("Artifacts", extractedArtifacts);
DebugUtils.dump(extractedArtifacts);
DebugUtils.dump(resources);
assertEquals("Same Result List", resources, extractedArtifacts);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(ArtifactAnalyzerTests.class);
}
}
--- NEW FILE: DefaultArtifactAnalyzerTests.java ---
/*
* Copyright 2000-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.files;
import java.util.List;
import junit.framework.TestCase;
import org.apache.depot.common.log.Logger;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.common.util.note.AnnotationScratchpad;
import org.apache.depot.update.Artifact;
import org.apache.depot.update.ArtifactInstance;
import org.apache.depot.update.UpdateException;
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.VersionImporter;
import org.apache.depot.update.impl.util.DiffTool;
/**
* @author arb_jack
*/
public class DefaultArtifactAnalyzerTests extends TestCase {
private DefaultArtifactFilenameAnalyzer m_analyzer = null;
public DefaultArtifactAnalyzerTests(String name) {
super(name);
Logger.testInit();
}
public void setUp() throws Exception {
m_analyzer = new DefaultArtifactFilenameAnalyzer(
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 UpdateException {
String testPattern = "mystuff-1.2.fred";
List testList = new ArrayList();
testList.add("fred");
checkExtensionList(testPattern, testList);
//:TODO: Do we want UNKNOWN type?
checkArtifact(testPattern, createArtifact(testPattern, "mystuff",
"1.2", null, "fred"));
}
public void testExtensions2() throws UpdateException {
String testPattern = "mystuff-1.2-src.fred";
List testList = new ArrayList();
testList.add("fred");
checkExtensionList(testPattern, testList);
checkArtifact(testPattern, createArtifact(testPattern, "mystuff",
"1.2", "src", "fred"));
}
public void testExtensions3() throws UpdateException {
String testPattern = "mystuff-1.2-src.fred.Z";
List testList = new ArrayList();
testList.add("fred.Z");
testList.add("Z");
checkExtensionList(testPattern, testList);
// :TODO: Is lower case ok?
checkArtifact(testPattern, createArtifact(testPattern, "mystuff",
"1.2", "src", "fred.z"));
}
*/
public void testDated1() throws UpdateException {
String testPattern = "commons-vfs-20030518103800.jar";
checkArtifact(testPattern, createArtifact(testPattern, "commons-vfs",
"20030518103800", "java", "jar"));
}
private ArtifactInstance createArtifact(String filename, String name, String v,
String t, String e) throws UpdateException {
Version version = null;
if (null != v) {
try {
version = VersionImporter.importVersion(v);
} catch (Exception ex) {
}
}
ArtifactType artifactType = null;
if (null != t )
artifactType = ArtifactType.getFromString(t);
else
artifactType = ArtifactType.UNKNOWN;
return new ArtifactInstance(new Artifact(name, name, artifactType, version),
new ArtifactLocator(filename,e,
new VirtualResourceLocator(
new VirtualResourceLocator(
"http://www.apache.org/depot"), filename)));
}
private void checkArtifact(String pattern, ArtifactInstance expected)
throws UpdateException {
DebugUtils.printSeparator();
DebugUtils.dump(true, expected);
ArtifactInstance instance = m_analyzer.determineArtifact(pattern);
assertNotNull("Determined something", instance);
DebugUtils.printSeparator();
DebugUtils.dump(true, instance);
AnnotationScratchpad pad =
DiffTool.diff(
expected,
instance);
DebugUtils.dump(pad);
assertEquals("Same Artifact", expected, instance);
}
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(DefaultArtifactAnalyzerTests.class);
}
}
-------------------------------------------------------
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/