summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2009-10-05 11:25:43 -0700
committerShawn O. Pearce <spearce@spearce.org>2009-11-02 17:53:58 -0800
commit1e84e8ad935aa22ca0f6f1d00dfed4a07878ef6f (patch)
tree4247ab81e185bfe3760e00ec79dbcad98fc7220b /org.eclipse.jgit.test
parent49aac32500985440c8c7599ccf953f011da8a763 (diff)
downloadjgit-1e84e8ad935aa22ca0f6f1d00dfed4a07878ef6f.tar.gz
jgit-1e84e8ad935aa22ca0f6f1d00dfed4a07878ef6f.zip
Refactor RepositoryTestCase to use LocalDiskRepository instead
Change-Id: I07014d1b8cc2fab0761d644a12e4ae04f0adf3ef Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jgit.test/pom.xml5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java97
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java234
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java51
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java8
11 files changed, 79 insertions, 359 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 225611ba9b..32d5efdfc4 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: com.jcraft.jsch,
junit.framework,
junit.textui,
+ org.eclipse.jgit.junit,
org.eclipse.jgit.diff,
org.eclipse.jgit.dircache,
org.eclipse.jgit.errors,
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index 2eb8f9aa78..6938ea60a0 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -67,6 +67,11 @@
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jgit</groupId>
+ <artifactId>org.eclipse.jgit.junit</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java
index 644c7b366c..9e83aa0e1e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java
@@ -72,7 +72,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
IOException {
// Create a new object in a new pack, and test that it is present.
//
- final Repository eden = createNewEmptyRepo();
+ final Repository eden = createBareRepository();
final RevObject o1 = writeBlob(eden, "o1");
pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
@@ -84,7 +84,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
// object into a different pack file, with some other object. We
// still should be able to access the objects.
//
- final Repository eden = createNewEmptyRepo();
+ final Repository eden = createBareRepository();
final RevObject o1 = writeBlob(eden, "o1");
final File[] out1 = pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
@@ -108,7 +108,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
throws IncorrectObjectTypeException, IOException {
// Create an object and pack it.
//
- final Repository eden = createNewEmptyRepo();
+ final Repository eden = createBareRepository();
final RevObject o1 = writeBlob(eden, "o1");
final File[] out1 = pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
@@ -141,7 +141,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
// object into a different pack file, with some other object. We
// still should be able to access the objects.
//
- final Repository eden = createNewEmptyRepo();
+ final Repository eden = createBareRepository();
final RevObject o1 = writeBlob(eden, "o1");
final File[] out1 = pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java
deleted file mode 100644
index 2e94632cee..0000000000
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2009, Google Inc.
- * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2009, Yann Simon <yann.simon.fr@gmail.com>
- * and other copyright owners as documented in the project's IP log.
- *
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package org.eclipse.jgit.lib;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimeZone;
-
-import org.eclipse.jgit.util.SystemReader;
-
-class MockSystemReader extends SystemReader {
- final Map<String, String> values = new HashMap<String, String>();
-
- FileBasedConfig userGitConfig;
-
- MockSystemReader() {
- init(Constants.OS_USER_NAME_KEY);
- init(Constants.GIT_AUTHOR_NAME_KEY);
- init(Constants.GIT_AUTHOR_EMAIL_KEY);
- init(Constants.GIT_COMMITTER_NAME_KEY);
- init(Constants.GIT_COMMITTER_EMAIL_KEY);
- userGitConfig = new FileBasedConfig(null);
- }
-
- private void init(final String n) {
- values.put(n, n);
- }
-
- public String getenv(String variable) {
- return values.get(variable);
- }
-
- public String getProperty(String key) {
- return values.get(key);
- }
-
- public FileBasedConfig openUserConfig() {
- return userGitConfig;
- }
-
- public String getHostname() {
- return "fake.host.example.com";
- }
-
- @Override
- public long getCurrentTime() {
- return 1250379778668L; // Sat Aug 15 20:12:58 GMT-03:30 2009
- }
-
- @Override
- public int getTimezone(long when) {
- return TimeZone.getTimeZone("GMT-3:30").getOffset(when);
- }
-}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
index e72b7e2156..f3b150fa45 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009, Christian Halstrick <christian.halstrick@sap.com>
* Copyright (C) 2009, Christian Halstrick, Matthias Sohn, SAP AG
+ * Copyright (C) 2009, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -61,8 +62,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// written
final Tree t = new Tree(db);
addFileToTree(t, "i-am-a-file", "and this is the data in me\n");
- commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz),
- new PersonIdent(jcommitter, commitTime, tz));
+ commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
+ new PersonIdent(committer, commitTime, tz));
commitTime += 100;
assertTrue(
"Reflog for HEAD still contain no entry",
@@ -74,8 +75,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// do one commit and check that reflog size is increased to 1
addFileToTree(t, "i-am-another-file", "and this is other data in me\n");
- commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz),
- new PersonIdent(jcommitter, commitTime, tz));
+ commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
+ new PersonIdent(committer, commitTime, tz));
commitTime += 100;
assertTrue(
"Reflog for HEAD should contain one entry",
@@ -88,8 +89,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// do one commit and check that reflog size is 2
addFileToTree(t, "i-am-anotheranother-file",
"and this is other other data in me\n");
- commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz),
- new PersonIdent(jcommitter, commitTime, tz));
+ commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
+ new PersonIdent(committer, commitTime, tz));
assertTrue(
"Reflog for HEAD should contain two entries",
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
index c0591755f4..f05889308d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
@@ -64,7 +64,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
}
public void testBareFileKey() throws IOException {
- Repository bare = createNewEmptyRepo(true);
+ Repository bare = createBareRepository();
File gitdir = bare.getDirectory();
File parent = gitdir.getParentFile();
String name = gitdir.getName();
@@ -92,7 +92,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
}
public void testFileKeyOpenNew() throws IOException {
- final Repository n = createNewEmptyRepo(true);
+ final Repository n = createBareRepository();
final File gitdir = n.getDirectory();
n.close();
recursiveDelete(gitdir);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
index 08e701ab50..2cbfc682ca 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
@@ -53,6 +53,7 @@ import java.util.LinkedList;
import junit.framework.TestCase;
import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
/**
@@ -115,9 +116,9 @@ public class RepositoryConfigTest extends TestCase {
final MockSystemReader mockSystemReader = new MockSystemReader();
SystemReader.setInstance(mockSystemReader);
final String hostname = mockSystemReader.getHostname();
- final Config userGitConfig = mockSystemReader.userGitConfig;
+ final Config userGitConfig = mockSystemReader.openUserConfig();
final Config localConfig = new Config(userGitConfig);
- mockSystemReader.values.clear();
+ mockSystemReader.clearProperties();
String authorName;
String authorEmail;
@@ -129,7 +130,7 @@ public class RepositoryConfigTest extends TestCase {
assertEquals(Constants.UNKNOWN_USER_DEFAULT + "@" + hostname, authorEmail);
// the system user name is defined
- mockSystemReader.values.put(Constants.OS_USER_NAME_KEY, "os user name");
+ mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "os user name");
localConfig.uncache(UserConfig.KEY);
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
assertEquals("os user name", authorName);
@@ -140,8 +141,8 @@ public class RepositoryConfigTest extends TestCase {
}
// the git environment variables are defined
- mockSystemReader.values.put(Constants.GIT_AUTHOR_NAME_KEY, "git author name");
- mockSystemReader.values.put(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email");
+ mockSystemReader.setProperty(Constants.GIT_AUTHOR_NAME_KEY, "git author name");
+ mockSystemReader.setProperty(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email");
localConfig.uncache(UserConfig.KEY);
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
index ac8881b1fc..ecbb7e073a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
@@ -1,6 +1,9 @@
/*
+ * Copyright (C) 2009, Google Inc.
+ * Copyright (C) 2008-2009, Jonas Fonseca <fonseca@diku.dk>
* Copyright (C) 2007-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2006-2007, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2009, Yann Simon <yann.simon.fr@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -49,117 +52,18 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.util.JGitTestUtil;
-import org.eclipse.jgit.util.SystemReader;
/**
* Base class for most JGit unit tests.
*
* Sets up a predefined test repository and has support for creating additional
* repositories and destroying them when the tests are finished.
- *
- * A system property <em>jgit.junit.usemmap</em> defines whether memory mapping
- * is used. Memory mapping has an effect on the file system, in that memory
- * mapped files in java cannot be deleted as long as they mapped arrays have not
- * been reclaimed by the garbage collector. The programmer cannot control this
- * with precision, though hinting using <em>{@link java.lang.System#gc}</em>
- * often helps.
*/
-public abstract class RepositoryTestCase extends TestCase {
-
- protected final File trashParent = new File("trash");
-
- protected File trash;
-
- protected File trash_git;
-
- protected static final PersonIdent jauthor;
-
- protected static final PersonIdent jcommitter;
-
- static {
- jauthor = new PersonIdent("J. Author", "jauthor@example.com");
- jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com");
- }
-
- protected boolean packedGitMMAP;
-
- /**
- * Configure JGit before setting up test repositories.
- */
- protected void configure() {
- final WindowCacheConfig c = new WindowCacheConfig();
- c.setPackedGitLimit(128 * WindowCacheConfig.KB);
- c.setPackedGitWindowSize(8 * WindowCacheConfig.KB);
- c.setPackedGitMMAP("true".equals(System.getProperty("jgit.junit.usemmap")));
- c.setDeltaBaseCacheLimit(8 * WindowCacheConfig.KB);
- WindowCache.reconfigure(c);
- }
-
- /**
- * Utility method to delete a directory recursively. It is
- * also used internally. If a file or directory cannot be removed
- * it throws an AssertionFailure.
- *
- * @param dir
- */
- protected void recursiveDelete(final File dir) {
- recursiveDelete(dir, false, getClass().getName() + "." + getName(), true);
- }
-
- protected static boolean recursiveDelete(final File dir, boolean silent,
- final String name, boolean failOnError) {
- assert !(silent && failOnError);
- if (!dir.exists())
- return silent;
- final File[] ls = dir.listFiles();
- if (ls != null) {
- for (int k = 0; k < ls.length; k++) {
- final File e = ls[k];
- if (e.isDirectory()) {
- silent = recursiveDelete(e, silent, name, failOnError);
- } else {
- if (!e.delete()) {
- if (!silent) {
- reportDeleteFailure(name, failOnError, e);
- }
- silent = !failOnError;
- }
- }
- }
- }
- if (!dir.delete()) {
- if (!silent) {
- reportDeleteFailure(name, failOnError, dir);
- }
- silent = !failOnError;
- }
- return silent;
- }
-
- private static void reportDeleteFailure(final String name,
- boolean failOnError, final File e) {
- String severity;
- if (failOnError)
- severity = "Error";
- else
- severity = "Warning";
- String msg = severity + ": Failed to delete " + e;
- if (name != null)
- msg += " in " + name;
- if (failOnError)
- fail(msg);
- else
- System.out.println(msg);
- }
-
+public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected static void copyFile(final File src, final File dst)
throws IOException {
final FileInputStream fis = new FileInputStream(src);
@@ -181,18 +85,9 @@ public abstract class RepositoryTestCase extends TestCase {
protected File writeTrashFile(final String name, final String data)
throws IOException {
- File tf = new File(trash, name);
- File tfp = tf.getParentFile();
- if (!tfp.exists() && !tf.getParentFile().mkdirs())
- throw new Error("Could not create directory " + tf.getParentFile());
- final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(tf), "UTF-8");
- try {
- fw.write(data);
- } finally {
- fw.close();
- }
- return tf;
+ File path = new File(db.getWorkDir(), name);
+ write(path, data);
+ return path;
}
protected static void checkFile(File f, final String checkData)
@@ -208,46 +103,17 @@ public abstract class RepositoryTestCase extends TestCase {
}
}
+ /** Test repository, initialized for this test case. */
protected Repository db;
- private static Thread shutdownhook;
- private static List<Runnable> shutDownCleanups = new ArrayList<Runnable>();
- private static int testcount;
-
- private ArrayList<Repository> repositoriesToClose = new ArrayList<Repository>();
+ /** Working directory of {@link #db}. */
+ protected File trash;
- public void setUp() throws Exception {
+ @Override
+ protected void setUp() throws Exception {
super.setUp();
- configure();
- final String name = getClass().getName() + "." + getName();
- recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff
- trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++));
- trash_git = new File(trash, ".git").getCanonicalFile();
- if (shutdownhook == null) {
- shutdownhook = new Thread() {
- @Override
- public void run() {
- // This may look superfluous, but is an extra attempt
- // to clean up. First GC to release as many resources
- // as possible and then try to clean up one test repo
- // at a time (to record problems) and finally to drop
- // the directory containing all test repositories.
- System.gc();
- for (Runnable r : shutDownCleanups)
- r.run();
- recursiveDelete(trashParent, false, null, false);
- }
- };
- Runtime.getRuntime().addShutdownHook(shutdownhook);
- }
-
- final MockSystemReader mockSystemReader = new MockSystemReader();
- mockSystemReader.userGitConfig = new FileBasedConfig(new File(
- trash_git, "usergitconfig"));
- SystemReader.setInstance(mockSystemReader);
-
- db = new Repository(trash_git);
- db.create();
+ db = createWorkRepository();
+ trash = db.getWorkDir();
final String[] packs = {
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f",
@@ -259,70 +125,12 @@ public abstract class RepositoryTestCase extends TestCase {
"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
};
final File packDir = new File(db.getObjectsDirectory(), "pack");
- for (int k = 0; k < packs.length; k++) {
- copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".pack"), new File(packDir,
- packs[k] + ".pack"));
- copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".idx"), new File(packDir,
- packs[k] + ".idx"));
+ for (String n : packs) {
+ copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack"));
+ copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx"));
}
- copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(trash_git,"packed-refs"));
- }
-
- protected void tearDown() throws Exception {
- RepositoryCache.clear();
- db.close();
- for (Repository r : repositoriesToClose)
- r.close();
-
- // Since memory mapping is controlled by the GC we need to
- // tell it this is a good time to clean up and unlock
- // memory mapped files.
- if (packedGitMMAP)
- System.gc();
-
- final String name = getClass().getName() + "." + getName();
- recursiveDelete(trash, false, name, true);
- for (Repository r : repositoriesToClose)
- recursiveDelete(r.getWorkDir(), false, name, true);
- repositoriesToClose.clear();
-
- super.tearDown();
- }
-
- /**
- * Helper for creating extra empty repos
- *
- * @return a new empty git repository for testing purposes
- *
- * @throws IOException
- */
- protected Repository createNewEmptyRepo() throws IOException {
- return createNewEmptyRepo(false);
- }
-
- /**
- * Helper for creating extra empty repos
- *
- * @param bare if true, create a bare repository.
- * @return a new empty git repository for testing purposes
- *
- * @throws IOException
- */
- protected Repository createNewEmptyRepo(boolean bare) throws IOException {
- final File newTestRepo = new File(trashParent, "new"
- + System.currentTimeMillis() + "." + (testcount++)
- + (bare ? "" : "/") + ".git").getCanonicalFile();
- assertFalse(newTestRepo.exists());
- final Repository newRepo = new Repository(newTestRepo);
- newRepo.create();
- final String name = getClass().getName() + "." + getName();
- shutDownCleanups.add(new Runnable() {
- public void run() {
- recursiveDelete(newTestRepo, false, name, false);
- }
- });
- repositoriesToClose.add(newRepo);
- return newRepo;
+ copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(db
+ .getDirectory(), "packed-refs"));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
index 74e98f1d8c..f7346a61fb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
@@ -83,7 +83,7 @@ public class T0003_Basic extends RepositoryTestCase {
// open when we create it we won't write the object file out as a loose
// object (as it already exists in the pack).
//
- final Repository newdb = createNewEmptyRepo();
+ final Repository newdb = createBareRepository();
final Tree t = new Tree(newdb);
t.accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY);
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId()
@@ -101,7 +101,8 @@ public class T0003_Basic extends RepositoryTestCase {
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId()
.name());
- final File o = new File(new File(new File(trash_git, "objects"), "4b"),
+ final File o = new File(new File(
+ new File(db.getDirectory(), "objects"), "4b"),
"825dc642cb6eb9a060e54bf8d69288fbee4904");
assertFalse("Exists " + o, o.isFile());
}
@@ -115,12 +116,12 @@ public class T0003_Basic extends RepositoryTestCase {
.name());
File o;
- o = new File(new File(new File(trash_git, "objects"), "7b"),
+ o = new File(new File(new File(db.getDirectory(), "objects"), "7b"),
"b943559a305bdd6bdee2cef6e5df2413c3d30a");
assertTrue("Exists " + o, o.isFile());
assertTrue("Read-only " + o, !o.canWrite());
- o = new File(new File(new File(trash_git, "objects"), "e6"),
+ o = new File(new File(new File(db.getDirectory(), "objects"), "e6"),
"9de29bb2d1d6434b8b29ae775ad8c2e48c5391");
assertTrue("Exists " + o, o.isFile());
assertTrue("Read-only " + o, !o.canWrite());
@@ -202,8 +203,8 @@ public class T0003_Basic extends RepositoryTestCase {
t.getTreeId());
final Commit c = new Commit(db);
- c.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
- c.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
+ c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
+ c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c.setMessage("A Commit\n");
c.setTree(t);
assertEquals(t.getTreeId(), c.getTreeId());
@@ -258,7 +259,7 @@ public class T0003_Basic extends RepositoryTestCase {
t.setObjId(emptyId);
t.setType("blob");
t.setTag("test020");
- t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
+ t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
t.setMessage("test020 tagged\n");
t.tag();
assertEquals("6759556b09fbb4fd8ae5e315134481cc25d46954", t.getTagId().name());
@@ -266,7 +267,7 @@ public class T0003_Basic extends RepositoryTestCase {
Tag mapTag = db.mapTag("test020");
assertEquals("blob", mapTag.getType());
assertEquals("test020 tagged\n", mapTag.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor());
assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().name());
}
@@ -292,7 +293,7 @@ public class T0003_Basic extends RepositoryTestCase {
t.setObjId(almostEmptyTreeId);
t.setType("tree");
t.setTag("test021");
- t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
+ t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
t.setMessage("test021 tagged\n");
t.tag();
assertEquals("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.getTagId().name());
@@ -300,7 +301,7 @@ public class T0003_Basic extends RepositoryTestCase {
Tag mapTag = db.mapTag("test021");
assertEquals("tree", mapTag.getType());
assertEquals("test021 tagged\n", mapTag.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor());
assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().name());
}
@@ -310,8 +311,8 @@ public class T0003_Basic extends RepositoryTestCase {
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
final Commit almostEmptyCommit = new Commit(db);
- almostEmptyCommit.setAuthor(new PersonIdent(jauthor, 1154236443000L, -2 * 60)); // not exactly the same
- almostEmptyCommit.setCommitter(new PersonIdent(jauthor, 1154236443000L, -2 * 60));
+ almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same
+ almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60));
almostEmptyCommit.setMessage("test022\n");
almostEmptyCommit.setTreeId(almostEmptyTreeId);
ObjectId almostEmptyCommitId = new ObjectWriter(db).writeCommit(almostEmptyCommit);
@@ -319,7 +320,7 @@ public class T0003_Basic extends RepositoryTestCase {
t.setObjId(almostEmptyCommitId);
t.setType("commit");
t.setTag("test022");
- t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
+ t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
t.setMessage("test022 tagged\n");
t.tag();
assertEquals("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.getTagId().name());
@@ -327,7 +328,7 @@ public class T0003_Basic extends RepositoryTestCase {
Tag mapTag = db.mapTag("test022");
assertEquals("commit", mapTag.getType());
assertEquals("test022 tagged\n", mapTag.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor());
assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObjId().name());
}
@@ -392,19 +393,19 @@ public class T0003_Basic extends RepositoryTestCase {
assertNotNull("have tag test020", mapTag20);
assertEquals("blob", mapTag20.getType());
assertEquals("test020 tagged\n", mapTag20.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag20.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag20.getAuthor());
assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.getObjId().name());
Tag mapTag21 = db.mapTag("test021");
assertEquals("tree", mapTag21.getType());
assertEquals("test021 tagged\n", mapTag21.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag21.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag21.getAuthor());
assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.getObjId().name());
Tag mapTag22 = db.mapTag("test022");
assertEquals("commit", mapTag22.getType());
assertEquals("test022 tagged\n", mapTag22.getMessage());
- assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag22.getAuthor());
+ assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag22.getAuthor());
assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.getObjId().name());
}
@@ -426,8 +427,8 @@ public class T0003_Basic extends RepositoryTestCase {
t.getTreeId());
final Commit c1 = new Commit(db);
- c1.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
- c1.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
+ c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
+ c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c1.setMessage("A Commit\n");
c1.setTree(t);
assertEquals(t.getTreeId(), c1.getTreeId());
@@ -437,8 +438,8 @@ public class T0003_Basic extends RepositoryTestCase {
assertEquals(cmtid1, c1.getCommitId());
final Commit c2 = new Commit(db);
- c2.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
- c2.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
+ c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
+ c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c2.setMessage("A Commit 2\n");
c2.setTree(t);
assertEquals(t.getTreeId(), c2.getTreeId());
@@ -458,8 +459,8 @@ public class T0003_Basic extends RepositoryTestCase {
assertEquals(c1.getCommitId(), rm2.getParentIds()[0]);
final Commit c3 = new Commit(db);
- c3.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
- c3.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
+ c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
+ c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c3.setMessage("A Commit 3\n");
c3.setTree(t);
assertEquals(t.getTreeId(), c3.getTreeId());
@@ -480,8 +481,8 @@ public class T0003_Basic extends RepositoryTestCase {
assertEquals(c2.getCommitId(), rm3.getParentIds()[1]);
final Commit c4 = new Commit(db);
- c4.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
- c4.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
+ c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
+ c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c4.setMessage("A Commit 4\n");
c4.setTree(t);
assertEquals(t.getTreeId(), c3.getTreeId());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
index 50fbce41aa..312fc00b13 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
@@ -147,8 +147,8 @@ public abstract class RevWalkTestCase extends RepositoryTestCase {
final Commit c = new Commit(db);
c.setTreeId(tree);
c.setParentIds(parents);
- c.setAuthor(new PersonIdent(jauthor, new Date(nowTick)));
- c.setCommitter(new PersonIdent(jcommitter, new Date(nowTick)));
+ c.setAuthor(new PersonIdent(author, new Date(nowTick)));
+ c.setCommitter(new PersonIdent(committer, new Date(nowTick)));
c.setMessage("");
return rw.lookupCommit(ow.writeCommit(c));
}
@@ -159,7 +159,7 @@ public abstract class RevWalkTestCase extends RepositoryTestCase {
t.setType(Constants.typeString(dst.getType()));
t.setObjId(dst.toObjectId());
t.setTag(name);
- t.setTagger(new PersonIdent(jcommitter, new Date(nowTick)));
+ t.setTagger(new PersonIdent(committer, new Date(nowTick)));
t.setMessage("");
return (RevTag) rw.lookupAny(ow.writeTag(t), Constants.OBJ_TAG);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index 6a6b63cab8..39ea2f2e42 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Google Inc.
+ * Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2008, Mike Ralphson <mike@abacus.co.uk>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* and other copyright owners as documented in the project's IP log.
@@ -74,7 +74,7 @@ public class BundleWriterTest extends RepositoryTestCase {
// Then we clone a new repo from that bundle and do a simple test. This
// makes sure
// we could read the bundle we created.
- Repository newRepo = createNewEmptyRepo();
+ Repository newRepo = createBareRepository();
FetchResult fetchResult = fetchFromBundle(newRepo, bundle);
Ref advertisedRef = fetchResult
.getAdvertisedRef("refs/heads/firstcommit");
@@ -101,7 +101,7 @@ public class BundleWriterTest extends RepositoryTestCase {
// Then we clone a new repo from that bundle and do a simple test. This
// makes sure
// we could read the bundle we created.
- Repository newRepo = createNewEmptyRepo();
+ Repository newRepo = createBareRepository();
FetchResult fetchResult = fetchFromBundle(newRepo, bundle);
Ref advertisedRef = fetchResult.getAdvertisedRef("refs/heads/aa");
@@ -123,7 +123,7 @@ public class BundleWriterTest extends RepositoryTestCase {
try {
// Check that we actually needed the first bundle
- Repository newRepo2 = createNewEmptyRepo();
+ Repository newRepo2 = createBareRepository();
fetchResult = fetchFromBundle(newRepo2, bundle);
fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled");
} catch (MissingBundlePrerequisiteException e) {