public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase
| Modifier and Type | Field and Description |
|---|---|
protected FileRepository |
db
Test repository, initialized for this test case.
|
protected java.io.File |
trash
Working directory of
db. |
ASSUME_UNCHANGED, author, committer, CONTENT, CONTENT_ID, LENGTH, mockSystemReader, MOD_TIME, SMUDGE| Constructor and Description |
|---|
RepositoryTestCase() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertEqualsFile(java.io.File expected,
java.io.File actual)
Assert files are equal
|
protected boolean |
check(java.lang.String name)
Check if file exists
|
protected static void |
checkFile(java.io.File f,
java.lang.String checkData)
Check content of a file.
|
protected void |
checkoutBranch(java.lang.String branchName)
Checkout a branch
|
protected RevCommit |
commitFile(java.lang.String filename,
java.lang.String contents,
java.lang.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(java.io.File src,
java.io.File dst)
Copy a file
|
protected void |
createBranch(ObjectId objectId,
java.lang.String branchName)
Create a branch
|
protected DirCacheEntry |
createEntry(java.lang.String path,
FileMode mode)
Create
DirCacheEntry |
protected DirCacheEntry |
createEntry(java.lang.String path,
FileMode mode,
int stage,
java.lang.String content)
Create
DirCacheEntry |
protected DirCacheEntry |
createEntry(java.lang.String path,
FileMode mode,
java.lang.String content)
Create
DirCacheEntry |
protected void |
deleteTrashFile(java.lang.String name)
Delete a trash file
|
static long |
fsTick(java.io.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.
|
java.lang.String |
indexState(int includedOptions)
Represent the state of the index in one String.
|
static java.lang.String |
lookup(java.lang.Object l,
java.lang.String nameTemplate,
java.util.Map<java.lang.Object,java.lang.String> lookupTable)
Helper method to map arbitrary objects to user-defined names.
|
protected java.lang.String |
read(java.lang.String name)
Read content of a file
|
protected void |
resetIndex(FileTreeIterator treeItr)
Resets the index to represent exactly some filesystem content.
|
void |
setUp()
Setup test
|
static java.lang.String |
slashify(java.lang.String str)
Replaces '\' by '/'
|
protected java.nio.file.Path |
writeLink(java.lang.String link,
java.lang.String target)
Create a symbolic link
|
protected java.io.File |
writeTrashFile(java.lang.String name,
java.lang.String data)
Write a trash file
|
protected java.io.File |
writeTrashFile(java.lang.String subdir,
java.lang.String name,
java.lang.String data)
Write a trash file
|
protected java.io.File |
writeTrashFiles(boolean ensureDistinctTimestamps,
java.lang.String... contents)
Writes a number of files in the working tree.
|
addRepoToClose, createBareRepository, createRepository, createTempDirectory, createTempFile, createUniqueTestGitDir, createWorkRepository, getCeilings, getTemporaryDirectory, indexState, read, recursiveDelete, runHook, tearDown, tick, write, writeprotected FileRepository db
protected java.io.File trash
db.protected static void copyFile(java.io.File src,
java.io.File dst)
throws java.io.IOException
src - dst - java.io.IOExceptionprotected java.io.File writeTrashFile(java.lang.String name,
java.lang.String data)
throws java.io.IOException
name - data - java.io.IOExceptionprotected java.nio.file.Path writeLink(java.lang.String link,
java.lang.String target)
throws java.lang.Exception
link - the path of the symbolic link to createtarget - the target of the symbolic linkjava.lang.Exceptionprotected java.io.File writeTrashFile(java.lang.String subdir,
java.lang.String name,
java.lang.String data)
throws java.io.IOException
subdir - name - data - java.io.IOExceptionprotected java.lang.String read(java.lang.String name)
throws java.io.IOException
name - java.io.IOExceptionprotected boolean check(java.lang.String name)
name - file nameprotected void deleteTrashFile(java.lang.String name)
throws java.io.IOException
name - file namejava.io.IOExceptionprotected static void checkFile(java.io.File f,
java.lang.String checkData)
throws java.io.IOException
f - checkData - expected contentjava.io.IOExceptionpublic void setUp()
throws java.lang.Exception
setUp in class LocalDiskRepositoryTestCasejava.lang.Exceptionpublic java.lang.String indexState(int includedOptions)
throws java.lang.IllegalStateException,
java.io.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.java.lang.IllegalStateExceptionjava.io.IOExceptionprotected void resetIndex(FileTreeIterator treeItr) throws java.io.FileNotFoundException, java.io.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 indexjava.io.FileNotFoundExceptionjava.io.IOExceptionpublic static java.lang.String lookup(java.lang.Object l,
java.lang.String nameTemplate,
java.util.Map<java.lang.Object,java.lang.String> lookupTable)
l - the object to lookuplookupTable - a table storing object-name mappings.nameTemplate - 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 ignoredpublic static java.lang.String slashify(java.lang.String str)
str - the string in which backslashes should be replacedpublic static long fsTick(java.io.File lastFile)
throws java.lang.InterruptedException,
java.io.IOException
lastFile - the file on which we want to wait until the filesystem timer
has advanced more than the lastmodification timestamp of this
filejava.lang.InterruptedExceptionjava.io.IOExceptionprotected void createBranch(ObjectId objectId, java.lang.String branchName) throws java.io.IOException
objectId - branchName - java.io.IOExceptionprotected void checkoutBranch(java.lang.String branchName)
throws java.lang.IllegalStateException,
java.io.IOException
branchName - java.lang.IllegalStateExceptionjava.io.IOExceptionprotected java.io.File writeTrashFiles(boolean ensureDistinctTimestamps,
java.lang.String... contents)
throws java.io.IOException,
java.lang.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 filesjava.io.IOExceptionjava.lang.InterruptedExceptionprotected RevCommit commitFile(java.lang.String filename, java.lang.String contents, java.lang.String branch)
It switches back to the original branch after the commit if there was one.
filename - contents - branch - protected DirCacheEntry createEntry(java.lang.String path, FileMode mode)
DirCacheEntrypath - mode - protected DirCacheEntry createEntry(java.lang.String path, FileMode mode, java.lang.String content)
DirCacheEntrypath - mode - content - protected DirCacheEntry createEntry(java.lang.String path, FileMode mode, int stage, java.lang.String content)
DirCacheEntrypath - mode - stage - content - public static void assertEqualsFile(java.io.File expected,
java.io.File actual)
throws java.io.IOException
expected - actual - java.io.IOException