Class ReplacementAspect
- java.lang.Object
-
- com.privalia.qa.aspects.ReplacementAspect
-
public final class ReplacementAspect extends Object
Aspect to replace variables used in the feature files- Author:
- Jose Fernandez
-
-
Constructor Summary
Constructors Constructor Description ReplacementAspect()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
aroundReplacementArguments(org.aspectj.lang.JoinPoint jp, io.cucumber.core.backend.TestCaseState state)
When a step is about to be executed, the Match#getArguments method is called.protected static String
replaceCodePlaceholders(String element, org.aspectj.lang.JoinPoint pjp)
Deprecated.Deprecated.static String
replacedElement(String el, org.aspectj.lang.JoinPoint jp)
protected static String
replaceEnvironmentPlaceholders(String element, org.aspectj.lang.JoinPoint jp)
Replaces every placeholded element, enclosed in ${} with the corresponding java propertyprotected void
replacementArguments(io.cucumber.core.backend.TestCaseState state)
protected static String
replacePropertyPlaceholders(String element, org.aspectj.lang.JoinPoint pjp)
Deprecated.Deprecated.protected static String
replaceReflectionPlaceholders(String element, org.aspectj.lang.JoinPoint pjp)
Deprecated.Deprecated.
-
-
-
Method Detail
-
replacementArguments
protected void replacementArguments(io.cucumber.core.backend.TestCaseState state)
-
aroundReplacementArguments
public void aroundReplacementArguments(org.aspectj.lang.JoinPoint jp, io.cucumber.core.backend.TestCaseState state) throws NoSuchFieldException, IllegalAccessException, FileNotFoundException, NonReplaceableException, org.apache.commons.configuration2.ex.ConfigurationException, URISyntaxException
When a step is about to be executed, the Match#getArguments method is called. this function retrieves the the arguments that are going to be used when executing the glue method.This method captures this event and replaces the variables with their appropriate value using reflection
- Parameters:
jp
- the jpstate
- the state- Throws:
NoSuchFieldException
- the no such field exceptionIllegalAccessException
- the illegal access exceptionFileNotFoundException
- the file not found exceptionNonReplaceableException
- the non replaceable exceptionorg.apache.commons.configuration2.ex.ConfigurationException
- the configuration exceptionURISyntaxException
- the uri syntax exception
-
replacedElement
public static String replacedElement(String el, org.aspectj.lang.JoinPoint jp) throws NonReplaceableException, org.apache.commons.configuration2.ex.ConfigurationException, URISyntaxException, FileNotFoundException
- Throws:
NonReplaceableException
org.apache.commons.configuration2.ex.ConfigurationException
URISyntaxException
FileNotFoundException
-
replacePropertyPlaceholders
@Deprecated protected static String replacePropertyPlaceholders(String element, org.aspectj.lang.JoinPoint pjp) throws org.apache.commons.configuration2.ex.ConfigurationException, URISyntaxException, NonReplaceableException, FileNotFoundException
Deprecated.Deprecated. This same function can now be perform viaStringSubstitutor
with theEnvPropertyLookup
(i.e. #{my.key} can be represented as ${envProperties:my.key})Replaces every placeholded element, enclosed in #{} with the corresponding value in a properties file.The file that contains all common configuration for the project (environment independent configuration) must be located in /resources/configuration/common.properties
Environment-specific configuration can be located in a separated file. This configuration can override the configuration from the common file. All environment specific configuration files can be included at runtime via maven variable, setting the 'env' to the name of the file.
for example, to use properties from the file pre.properties located in /resources/configuration/pre.properties, just pass -Denv=pre when running your tests
- Parameters:
element
- element to be replacedpjp
- JoinPoint- Returns:
- resulting string
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
- ConfigurationExceptionURISyntaxException
- URISyntaxExceptionNonReplaceableException
- NonReplaceableExceptionFileNotFoundException
- FileNotFoundException
-
replaceCodePlaceholders
@Deprecated protected static String replaceCodePlaceholders(String element, org.aspectj.lang.JoinPoint pjp) throws NonReplaceableException
Deprecated.Deprecated. @{} functions can now be performed usingStringSubstitutor
with the ${} variable placeholderReplaces every placeholded element, enclosed in @{} with the corresponding attribute value in local Common classIf the element starts with: - IP: We expect it to be followed by '.' + interface name (i.e. IP.eth0). It can contain other replacements.
If the element starts with: - JSON: We expect it to be followed by '.' + path_to_json_file (relative to src/test/resources or target/test-classes). The json is read and its content is returned as a string
If the element starts with: - FILE: We expect it to be followed by '.' + path_to_file (relative to src/test/resources or target/test-classes). The file is read and its content is returned as a string
- Parameters:
element
- element to be replacedpjp
- JoinPoint- Returns:
- String
- Throws:
NonReplaceableException
- exception
-
replaceReflectionPlaceholders
@Deprecated protected static String replaceReflectionPlaceholders(String element, org.aspectj.lang.JoinPoint pjp)
Deprecated.Deprecated. ${} placeholder can also be used as placeholder for Thread variablesReplaces every placeholded element, enclosed in !{} with the corresponding attribute value in local Common class- Parameters:
element
- element to be replacedpjp
- JoinPoint- Returns:
- String string
-
replaceEnvironmentPlaceholders
protected static String replaceEnvironmentPlaceholders(String element, org.aspectj.lang.JoinPoint jp) throws NonReplaceableException
Replaces every placeholded element, enclosed in ${} with the corresponding java property- Parameters:
element
- element to be replacedjp
- JoinPoint- Returns:
- String
- Throws:
NonReplaceableException
- exception
-
-