Package jetbrains.buildServer
Class BaseTestCase
- java.lang.Object
-
- junit.framework.Assert
-
- jetbrains.buildServer.MockSupport
-
- jetbrains.buildServer.AfterTestHook
-
- jetbrains.buildServer.BaseTestCase
-
- All Implemented Interfaces:
org.testng.IHookable
,org.testng.ITestNGListener
- Direct Known Subclasses:
AbstractCommitSupportTest
,BaseDatabaseTestCase
,BaseJMockTestCase
,BuildArtifactsTestCase
public abstract class BaseTestCase extends AfterTestHook
- Author:
- Kir
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
BaseTestCase.UnderLockedFile
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
IS_WINDOWS
Is set under MS Windows and is not set otherwise.protected TestLogger
myTestLogger
protected static String
OS_NAME
Operating system name (as in the "os.name" environment variable), in lower case.-
Fields inherited from class jetbrains.buildServer.MockSupport
ANYTHING, NOT_NULL, NULL
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseTestCase()
BaseTestCase(String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
assertArraysEqual(byte[] expected, byte[] got)
static void
assertArraysEqual(int[] expected, int[] got)
static void
assertContains(String textToCheck, String substring)
static void
assertContains(String textToCheck, String substring, boolean caseSensitive)
static void
assertContains(String textToCheck, Pattern pattern)
static <T> void
assertContains(Collection<T> collection, T... items)
Checks that the collection contains the given item.static <K,V>
voidassertContains(Map<K,V> includingMap, Map<K,V> includedMap)
static void
assertContainsAll(String text, String... messages)
static void
assertContainsAny(String text, String... messages)
static void
assertContainsWithCount(String textToCheck, String substring, int expectedCount)
protected static void
assertEmpty(Collection collection)
Asserts that collection is empty or null.protected static void
assertEmpty(Collection collection, String message)
Asserts that collection is empty or null.static void
assertEquals(String message, BigDecimal expected, BigDecimal got)
static void
assertEquals(String message, Date exp, Date got, long limit)
Asserts sate and time.static void
assertEquals(BigDecimal expected, BigDecimal got)
static void
assertEquals(Date exp, Date got, long limit)
Asserts sate and time.static void
assertEqualsIgnoreNonBMP(String expected, String got)
static void
assertExceptionThrown(Callable callable, Class<? extends Exception> expected)
static void
assertExceptionThrown(Callable callable, Class<? extends Exception> expected, String expectedMessage)
static void
assertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected)
static void
assertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected, String expectedMessage)
static void
assertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected, Consumer<Exception> exceptionChecker)
protected static void
assertGreater(int actual, int lowBound)
protected static void
assertGreater(long actual, long lowBound)
protected static void
assertGreaterOrEquals(long actual, long lowBound)
static void
assertHasWithCount(String textToCheck, String substring, int expectedCount)
static <T> void
assertInstanceOf(Object instance, Class<T> expectedClass)
static <T> void
assertListEquals(List<T> actual, T... expected)
protected static <K,V>
voidassertMap(Map<K,V> map, Object... expected)
protected static <K,V>
voidassertMapping(Map<K,V> map, K key, V expectedValue)
static void
assertMatches(String actual, String pattern)
static void
assertMatches(String actual, Pattern pattern)
protected static void
assertMeaningTextEquals(String actual, String expected)
static void
assertNotContains(String textToCheck, String substring, boolean caseSensitive)
static void
assertNotContains(String textToCheck, Pattern pattern)
static <T> void
assertNotContains(Collection<T> collection, T... items)
Checks that the collection contains the given item.static void
assertNotEmpty(Collection<?> collection)
Asserts that the collections is not empty (and is not null).protected static void
assertNull2(Object object)
More descriptive assertion thanAssert.assertNull(java.lang.Object)
.static <T> void
assertSameElements(Collection<? extends T> collection, Collection<T> expected)
static <T> void
assertSameElements(Collection<? extends T> collection, T... expected)
static <T> void
assertSameElements(T[] collection, T... expected)
static <T> void
assertSetEquals(Set<T> actual, T... expected)
Applicable for both sorted set and has set.static void
assertTime(double maxAllowedExecutionTimeInSecs, String message, int numberOfAttempts, Runnable r)
static void
assertTime(double maxAllowedExecutionTimeInSecs, String message, Runnable r)
static void
assertTimestampEquals(Date actual, Date expected)
static void
assertXmlEqual(String expectedXml, String actualXml)
static void
assertXmlEqual(String expectedXml, String actualXml, String message)
static double
averageExecutionTime(Runnable r, int numAttempts)
protected <T> void
checkOrderedCollection(Collection<T> actual)
protected <T> void
checkOrderedCollection(Collection<T> actual, T... expected)
protected <T> void
checkUnorderedCollection(Collection<T> actual)
static <T> void
checkUnorderedCollection(Collection<T> actual, T... expected)
protected boolean
clearFailure()
protected <K,V>
Map<K,V>createMap(Object... params)
protected <T> Set<T>
createSet(T... params)
protected File
createTempDir()
Returns a File object for created temp directory.protected File
createTempFile()
protected File
createTempFile(int size)
protected File
createTempFile(String content)
protected TestLogger
createTestLogger()
protected void
doUnderLockedDirectory(File lock, BaseTestCase.UnderLockedFile locked)
Works only under windows.protected void
doUnderLockedFile(File lock, BaseTestCase.UnderLockedFile locked)
Works only under windows.protected void
doUnderUnreadableLockedFile(File lock, BaseTestCase.UnderLockedFile locked)
Works only under windows.static void
dumpCollection(Iterable it)
static void
dumpFile(File file)
static void
dumpItems(Iterable it)
protected StringBuilder
enableAndRecordDebugLog()
protected void
enableDebug()
protected void
enableDebug(String category)
protected void
enableInfo()
protected void
env(String property, String value, VoidCallable action)
protected Throwable
getLoggedFailure()
String
getName()
Path
getProjectDir(String... sub)
File
getTestDataFile(String projectMarker, String... subs)
TestFiles
getTestFiles()
Path
getTestFilesDataPath(String projectMarker, String... subs)
protected boolean
hasCustomInternalProperty(String propKey)
static boolean
isPropertyDefined(String key)
protected File[]
listFilesOrDie(File file)
protected File[]
listFilesOrDie(File file, String directory)
protected void
log(String message)
protected void
performAfterTestVerification()
You should implement this method if you want to perform any checks after test was run.protected static Boolean[][]
provideWithBooleans()
protected OSType[][]
provideWithLinuxMacWindows()
protected String[][]
provideWithWindowsOnly()
protected File
registerAsTempFile(File file)
protected void
removeInternalProperty(String propKey)
void
resetAllFields()
static void
resetFields2Null(Object obj)
void
runAndReportMemoryAllocations(int allocatedMemoryThresholdBytes, Runnable action)
void
runAsync(int numberOfThreadsPerRunnable, Runnable... actions)
static void
runAsync(int numberOfThreadsPerRunnable, TestLogger testLogger, Runnable... actions)
static void
runAsyncAndFailOnException(int numberOfThreadsPerRunnable, Runnable... actions)
protected void
setInternalProperty(String propKey, boolean value)
protected void
setInternalProperty(String propKey, int value)
protected void
setInternalProperty(String propKey, String value)
protected void
setLogLevel(org.apache.log4j.Level level)
void
setName(String name)
protected void
setUp()
protected void
setUpClass()
void
setupSuite(org.testng.ITestContext context)
static Set<Thread>
startThreadsAsync(int numberOfThreadsPerRunnable, Runnable... actions)
protected void
tearDown()
static void
threadDump()
static Object[][]
toProvide(Object... items)
protected Object[][]
trueFalseDataProvider()
void
waitFor(Collection<Thread> threads)
static void
waitFor(Collection<Thread> threads, TestLogger testLogger)
static void
waitFor(Condition condition, long timeLimitMsec)
protected static void
writeTextToFile(File file, String text)
-
Methods inherited from class jetbrains.buildServer.AfterTestHook
finishAfterTestHook, initializeAfterTestHook, run
-
Methods inherited from class jetbrains.buildServer.MockSupport
and, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, arrayContaining, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, atLeastOnce, collectionContaining, collectionContaining, compatibleType, contains, containsInAnyOrder, containsInAnyOrder, containsInOrder, containsInOrder, defaultMockNameForType, doAll, doAll, doAll, doAll, endsWith, eq, eq, eq, eq, eq, eq, eq, eq, eq, eq, exactly, hasProperty, hasProperty, isA, isGreaterThan, isIn, isIn, isLessThan, mapContaining, mapContaining, mapWithKey, mapWithKey, mapWithValue, mapWithValue, mock, mock, never, never, newDummy, newDummy, newDummy, not, not, once, onConsecutiveCalls, onConsecutiveCalls, onConsecutiveCalls, onConsecutiveCalls, or, returnIterator, returnIterator, returnValue, returnValue, returnValue, returnValue, returnValue, returnValue, returnValue, returnValue, returnValue, same, setUpMocks, startsWith, stringContains, tearDownMocks, throwException, toString, verify
-
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
-
-
-
-
Field Detail
-
myTestLogger
@Nullable protected final TestLogger myTestLogger
-
OS_NAME
protected static final String OS_NAME
Operating system name (as in the "os.name" environment variable), in lower case.
-
IS_WINDOWS
protected static final boolean IS_WINDOWS
Is set under MS Windows and is not set otherwise.
-
-
Constructor Detail
-
BaseTestCase
protected BaseTestCase()
-
BaseTestCase
public BaseTestCase(String name)
-
-
Method Detail
-
createTestLogger
@Nullable protected TestLogger createTestLogger()
-
performAfterTestVerification
protected void performAfterTestVerification()
Description copied from class:AfterTestHook
You should implement this method if you want to perform any checks after test was run. You shouldn't do it in theAfterMethod
because any exception there will result in that TestNG skip all following tests.- Overrides:
performAfterTestVerification
in classAfterTestHook
-
log
protected void log(String message)
-
setName
public void setName(String name)
-
getName
public String getName()
-
setupSuite
@BeforeSuite(alwaysRun=true) public void setupSuite(org.testng.ITestContext context)
-
enableInfo
protected void enableInfo()
-
enableDebug
protected void enableDebug()
-
enableDebug
protected void enableDebug(@NotNull String category)
-
enableAndRecordDebugLog
@NotNull protected StringBuilder enableAndRecordDebugLog()
-
clearFailure
protected boolean clearFailure()
-
getLoggedFailure
protected Throwable getLoggedFailure()
-
resetAllFields
@AfterClass public void resetAllFields() throws IllegalAccessException
- Throws:
IllegalAccessException
-
setLogLevel
protected void setLogLevel(org.apache.log4j.Level level)
-
provideWithWindowsOnly
@DataProvider protected String[][] provideWithWindowsOnly()
-
provideWithLinuxMacWindows
@DataProvider protected OSType[][] provideWithLinuxMacWindows()
-
createTempFile
protected final File createTempFile(String content) throws IOException
- Throws:
IOException
-
createTempFile
protected final File createTempFile() throws IOException
- Throws:
IOException
-
createTempFile
protected final File createTempFile(int size) throws IOException
- Throws:
IOException
-
setInternalProperty
protected void setInternalProperty(@NotNull String propKey, @NotNull String value)
-
hasCustomInternalProperty
protected boolean hasCustomInternalProperty(@NotNull String propKey)
-
setInternalProperty
protected void setInternalProperty(@NotNull String propKey, boolean value)
-
setInternalProperty
protected void setInternalProperty(@NotNull String propKey, int value)
-
removeInternalProperty
protected void removeInternalProperty(@NotNull String propKey)
-
createTempDir
protected final File createTempDir() throws IOException
Returns a File object for created temp directory.- Returns:
- a File object for created temp directory
- Throws:
IOException
- if directory creation fails.
-
runAsyncAndFailOnException
public static void runAsyncAndFailOnException(int numberOfThreadsPerRunnable, Runnable... actions) throws InterruptedException
- Throws:
InterruptedException
-
runAsync
public void runAsync(int numberOfThreadsPerRunnable, Runnable... actions) throws InterruptedException
- Throws:
InterruptedException
-
runAsync
public static void runAsync(int numberOfThreadsPerRunnable, @Nullable TestLogger testLogger, Runnable... actions) throws InterruptedException
- Throws:
InterruptedException
-
runAndReportMemoryAllocations
public void runAndReportMemoryAllocations(int allocatedMemoryThresholdBytes, @NotNull Runnable action)
-
waitFor
public void waitFor(@NotNull Collection<Thread> threads)
-
waitFor
public static void waitFor(@NotNull Collection<Thread> threads, @Nullable TestLogger testLogger)
-
waitFor
public static void waitFor(@NotNull Condition condition, long timeLimitMsec)
-
startThreadsAsync
public static Set<Thread> startThreadsAsync(int numberOfThreadsPerRunnable, Runnable... actions) throws InterruptedException
- Throws:
InterruptedException
-
assertTime
public static void assertTime(double maxAllowedExecutionTimeInSecs, String message, Runnable r)
-
assertTime
public static void assertTime(double maxAllowedExecutionTimeInSecs, String message, int numberOfAttempts, Runnable r)
-
assertXmlEqual
public static void assertXmlEqual(@NotNull String expectedXml, @NotNull String actualXml, @Nullable String message) throws IOException
- Throws:
IOException
-
assertXmlEqual
public static void assertXmlEqual(@NotNull String expectedXml, @NotNull String actualXml) throws IOException
- Throws:
IOException
-
averageExecutionTime
public static double averageExecutionTime(Runnable r, int numAttempts)
-
isPropertyDefined
public static boolean isPropertyDefined(String key)
-
dumpCollection
public static void dumpCollection(Iterable it)
-
dumpItems
public static void dumpItems(Iterable it)
-
dumpFile
public static void dumpFile(File file)
-
resetFields2Null
public static void resetFields2Null(Object obj) throws IllegalAccessException
- Throws:
IllegalAccessException
-
threadDump
public static void threadDump()
-
checkOrderedCollection
protected <T> void checkOrderedCollection(@NotNull Collection<T> actual, T... expected)
-
checkOrderedCollection
protected <T> void checkOrderedCollection(@NotNull Collection<T> actual)
-
checkUnorderedCollection
public static <T> void checkUnorderedCollection(@NotNull Collection<T> actual, T... expected)
-
checkUnorderedCollection
protected <T> void checkUnorderedCollection(@NotNull Collection<T> actual)
-
assertContains
public static <T> void assertContains(@Nullable Collection<T> collection, T... items)
Checks that the collection contains the given item.- Type Parameters:
T
- type of items.- Parameters:
collection
- collection to check.
-
assertContains
public static <K,V> void assertContains(@NotNull Map<K,V> includingMap, @NotNull Map<K,V> includedMap)
-
assertNotContains
public static <T> void assertNotContains(@Nullable Collection<T> collection, T... items)
Checks that the collection contains the given item.- Type Parameters:
T
- type of items.- Parameters:
collection
- collection to check.items
- items to found.
-
assertEmpty
protected static void assertEmpty(@Nullable Collection collection)
Asserts that collection is empty or null.- Parameters:
collection
- the collection to check.
-
assertEmpty
protected static void assertEmpty(@Nullable Collection collection, @Nullable String message)
Asserts that collection is empty or null.- Parameters:
collection
- the collection to check.
-
assertNotEmpty
public static void assertNotEmpty(@Nullable Collection<?> collection)
Asserts that the collections is not empty (and is not null).- Parameters:
collection
- the collection to check.
-
assertNull2
protected static void assertNull2(@Nullable Object object)
More descriptive assertion thanAssert.assertNull(java.lang.Object)
. If object is not null, it says the object's value (usingObject.toString()
).- Parameters:
object
- object that is checking to be null.
-
assertMeaningTextEquals
protected static void assertMeaningTextEquals(@Nullable String actual, @Nullable String expected)
-
assertContainsAll
public static void assertContainsAll(@Nullable String text, @NotNull String... messages)
-
assertContainsAny
public static void assertContainsAny(@Nullable String text, @NotNull String... messages)
-
assertContains
public static void assertContains(@Nullable String textToCheck, @NotNull String substring, boolean caseSensitive)
-
assertNotContains
public static void assertNotContains(@Nullable String textToCheck, @NotNull String substring, boolean caseSensitive)
-
assertHasWithCount
public static void assertHasWithCount(String textToCheck, String substring, int expectedCount)
-
assertContainsWithCount
public static void assertContainsWithCount(String textToCheck, String substring, int expectedCount)
-
assertSameElements
public static <T> void assertSameElements(T[] collection, T... expected)
-
assertSameElements
public static <T> void assertSameElements(Collection<? extends T> collection, T... expected)
-
assertSameElements
public static <T> void assertSameElements(Collection<? extends T> collection, Collection<T> expected)
-
assertEquals
public static void assertEquals(Date exp, Date got, long limit)
Asserts sate and time.- Parameters:
exp
- what is expected.got
- what's got (actual).limit
- max allowed difference, in seconds.
-
assertEquals
public static void assertEquals(String message, Date exp, Date got, long limit)
Asserts sate and time.- Parameters:
message
- message that will be outputted in case of a fail.exp
- what is expected.got
- what's got (actual).limit
- max allowed difference, in seconds.
-
assertEquals
public static void assertEquals(BigDecimal expected, BigDecimal got)
-
assertEquals
public static void assertEquals(String message, BigDecimal expected, BigDecimal got)
-
assertEqualsIgnoreNonBMP
public static void assertEqualsIgnoreNonBMP(@Nullable String expected, @Nullable String got)
-
assertArraysEqual
public static void assertArraysEqual(int[] expected, int[] got)
-
assertArraysEqual
public static void assertArraysEqual(byte[] expected, byte[] got)
-
assertSetEquals
public static <T> void assertSetEquals(Set<T> actual, T... expected)
Applicable for both sorted set and has set. In case of sorted one, the actual set's comparator is used.- Type Parameters:
T
- type of items- Parameters:
actual
- the set to checkexpected
- expected items, must be no duplicates- Since:
- 8.1
-
assertListEquals
public static <T> void assertListEquals(List<T> actual, @NotNull T... expected)
-
listFilesOrDie
@NotNull protected File[] listFilesOrDie(@NotNull File file, @NotNull String directory)
-
writeTextToFile
protected static void writeTextToFile(@NotNull File file, @NotNull String text) throws RuntimeException
- Throws:
RuntimeException
-
getTestFiles
public TestFiles getTestFiles()
-
doUnderLockedFile
protected void doUnderLockedFile(@NotNull File lock, @NotNull BaseTestCase.UnderLockedFile locked) throws IOException
Works only under windows. Executes an action under opened for write file (read allowed, but write, move or delete operations are not allowed).- Parameters:
lock
- directory to locklocked
- action to run- Throws:
IOException
- exception- Since:
- 7.1.x
-
doUnderUnreadableLockedFile
protected void doUnderUnreadableLockedFile(@NotNull File lock, @NotNull BaseTestCase.UnderLockedFile locked) throws IOException
Works only under windows. Executes an action under totally locked file (no read, write, move, delete operations allowed).- Parameters:
lock
- directory to locklocked
- action to run- Throws:
IOException
- exception- Since:
- 7.1.x
-
doUnderLockedDirectory
protected void doUnderLockedDirectory(@NotNull File lock, @NotNull BaseTestCase.UnderLockedFile locked) throws IOException
Works only under windows. Executes an action under locked directory.- Parameters:
lock
- directory to locklocked
- action to run- Throws:
IOException
- exception- Since:
- 7.1.x
-
assertGreater
protected static void assertGreater(int actual, int lowBound)
-
assertGreater
protected static void assertGreater(long actual, long lowBound)
-
assertGreaterOrEquals
protected static void assertGreaterOrEquals(long actual, long lowBound)
-
assertMapping
protected static <K,V> void assertMapping(@NotNull Map<K,V> map, @NotNull K key, @NotNull V expectedValue)
-
createSet
@NotNull protected <T> Set<T> createSet(T... params)
-
provideWithBooleans
@DataProvider protected static Boolean[][] provideWithBooleans()
-
assertExceptionThrown
public static void assertExceptionThrown(@NotNull Callable callable, @NotNull Class<? extends Exception> expected)
-
assertExceptionThrown
public static void assertExceptionThrown(@NotNull Callable callable, @NotNull Class<? extends Exception> expected, @Nullable String expectedMessage)
-
assertExceptionThrown
public static void assertExceptionThrown(@NotNull VoidCallable callable, @NotNull Class<? extends Exception> expected)
-
assertExceptionThrown
public static void assertExceptionThrown(@NotNull VoidCallable callable, @NotNull Class<? extends Exception> expected, @Nullable String expectedMessage)
-
assertExceptionThrown
public static void assertExceptionThrown(@NotNull VoidCallable callable, @NotNull Class<? extends Exception> expected, @NotNull Consumer<Exception> exceptionChecker)
-
trueFalseDataProvider
@DataProvider(name="true,false") protected Object[][] trueFalseDataProvider()
-
env
protected void env(String property, String value, VoidCallable action)
-
-