Class ConfigurableScenarioTest<C extends dev.aherscu.qa.testing.utils.config.AbstractConfiguration<? extends org.apache.commons.configuration.Configuration>,T extends AnyScenarioType,GIVEN extends GenericFixtures<T,?> & ScenarioType<T>,WHEN extends GenericActions<T,?> & ScenarioType<T>,THEN extends GenericVerifications<T,?> & ScenarioType<T>>
- java.lang.Object
-
- com.tngtech.jgiven.base.ScenarioTestBase<GIVEN,WHEN,THEN>
-
- dev.aherscu.qa.jgiven.commons.utils.ScenarioTestEx<GIVEN,WHEN,THEN>
-
- dev.aherscu.qa.jgiven.commons.model.TypedScenarioTest<T,GIVEN,WHEN,THEN>
-
- dev.aherscu.qa.jgiven.commons.utils.ConfigurableScenarioTest<C,T,GIVEN,WHEN,THEN>
-
- Type Parameters:
C
- type of configuration used by scenarioT
- type of scenarioGIVEN
- the fixtures stageWHEN
- the actions stageTHEN
- the verifications stage
- Direct Known Subclasses:
AbstractWireMockTest
@ThreadSafe public abstract class ConfigurableScenarioTest<C extends dev.aherscu.qa.testing.utils.config.AbstractConfiguration<? extends org.apache.commons.configuration.Configuration>,T extends AnyScenarioType,GIVEN extends GenericFixtures<T,?> & ScenarioType<T>,WHEN extends GenericActions<T,?> & ScenarioType<T>,THEN extends GenericVerifications<T,?> & ScenarioType<T>> extends TypedScenarioTest<T,GIVEN,WHEN,THEN>
Enables Apache Configuration on JGiven/TestNG tests.- Author:
- aherscu
-
-
Field Summary
Fields Modifier and Type Field Description static AtomicInteger
concurrency
Concurrency achieved so far.protected Class<C>
configurationType
The configuration type of this scenario.static String
INTERNAL_DATA_PROVIDER
The internal data provider name.static Set<String>
issuedRandomIds
List of generated random identifiers.protected ThreadLocal<String>
randomId
Stores a random string per thread.protected ThreadLocal<Instant>
startTime
Start time of execution thread.protected static String
USE_FIRST_PARAM
The first parameter to be used withCaseAs
annotation.-
Fields inherited from class dev.aherscu.qa.jgiven.commons.model.TypedScenarioTest
EPOCH_MILLI_64
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConfigurableScenarioTest(Class<C> configurationType)
Initializes the configuration type of this scenario by "configuration-sources.xml".
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterMethodKeepJenkinsAlive(Method testMethod)
When running repeated tests in Jenkins we must write something into the console otherwise connection is lost.protected void
beforeClassInitializeSession()
Renames current thread as<class-simple-name>
, as returned byClass.getSimpleName()
.protected void
beforeMethodInitializeSession(Method testMethod, Object[] parameters)
If therandomId
forcurrent thread
was not already set, then generates one and sets it.protected C
configuration()
On first call initializes the configuration for this scenario type and caches it; on further calls will return the cached configuration.protected String
generateRandomId()
Generates a Base64, URL-friendly, encoding of a random UUID.protected String
randomId()
-
Methods inherited from class dev.aherscu.qa.jgiven.commons.utils.ScenarioTestEx
getScenario
-
-
-
-
Field Detail
-
INTERNAL_DATA_PROVIDER
public static final String INTERNAL_DATA_PROVIDER
The internal data provider name.- See Also:
- Constant Field Values
-
concurrency
public static final AtomicInteger concurrency
Concurrency achieved so far.
-
issuedRandomIds
public static final Set<String> issuedRandomIds
List of generated random identifiers.
-
USE_FIRST_PARAM
protected static final String USE_FIRST_PARAM
The first parameter to be used withCaseAs
annotation.- See Also:
- Constant Field Values
-
configurationType
protected final Class<C extends dev.aherscu.qa.testing.utils.config.AbstractConfiguration<? extends org.apache.commons.configuration.Configuration>> configurationType
The configuration type of this scenario.
-
startTime
protected final ThreadLocal<Instant> startTime
Start time of execution thread.
-
randomId
protected final ThreadLocal<String> randomId
Stores a random string per thread.- See Also:
randomId()
-
-
Method Detail
-
afterMethodKeepJenkinsAlive
@AfterMethod(alwaysRun=true) protected final void afterMethodKeepJenkinsAlive(Method testMethod)
When running repeated tests in Jenkins we must write something into the console otherwise connection is lost.- Parameters:
testMethod
- The test method, not null
-
beforeClassInitializeSession
@BeforeClass(alwaysRun=true) protected final void beforeClassInitializeSession()
Renames current thread as
<class-simple-name>
, as returned byClass.getSimpleName()
. This means that code running inBeforeClass
orBeforeTest
annotated methods will have its thread named such this.
-
beforeMethodInitializeSession
@BeforeMethod(alwaysRun=true) protected final void beforeMethodInitializeSession(Method testMethod, Object[] parameters)
If the
randomId
forcurrent thread
was not already set, then generates one and sets it. The generated random id is URL-friendly. Thread starting time is stored instartTime
.In addition, renames current thread as
<class-simple-name>:<method-name>:<hash-of-params>@<thread-id>
, where:- class-simple-name
- as returned by
Class.getSimpleName()
- method-name
- as returned by
Method.getName()
- class-simple-name
- hex string of whatever is returned by
Arrays.hashCode(Object[])
, whereinObject[]
is the parameters of the test method - thread-id
- identifier of thread as of
Thread.getId()
Test
annotated methods will have its thread named such this.- Parameters:
testMethod
- The test method, not nullparameters
- the parameters used to invoke this test method instance
-
configuration
protected C configuration()
On first call initializes the configuration for this scenario type and caches it; on further calls will return the cached configuration.- Returns:
- the configuration for this type
- Throws:
RuntimeException
- if the configuration type cannot be instantiated or the "configuration-sources.xml" refer to a non-existing resource.
-
generateRandomId
protected String generateRandomId()
Generates a Base64, URL-friendly, encoding of a random UUID. It is called once per thread initialization.Override to provide different behavior.
- Returns:
- random identifier to be used during the entire test session
-
randomId
protected final String randomId()
- Returns:
- a random string; by default, initialized before each method.
-
-