Package org.eclipse.jgit.junit
Class RepositoryTestCase
- java.lang.Object
-
- org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
-
- org.eclipse.jgit.junit.RepositoryTestCase
-
- Direct Known Subclasses:
SshTestHarness
public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected FileRepositorydbTest repository, initialized for this test case.protected java.io.FiletrashWorking directory ofdb.-
Fields inherited from class org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
ASSUME_UNCHANGED, author, committer, CONTENT, CONTENT_ID, LENGTH, mockSystemReader, MOD_TIME, SMUDGE
-
-
Constructor Summary
Constructors Constructor Description RepositoryTestCase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertEqualsFile(java.io.File expected, java.io.File actual)Assert files are equalprotected booleancheck(java.lang.String name)Check if file existsprotected static voidcheckFile(java.io.File f, java.lang.String checkData)Check content of a file.protected voidcheckoutBranch(java.lang.String branchName)Checkout a branchprotected RevCommitcommitFile(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 voidcopyFile(java.io.File src, java.io.File dst)Copy a fileprotected voidcreateBranch(ObjectId objectId, java.lang.String branchName)Create a branchprotected DirCacheEntrycreateEntry(java.lang.String path, FileMode mode)CreateDirCacheEntryprotected DirCacheEntrycreateEntry(java.lang.String path, FileMode mode, int stage, java.lang.String content)CreateDirCacheEntryprotected DirCacheEntrycreateEntry(java.lang.String path, FileMode mode, java.lang.String content)CreateDirCacheEntryprotected DirCacheEntrycreateGitLink(java.lang.String path, AnyObjectId objectId)CreateDirCacheEntryprotected voiddeleteTrashFile(java.lang.String name)Delete a trash filestatic java.time.InstantfsTick(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.StringindexState(int includedOptions)Represent the state of the index in one String.static java.lang.Stringlookup(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.Stringread(java.lang.String name)Read content of a fileprotected voidresetIndex(FileTreeIterator treeItr)Resets the index to represent exactly some filesystem content.voidsetUp()Setup teststatic java.lang.Stringslashify(java.lang.String str)Replaces '\' by '/'voidtearDown()Tear down the testprotected java.nio.file.PathwriteLink(java.lang.String link, java.lang.String target)Create a symbolic linkprotected java.io.FilewriteTrashFile(java.lang.String name, java.lang.String data)Write a trash fileprotected java.io.FilewriteTrashFile(java.lang.String subdir, java.lang.String name, java.lang.String data)Write a trash fileprotected java.io.FilewriteTrashFiles(boolean ensureDistinctTimestamps, java.lang.String... contents)Writes a number of files in the working tree.-
Methods inherited from class org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
addRepoToClose, createBareRepository, createRepository, createRepository, createTempDirectory, createTempFile, createUniqueTestGitDir, createWorkRepository, getCeilings, getTemporaryDirectory, indexState, read, recursiveDelete, runHook, tick, write, write
-
-
-
-
Field Detail
-
db
protected FileRepository db
Test repository, initialized for this test case.
-
trash
protected java.io.File trash
Working directory ofdb.
-
-
Method Detail
-
copyFile
protected static void copyFile(java.io.File src, java.io.File dst) throws java.io.IOExceptionCopy a file- Parameters:
src-dst-- Throws:
java.io.IOException
-
writeTrashFile
protected java.io.File writeTrashFile(java.lang.String name, java.lang.String data) throws java.io.IOExceptionWrite a trash file- Parameters:
name-data-- Returns:
- the trash file
- Throws:
java.io.IOException
-
writeLink
protected java.nio.file.Path writeLink(java.lang.String link, java.lang.String target) throws java.lang.ExceptionCreate a symbolic link- Parameters:
link- the path of the symbolic link to createtarget- the target of the symbolic link- Returns:
- the path to the symbolic link
- Throws:
java.lang.Exception- Since:
- 4.2
-
writeTrashFile
protected java.io.File writeTrashFile(java.lang.String subdir, java.lang.String name, java.lang.String data) throws java.io.IOExceptionWrite a trash file- Parameters:
subdir-name-data-- Returns:
- the trash file
- Throws:
java.io.IOException
-
read
protected java.lang.String read(java.lang.String name) throws java.io.IOExceptionRead content of a file- Parameters:
name-- Returns:
- the file's content
- Throws:
java.io.IOException
-
check
protected boolean check(java.lang.String name)
Check if file exists- Parameters:
name- file name- Returns:
- if the file exists
-
deleteTrashFile
protected void deleteTrashFile(java.lang.String name) throws java.io.IOExceptionDelete a trash file- Parameters:
name- file name- Throws:
java.io.IOException
-
checkFile
protected static void checkFile(java.io.File f, java.lang.String checkData) throws java.io.IOExceptionCheck content of a file.- Parameters:
f-checkData- expected content- Throws:
java.io.IOException
-
setUp
public void setUp() throws java.lang.ExceptionSetup test- Overrides:
setUpin classLocalDiskRepositoryTestCase- Throws:
java.lang.Exception
-
tearDown
public void tearDown() throws java.lang.ExceptionDescription copied from class:LocalDiskRepositoryTestCaseTear down the test- Overrides:
tearDownin classLocalDiskRepositoryTestCase- Throws:
java.lang.Exception
-
indexState
public java.lang.String indexState(int includedOptions) throws java.lang.IllegalStateException, java.io.IOExceptionRepresent the state of the index in one String. This representation is useful when writing tests which do assertions on the state of the index. By default information about path, mode, stage (if different from 0) is included. A bitmask controls which additional info about modificationTimes, smudge state and length is included.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.- Parameters:
includedOptions- a bitmask constructed out of the constantsLocalDiskRepositoryTestCase.MOD_TIME,LocalDiskRepositoryTestCase.SMUDGE,LocalDiskRepositoryTestCase.LENGTH,LocalDiskRepositoryTestCase.CONTENT_IDandLocalDiskRepositoryTestCase.CONTENTcontrolling which info is present in the resulting string.- Returns:
- a string encoding the index state
- Throws:
java.lang.IllegalStateExceptionjava.io.IOException
-
resetIndex
protected void resetIndex(FileTreeIterator treeItr) throws java.io.FileNotFoundException, java.io.IOException
Resets the index to represent exactly some filesystem content. E.g. the following call will replace the index with the working tree content: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.
- Parameters:
treeItr- aFileTreeIteratorwhich determines which files should go into the new index- Throws:
java.io.FileNotFoundExceptionjava.io.IOException
-
lookup
public 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. This can be used create short names for objects to produce small and stable debug output. It is guaranteed that when you lookup the same object multiple times even with different nameTemplates this method will always return the same name which was derived from the first nameTemplate. nameTemplates can contain "%n" which will be replaced by a running number before used as a name.- Parameters:
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 ignored- Returns:
- a name of that object. Is not guaranteed to be unique. Use nameTemplates containing "%n" to always have unique names
-
slashify
public static java.lang.String slashify(java.lang.String str)
Replaces '\' by '/'- Parameters:
str- the string in which backslashes should be replaced- Returns:
- the resulting string with slashes
- Since:
- 4.2
-
fsTick
public static java.time.Instant fsTick(java.io.File lastFile) throws java.lang.InterruptedException, java.io.IOExceptionWaits until it is guaranteed that a subsequent file modification has a younger modification timestamp than the modification timestamp of the given file. This is done by touching a temporary file, reading the lastmodified attribute and, if needed, sleeping. After sleeping this loop starts again until the filesystem timer has advanced enough. The temporary file will be created as a sibling of lastFile.- Parameters:
lastFile- the file on which we want to wait until the filesystem timer has advanced more than the lastmodification timestamp of this file- Returns:
- return the last measured value of the filesystem timer which is greater than then the lastmodification time of lastfile.
- Throws:
java.lang.InterruptedExceptionjava.io.IOException
-
createBranch
protected void createBranch(ObjectId objectId, java.lang.String branchName) throws java.io.IOException
Create a branch- Parameters:
objectId-branchName-- Throws:
java.io.IOException
-
checkoutBranch
protected void checkoutBranch(java.lang.String branchName) throws java.lang.IllegalStateException, java.io.IOExceptionCheckout a branch- Parameters:
branchName-- Throws:
java.lang.IllegalStateExceptionjava.io.IOException
-
writeTrashFiles
protected java.io.File writeTrashFiles(boolean ensureDistinctTimestamps, java.lang.String... contents) throws java.io.IOException, java.lang.InterruptedExceptionWrites a number of files in the working tree. The first content specified will be written into a file named '0', the second into a file named "1" and so on. Ifnullis specified as content then this file is skipped.- Parameters:
ensureDistinctTimestamps- if set totruethen 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 files- Returns:
- the File object associated to the last written file.
- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
commitFile
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.It switches back to the original branch after the commit if there was one.
- Parameters:
filename-contents-branch-- Returns:
- the created commit
-
createEntry
protected DirCacheEntry createEntry(java.lang.String path, FileMode mode)
CreateDirCacheEntry- Parameters:
path-mode-- Returns:
- the DirCacheEntry
-
createEntry
protected DirCacheEntry createEntry(java.lang.String path, FileMode mode, java.lang.String content)
CreateDirCacheEntry- Parameters:
path-mode-content-- Returns:
- the DirCacheEntry
-
createEntry
protected DirCacheEntry createEntry(java.lang.String path, FileMode mode, int stage, java.lang.String content)
CreateDirCacheEntry- Parameters:
path-mode-stage-content-- Returns:
- the DirCacheEntry
-
createGitLink
protected DirCacheEntry createGitLink(java.lang.String path, AnyObjectId objectId)
CreateDirCacheEntry- Parameters:
path-objectId-- Returns:
- the DirCacheEntry
-
assertEqualsFile
public static void assertEqualsFile(java.io.File expected, java.io.File actual) throws java.io.IOExceptionAssert files are equal- Parameters:
expected-actual-- Throws:
java.io.IOException
-
-