krysalis-update/src/test/java/org/apache/depot/update/usecases ArtifactTests.java,NONE,1.1 FileHelper.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:09 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/test/java/org/apache/depot/update/usecases
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/test/java/org/apache/depot/update/usecases
Added Files:
ArtifactTests.java FileHelper.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: FileHelper.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.usecases;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
class FileHelper {
private List m_testFiles = new LinkedList();
public void setUp() {
}
public void tearDown() {
Iterator fileIter = m_testFiles.iterator();
while (fileIter.hasNext()) {
File file = (File) fileIter.next();
file.delete();
}
}
/**
* Create a file for testing. Will also register the file for
* cleanup at the end of the testcase
* @param baseDir Base directory for the file
* @param name Name of the file (may contain a path)
* @return New File object
* @throws java.io.IOException If error occurs creating a file
*/
public File setupActualFile( File baseDir, String name ) throws IOException {
File theFile = new File( baseDir, name );
if( !theFile.exists() ) {
theFile.getParentFile().mkdirs();
theFile.createNewFile();
}
m_testFiles.add( theFile );
return theFile;
}
/**
* Create file that we expect a testcase to create. Will also register the file for
* cleanup at the end of the testcase
* @param baseDir Base directory for the file
* @param name Name of the file (may contain a path)
* @return New File object
*/
public File setupExpectedFile(File baseDir, String name) {
File theFile = new File( baseDir, name );
m_testFiles.add( theFile );
return theFile;
}
}
--- 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.usecases;
import java.io.File;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.depot.update.Artifact;
import org.apache.depot.update.ArtifactInstance;
import org.apache.depot.update.ArtifactUpdater;
import org.apache.depot.update.ArtifactUpdaterFactory;
import org.apache.depot.update.Repository;
import org.apache.depot.update.repository.DefaultRepository;
import org.apache.depot.update.repository.RepositorySet;
import org.apache.depot.update.util.io.ResolvedFile;
import org.apache.depot.update.util.net.VirtualResourceLocator;
public class ArtifactTests extends TestCase {
private ResolvedFile m_repoDir = ResolvedFile.resolve("src/artifacts/test/usecase/find/repo");
private FileHelper m_fileHelper = new FileHelper();
protected void setUp() {
if (!m_repoDir.exists()) {
m_repoDir.mkdirs();
}
m_fileHelper.setUp();
}
protected void tearDown() {
m_fileHelper.tearDown();
}
/**
* Start simple,
* Find a single jar in a repository
*/
public void testFindSingleJar() throws Exception {
File artifactFile =
m_fileHelper.setupActualFile(
m_repoDir,
"gorilla/jars/gorilla-1.0.jar");
// 1. User configures Depot
ArtifactUpdater updater =
ArtifactUpdaterFactory.getDefaultUpdater();
Repository fileRepo =
new DefaultRepository("test", m_repoDir.toURL().toString());
RepositorySet repos = new RepositorySet();
repos.addRepository(fileRepo);
// 2. User supplies artifact query and asks Depot process it
Artifact artifact = new Artifact("gorilla");
ArtifactInstance instance = updater.getInstance(artifact);
// 3. Depot examines query to extract artifact information
// 4. Depot queries repositories for artifact
// 5. Depot reports results to User
assertNotNull("Should get a result", instance);
VirtualResourceLocator expected =
new VirtualResourceLocator(ResolvedFile.resolve(artifactFile));
assertEquals(
"Got unexpected location",
expected,
instance.getLocator().getLocation());
}
public static Test suite() {
return new TestSuite(ArtifactTests.class);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
-------------------------------------------------------
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/