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 interfaceBaseTestCase.UnderLockedFile
-
Field Summary
Fields Modifier and Type Field Description protected static booleanIS_WINDOWSIs set under MS Windows and is not set otherwise.protected TestLoggermyTestLoggerprotected static StringOS_NAMEOperating 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 protectedBaseTestCase()BaseTestCase(String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidassertArraysEqual(byte[] expected, byte[] got)static voidassertArraysEqual(int[] expected, int[] got)static voidassertContains(String textToCheck, String substring)static voidassertContains(String textToCheck, String substring, boolean caseSensitive)static voidassertContains(String textToCheck, Pattern pattern)static <T> voidassertContains(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 voidassertContainsAll(String text, String... messages)static voidassertContainsAny(String text, String... messages)static voidassertContainsWithCount(String textToCheck, String substring, int expectedCount)protected static voidassertEmpty(Collection collection)Asserts that collection is empty or null.protected static voidassertEmpty(Collection collection, String message)Asserts that collection is empty or null.static voidassertEquals(String message, BigDecimal expected, BigDecimal got)static voidassertEquals(String message, Date exp, Date got, long limit)Asserts sate and time.static voidassertEquals(BigDecimal expected, BigDecimal got)static voidassertEquals(Date exp, Date got, long limit)Asserts sate and time.static voidassertEqualsIgnoreNonBMP(String expected, String got)static voidassertExceptionThrown(Callable callable, Class<? extends Exception> expected)static voidassertExceptionThrown(Callable callable, Class<? extends Exception> expected, String expectedMessage)static voidassertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected)static voidassertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected, String expectedMessage)static voidassertExceptionThrown(VoidCallable callable, Class<? extends Exception> expected, Consumer<Exception> exceptionChecker)protected static voidassertGreater(int actual, int lowBound)protected static voidassertGreater(long actual, long lowBound)protected static voidassertGreaterOrEquals(long actual, long lowBound)static voidassertHasWithCount(String textToCheck, String substring, int expectedCount)static <T> voidassertInstanceOf(Object instance, Class<T> expectedClass)static <T> voidassertListEquals(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 voidassertMatches(String actual, String pattern)static voidassertMatches(String actual, Pattern pattern)protected static voidassertMeaningTextEquals(String actual, String expected)static voidassertNotContains(String textToCheck, String substring, boolean caseSensitive)static voidassertNotContains(String textToCheck, Pattern pattern)static <T> voidassertNotContains(Collection<T> collection, T... items)Checks that the collection contains the given item.static voidassertNotEmpty(Collection<?> collection)Asserts that the collections is not empty (and is not null).protected static voidassertNull2(Object object)More descriptive assertion thanAssert.assertNull(java.lang.Object).static <T> voidassertSameElements(Collection<? extends T> collection, Collection<T> expected)static <T> voidassertSameElements(Collection<? extends T> collection, T... expected)static <T> voidassertSameElements(T[] collection, T... expected)static <T> voidassertSetEquals(Set<T> actual, T... expected)Applicable for both sorted set and has set.static voidassertTime(double maxAllowedExecutionTimeInSecs, String message, int numberOfAttempts, Runnable r)static voidassertTime(double maxAllowedExecutionTimeInSecs, String message, Runnable r)static voidassertTimestampEquals(Date actual, Date expected)static voidassertXmlEqual(String expectedXml, String actualXml)static voidassertXmlEqual(String expectedXml, String actualXml, String message)static doubleaverageExecutionTime(Runnable r, int numAttempts)protected <T> voidcheckOrderedCollection(Collection<T> actual)protected <T> voidcheckOrderedCollection(Collection<T> actual, T... expected)protected <T> voidcheckUnorderedCollection(Collection<T> actual)static <T> voidcheckUnorderedCollection(Collection<T> actual, T... expected)protected booleanclearFailure()protected <K,V>
Map<K,V>createMap(Object... params)protected <T> Set<T>createSet(T... params)protected FilecreateTempDir()Returns a File object for created temp directory.protected FilecreateTempFile()protected FilecreateTempFile(int size)protected FilecreateTempFile(String content)protected TestLoggercreateTestLogger()protected voiddoUnderLockedDirectory(File lock, BaseTestCase.UnderLockedFile locked)Works only under windows.protected voiddoUnderLockedFile(File lock, BaseTestCase.UnderLockedFile locked)Works only under windows.protected voiddoUnderUnreadableLockedFile(File lock, BaseTestCase.UnderLockedFile locked)Works only under windows.static voiddumpCollection(Iterable it)static voiddumpFile(File file)static voiddumpItems(Iterable it)protected StringBuilderenableAndRecordDebugLog()protected voidenableDebug()protected voidenableDebug(String category)protected voidenableInfo()protected voidenv(String property, String value, VoidCallable action)protected ThrowablegetLoggedFailure()StringgetName()PathgetProjectDir(String... sub)FilegetTestDataFile(String projectMarker, String... subs)TestFilesgetTestFiles()PathgetTestFilesDataPath(String projectMarker, String... subs)protected booleanhasCustomInternalProperty(String propKey)static booleanisPropertyDefined(String key)protected File[]listFilesOrDie(File file)protected File[]listFilesOrDie(File file, String directory)protected voidlog(String message)protected voidperformAfterTestVerification()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 FileregisterAsTempFile(File file)protected voidremoveInternalProperty(String propKey)voidresetAllFields()static voidresetFields2Null(Object obj)voidrunAndReportMemoryAllocations(int allocatedMemoryThresholdBytes, Runnable action)voidrunAsync(int numberOfThreadsPerRunnable, Runnable... actions)static voidrunAsync(int numberOfThreadsPerRunnable, TestLogger testLogger, Runnable... actions)static voidrunAsyncAndFailOnException(int numberOfThreadsPerRunnable, Runnable... actions)protected voidsetInternalProperty(String propKey, boolean value)protected voidsetInternalProperty(String propKey, int value)protected voidsetInternalProperty(String propKey, String value)protected voidsetLogLevel(org.apache.log4j.Level level)voidsetName(String name)protected voidsetUp()protected voidsetUpClass()voidsetupSuite(org.testng.ITestContext context)static Set<Thread>startThreadsAsync(int numberOfThreadsPerRunnable, Runnable... actions)protected voidtearDown()static voidthreadDump()static Object[][]toProvide(Object... items)protected Object[][]trueFalseDataProvider()voidwaitFor(Collection<Thread> threads)static voidwaitFor(Collection<Thread> threads, TestLogger testLogger)static voidwaitFor(Condition condition, long timeLimitMsec)protected static voidwriteTextToFile(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:AfterTestHookYou should implement this method if you want to perform any checks after test was run. You shouldn't do it in theAfterMethodbecause any exception there will result in that TestNG skip all following tests.- Overrides:
performAfterTestVerificationin 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 IOExceptionWorks 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 IOExceptionWorks 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 IOExceptionWorks 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)
-
-