Package org.confng.sources
Class TestNGParameterSource
- java.lang.Object
-
- org.confng.sources.TestNGParameterSource
-
- All Implemented Interfaces:
ConfigSource
public class TestNGParameterSource extends Object implements ConfigSource
Configuration source that provides values from TestNG parameters.This source captures parameters from TestNG test execution including:
- Suite-level parameters (from testng.xml suite)
- Test-level parameters (from testng.xml test)
- Method-level parameters (from @Parameters annotation)
Parameter precedence (highest to lowest):
- Method-level parameters
- Test-level parameters
- Suite-level parameters
This source is automatically registered when using the TestNGParameterListener which is loaded via TestNG's service loader mechanism.
- Since:
- 1.0
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
- See Also:
TestNGParameterListener
-
-
Constructor Summary
Constructors Constructor Description TestNGParameterSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMethodParameters(String methodName, Map<String,String> parameters)Adds method-level parameters for a specific test method.voidaddSuiteParameters(Map<String,String> parameters)Adds suite-level parameters from TestNG suite configuration.voidaddTestParameters(String testName, Map<String,String> parameters)Adds test-level parameters for a specific test context.voidclearAllParameters()Clears all parameters (suite, test, and method level).voidclearMethodParameters(String methodName)Clears method-level parameters for a specific method.voidclearSuiteParameters()Clears suite-level parameters.voidclearTestParameters(String testName)Clears test-level parameters for a specific test context.Optional<String>get(String key)Retrieves a configuration value for the given key.Map<String,String>getAllParameters()Gets all parameters in precedence order.StringgetCurrentTestName()Gets the name of the current test context.Map<String,String>getMethodParameters(String methodName)Gets method parameters for a specific method.StringgetName()Returns the name of this configuration source.intgetPriority()Returns the priority of this configuration source.Map<String,String>getSuiteParameters()Gets all suite parameters.Map<String,Map<String,String>>getTestParameters()Gets all test parameters for all test contexts.Map<String,String>getTestParameters(String testName)Gets test parameters for a specific test context.voidsetCurrentTestName(String testName)Sets the name of the current test context for the thread.
-
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:ConfigSourceReturns the name of this configuration source.- Specified by:
getNamein interfaceConfigSource- Returns:
- the source name, never null
-
get
public Optional<String> get(String key)
Description copied from interface:ConfigSourceRetrieves a configuration value for the given key.If the key is not found in this source, an empty Optional should be returned. This allows the ConfNG system to try other sources in the resolution chain.
- Specified by:
getin interfaceConfigSource- Parameters:
key- the configuration key to look up- Returns:
- an Optional containing the value if found, empty otherwise
-
getPriority
public int getPriority()
Description copied from interface:ConfigSourceReturns the priority of this configuration source.Sources with higher priority values are consulted first in the resolution chain. Default priorities:
- 100+ - Secret managers and secure sources
- 80-99 - TestNG parameters and test-specific sources
- 60-79 - Environment variables
- 40-59 - System properties
- 20-39 - Configuration files (JSON, Properties)
- 0-19 - Default and fallback sources
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- the priority value, higher values have higher priority
-
addSuiteParameters
public void addSuiteParameters(Map<String,String> parameters)
Adds suite-level parameters from TestNG suite configuration.- Parameters:
parameters- the suite parameters to add
-
addTestParameters
public void addTestParameters(String testName, Map<String,String> parameters)
Adds test-level parameters for a specific test context.- Parameters:
testName- the name of the testparameters- the test parameters to add
-
addMethodParameters
public void addMethodParameters(String methodName, Map<String,String> parameters)
Adds method-level parameters for a specific test method.- Parameters:
methodName- the name of the test methodparameters- the method parameters to add
-
clearSuiteParameters
public void clearSuiteParameters()
Clears suite-level parameters.
-
clearTestParameters
public void clearTestParameters(String testName)
Clears test-level parameters for a specific test context.- Parameters:
testName- the name of the test to clear parameters for
-
clearMethodParameters
public void clearMethodParameters(String methodName)
Clears method-level parameters for a specific method.- Parameters:
methodName- the name of the method to clear parameters for
-
clearAllParameters
public void clearAllParameters()
Clears all parameters (suite, test, and method level).
-
getSuiteParameters
public Map<String,String> getSuiteParameters()
Gets all suite parameters.- Returns:
- a copy of the suite parameters
-
getTestParameters
public Map<String,Map<String,String>> getTestParameters()
Gets all test parameters for all test contexts.- Returns:
- a copy of all test parameters
-
getTestParameters
public Map<String,String> getTestParameters(String testName)
Gets test parameters for a specific test context.- Parameters:
testName- the name of the test- Returns:
- a copy of the test parameters, or empty map if not found
-
getMethodParameters
public Map<String,String> getMethodParameters(String methodName)
Gets method parameters for a specific method.- Parameters:
methodName- the name of the method- Returns:
- a copy of the method parameters, or empty map if not found
-
getAllParameters
public Map<String,String> getAllParameters()
Gets all parameters in precedence order. Method parameters override test parameters, which override suite parameters.- Returns:
- a map containing all parameters with proper precedence
-
getCurrentTestName
public String getCurrentTestName()
Gets the name of the current test context.- Returns:
- the current test name, or null if not set
-
setCurrentTestName
public void setCurrentTestName(String testName)
Sets the name of the current test context for the thread.- Parameters:
testName- the test name to set as current
-
-