public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase
Modifier and Type | Field and Description |
---|---|
protected FileRepository |
db
Test repository, initialized for this test case.
|
protected File |
trash
Working directory of
db . |
ASSUME_UNCHANGED, author, committer, CONTENT, CONTENT_ID, LENGTH, MOD_TIME, SMUDGE
Constructor and Description |
---|
RepositoryTestCase() |
Modifier and Type | Method and Description |
---|---|
static void |
assertEqualsFile(File expected,
File actual) |
protected boolean |
check(String name) |
protected static void |
checkFile(File f,
String checkData) |
protected void |
checkoutBranch(String branchName) |
protected RevCommit |
commitFile(String filename,
String contents,
String branch)
Commit a file with the specified contents on the specified branch,
creating the branch if it didn't exist before.
|
protected static void |
copyFile(File src,
File dst) |
protected void |
createBranch(ObjectId objectId,
String branchName) |
protected DirCacheEntry |
createEntry(String path,
FileMode mode) |
protected DirCacheEntry |
createEntry(String path,
FileMode mode,
int stage,
String content) |
protected DirCacheEntry |
createEntry(String path,
FileMode mode,
String content) |
protected void |
deleteTrashFile(String name) |
static long |
fsTick(File lastFile)
Waits until it is guaranteed that a subsequent file modification has a
younger modification timestamp than the modification timestamp of the
given file.
|
String |
indexState(int includedOptions)
Represent the state of the index in one String.
|
static String |
lookup(Object l,
String nameTemplate,
Map<Object,String> lookupTable)
Helper method to map arbitrary objects to user-defined names.
|
protected String |
read(String name) |
protected void |
resetIndex(FileTreeIterator treeItr)
Resets the index to represent exactly some filesystem content.
|
void |
setUp() |
protected File |
writeTrashFile(String name,
String data) |
protected File |
writeTrashFile(String subdir,
String name,
String data) |
protected File |
writeTrashFiles(boolean ensureDistinctTimestamps,
String... contents)
Writes a number of files in the working tree.
|
addRepoToClose, createBareRepository, createTempDirectory, createTempFile, createUniqueTestGitDir, createWorkRepository, getCeilings, getTemporaryDirectory, indexState, read, recursiveDelete, runHook, tearDown, tick, write, write
protected FileRepository db
protected static void copyFile(File src, File dst) throws IOException
IOException
protected File writeTrashFile(String name, String data) throws IOException
IOException
protected File writeTrashFile(String subdir, String name, String data) throws IOException
IOException
protected String read(String name) throws IOException
IOException
protected boolean check(String name)
protected void deleteTrashFile(String name) throws IOException
IOException
protected static void checkFile(File f, String checkData) throws IOException
IOException
public void setUp() throws Exception
setUp
in class LocalDiskRepositoryTestCase
Exception
public String indexState(int includedOptions) throws IllegalStateException, IOException
The format of the returned string is described with this BNF:
result = ( "[" path mode stage? time? smudge? length? sha1? content? "]" )* . mode = ", mode:" number . stage = ", stage:" number . time = ", time:t" timestamp-index . smudge = "" | ", smudged" . length = ", length:" number . sha1 = ", sha1:" hex-sha1 . content = ", content:" blob-data .'stage' is only presented when the stage is different from 0. All reported time stamps are mapped to strings like "t0", "t1", ... "tn". The smallest reported time-stamp will be called "t0". This allows to write assertions against the string although the concrete value of the time stamps is unknown.
includedOptions
- a bitmask constructed out of the constants LocalDiskRepositoryTestCase.MOD_TIME
,
LocalDiskRepositoryTestCase.SMUDGE
, LocalDiskRepositoryTestCase.LENGTH
, LocalDiskRepositoryTestCase.CONTENT_ID
and
LocalDiskRepositoryTestCase.CONTENT
controlling which info is present in the
resulting string.IllegalStateException
IOException
protected void resetIndex(FileTreeIterator treeItr) throws FileNotFoundException, IOException
resetIndex(new FileSystemIterator(db))
This method can be used by testcases which first prepare a new commit somewhere in the filesystem (e.g. in the working-tree) and then want to have an index which matches their prepared content.
treeItr
- a FileTreeIterator
which determines which files should
go into the new indexFileNotFoundException
IOException
public static String lookup(Object l, String nameTemplate, Map<Object,String> lookupTable)
l
- the object to lookupnameTemplate
- the name for that object. Can contain "%n" which will be
replaced by a running number before used as a name. If the
lookup table already contains the object this parameter will
be ignoredlookupTable
- a table storing object-name mappings.public static long fsTick(File lastFile) throws InterruptedException, IOException
lastFile
- the file on which we want to wait until the filesystem timer
has advanced more than the lastmodification timestamp of this
fileInterruptedException
IOException
protected void createBranch(ObjectId objectId, String branchName) throws IOException
IOException
protected void checkoutBranch(String branchName) throws IllegalStateException, IOException
IllegalStateException
IOException
protected File writeTrashFiles(boolean ensureDistinctTimestamps, String... contents) throws IOException, InterruptedException
null
is specified as content then this file is
skipped.ensureDistinctTimestamps
- if set to true
then between two write operations
this method will wait to ensure that the second file will get
a different lastmodification timestamp than the first file.contents
- the contents which should be written into the filesIOException
InterruptedException
protected RevCommit commitFile(String filename, String contents, String branch)
It switches back to the original branch after the commit if there was one.
filename
- contents
- branch
- protected DirCacheEntry createEntry(String path, FileMode mode)
protected DirCacheEntry createEntry(String path, FileMode mode, String content)
protected DirCacheEntry createEntry(String path, FileMode mode, int stage, String content)
public static void assertEqualsFile(File expected, File actual) throws IOException
IOException
Copyright © 2015 Eclipse JGit Project. All rights reserved.