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, mockSystemReader, MOD_TIME, SMUDGE
Constructor and Description |
---|
RepositoryTestCase() |
Modifier and Type | Method and Description |
---|---|
static void |
assertEqualsFile(File expected,
File actual)
Assert files are equal
|
protected boolean |
check(String name)
Check if file exists
|
protected static void |
checkFile(File f,
String checkData)
Check content of a file.
|
protected void |
checkoutBranch(String branchName)
Checkout a branch
|
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)
Copy a file
|
protected void |
createBranch(ObjectId objectId,
String branchName)
Create a branch
|
protected DirCacheEntry |
createEntry(String path,
FileMode mode)
Create
DirCacheEntry |
protected DirCacheEntry |
createEntry(String path,
FileMode mode,
int stage,
String content)
Create
DirCacheEntry |
protected DirCacheEntry |
createEntry(String path,
FileMode mode,
String content)
Create
DirCacheEntry |
protected void |
deleteTrashFile(String name)
Delete a trash file
|
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)
Read content of a file
|
protected void |
resetIndex(FileTreeIterator treeItr)
Resets the index to represent exactly some filesystem content.
|
void |
setUp()
Setup test
|
static String |
slashify(String str)
Replaces '\' by '/'
|
protected Path |
writeLink(String link,
String target)
Create a symbolic link
|
protected File |
writeTrashFile(String name,
String data)
Write a trash file
|
protected File |
writeTrashFile(String subdir,
String name,
String data)
Write a trash file
|
protected File |
writeTrashFiles(boolean ensureDistinctTimestamps,
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, write
protected FileRepository db
protected static void copyFile(File src, File dst) throws IOException
src
- dst
- IOException
protected File writeTrashFile(String name, String data) throws IOException
name
- data
- IOException
protected Path writeLink(String link, String target) throws Exception
link
- the path of the symbolic link to createtarget
- the target of the symbolic linkException
protected File writeTrashFile(String subdir, String name, String data) throws IOException
subdir
- name
- data
- IOException
protected String read(String name) throws IOException
name
- IOException
protected boolean check(String name)
name
- file nameprotected void deleteTrashFile(String name) throws IOException
name
- file nameIOException
protected static void checkFile(File f, String checkData) throws IOException
f
- checkData
- expected contentIOException
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 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 String slashify(String str)
str
- the string in which backslashes should be replacedpublic 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
objectId
- branchName
- IOException
protected void checkoutBranch(String branchName) throws IllegalStateException, IOException
branchName
- 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)
DirCacheEntry
path
- mode
- protected DirCacheEntry createEntry(String path, FileMode mode, String content)
DirCacheEntry
path
- mode
- content
- protected DirCacheEntry createEntry(String path, FileMode mode, int stage, String content)
DirCacheEntry
path
- mode
- stage
- content
- public static void assertEqualsFile(File expected, File actual) throws IOException
expected
- actual
- IOException
Copyright © 2018 Eclipse JGit Project. All rights reserved.