Can SoapUI's property expansion be used to access a TestCase label? - soap

I'm trying to write a SoapUI TestCase at the moment. I'd like to access the label of the test case in one of my test steps. Is there any way to do this using the property expansion syntax?
Something in the region of
${#TestCase#label}
Thanks

It's possible using the follow syntax:
${=context.testCase.name}
Explanation
${= } this allows to execute some Groovy code inside the request.
Like in the Groovy testSteps you've context available so you can access the testCase and then access the name property which contains the label.

Related

How do I make Cloudformation reprocess a template using a macro when parameters change?

I have a Cloudformation template that uses a custom Macro to generate part of the template. The lambda for the Macro uses template parameters (via the templateParameterValues field in the incoming event) to generate the template fragment.
When I change the Cloudformation Stack's parameters, I get an error:
The submitted information didn't contain changes. Submit different information to create a change set.
If I use the CLI I get a similar error:
An error occurred (ValidationError) when calling the UpdateStack operation: No updates are to be performed.
The parameters I am changing are only used by the Macro, not the rest of the template.
How can I make Cloudformation reprocess the template with the macro when I update these parameters?
After working with AWS Support I learned that you must supply the template again in order for the macro to be re-processed.
Even if it is the same exact template it will cause the macros to be reprocessed.
You can do this via the Console UI (by uploading the template file again) or the CLI (by passing the template / template URL again).
I recently came across this when using the count macro to create instances.
I found i was able to modify just the parameters used just by the macro by moving that part of the template to a nested stack and passing the parameters through.
It does involve a bit more work to setup by having the separate stacks, but it did allow me to modify just the parameters of the parent stack how i wanted.

How to create test variable from bean property value in XML test

I need to create a test variable in my XML Citrus test. The variable should be set from a bean property, like this:
<variable name="zzzz" value="#{beanID.property}"/>
The variable gets created, but the #{beanID.property} does not get evaluated to bean's property value and the variable is set to the string '#{beanID.property}' instead.
The bean property is already available in the test, for example
<echo>
<message>My best idea: #{beanID.property}</message>
</echo>
works as expected.
Any other variables which are set using the standard ${...} substitution are created as expected.
No error messages from the framework are generated.
The Spring bean property expression language is not supported by the Citrus Xml test specification. Though a good enhancement idea so maybe worth a feature request and contribution to the framework.
If you want to use it right now you can also write a custom function that resolves the Spring bean property expression on the fly.
You can find good documentation about custom functions in Citrus user guide.

Using Java DSL TestRunner - How to access variable in my own Java-Code

I'm using the Java DSL with the TestRunner to define my tests and basically want to have the following steps:
Load a JSON-Structure from a REST-Endpoint with the http-client
Extract the received JSON-Structure into a Citrus variable
Then I would like to manipulate this variable with some Java-Code for some reason - But I can't get it available in my Java-Code.
Basically like this:
http(builder -> builder.client("client").send()
.get("/config").header("Content-Type", "application/json"));
http(builder -> builder.client("client").receive()
.response(HttpStatus.OK).messageType(MessageType.JSON)
.extractFromPayload("$", "myConfig"));
The variable is set:
echo("${myConfig}")
shows the desired output. But how can I get access to that variable to do something with it in pure Java?
I tried this approach:
variable("chgConfig", MyClassABC.myStaticFunctionXZY("${myConfig}");
And I already tried to use a Citrus Function, but I don't know how to call/include it using the Java DSL.
Is there perhaps any way, to get the actual TestContext and hand it over to my Java-Code?
My understanding was, when using the TestRunner, everything is immediately executed and I was thinking: Oh, that's cool, as I can just insert standard Java-Code when needed.
Yeah, I found the solution myself, just reading a second (or maybe a third ) time the documentation.
I have changed my Test-Class like this:
#CitrusTest
#Test #Parameters("context")
public void run(#Optional #CitrusResource TestContext context) {
...
.....
...
MyClassABC.myStaticFunctionXZY(context.getVariable("myConfig"));
This injects me the actual Test-Context and allows me to access & manipulate variables from my Java-Code. Great stuff.

Citrusframework - Java action - Get result

Besides REST-API Calls, I need to call my own Java-Class, which basically does something, which I want to confirm later in the test via REST-API-Calls.
When calling my Java-Class, there is an expected behavior: It may fail or not fail, depending on the actual Test-Case.
Is there any chance to code this expectation this into my test-class:
java("com.org.xyz.App").method("run").methodArgs(args).build();
As this is the Main-Class, which should be executed later in a automated fashion, I would prefer to validate the Return-Code.
However, I'm looking for any possible way (Exception-Assertion, Stdout-Check, ..) to verify the status of the program.
As you are using the Java DSL to write test cases I would suggest to go with custom test action implementation and/or initializing your custom class directly in the test method and call the method as you would do with any other API.
You can wrap the custom code in a custom AbstractTestAction implementation as you then have access to the TestContext and your custom code is integrated into the test action sequence.
The java("com.org.xyz.App").method("run").methodArgs(args) API is just for compliance to the XML DSL where you do not have the opportunity to initialize own Java class instances. Way too complicated for your requirement in my opinion.

Access to Bind Parameters in MyBatis Interceptor

How do I read the bind parameters inside a MyBatis Interceptor? I'm trying to extract those information so I can write them to a log table.
The guide (http://www.mybatis.org/mybatis-3/configuration.html) didn't mention how to get them, and the JavaDoc (http://www.mybatis.org/mybatis-3/es/apidocs/org/apache/ibatis/mapping/BoundSql.html) does not have a single line of comment. I saw an example on SO about constructing a new BoundSql but that isn't what I needed.
I tried to test what contents are stored in BoundSql.getParameterMappings() and BoundSql.getParameterObject(), but it seems to be pretty complex. There's JavaType and JdbcType, and if there's only one parameter the ParameterObject isn't a Map object.
What is the proper way to get the bind parameters from BoundSql?
After going through MyBatis source code (where comment is an endangered species), I found out how MyBatis processes the bind parameters. However, that requires access to the JDBC Statement object, which is simply not available inside an Interceptor.
Then I did some testing and settled on this:
If there is only a single parameter, BindSql.getParameterObject() will give you the parameter itself. By using BindSql.getParameterMappings() and ParameterMapping.getJavaType() I can tell which Java class the parameter is.
If there are more than one parameter, BindSql.getParameterObject() will return an instance of org.apache.ibatis.binding.MapperMethod.ParamMap, which extends HashMap, or it will be an instance of the DTO you used. Using .getProperty() from ParameterMapping as key or as getter name, you can process the bind parameters one by one.
If anyone has a better way to do this, I'm all ears.