AnsweredAssumed Answered

Set/used variables from custom assertion not refreshed by gateway

Question asked by adrian.wawrzak on Nov 22, 2018
Latest reply on Dec 10, 2018 by Stephen_Hughes

Hi, I'm developing custom assertion and there's one problem that I can't solve.

I want to dynamically set what variables are used/set by my assertion, but it doesn't seem to be refreshed in gateway, there are only properties visible that are set when assertion class is constructed, so I assume that these methods are only called once on assertion creation.

How can I force gateway to refresh this?

 

Here's my code in Kotlin:

 

class JsonTransformationAssertion : CustomAssertion, UsesVariables, SetsVariables {

    var source: String? = null
    var destination: String? = null
    var isFormatOutput: Boolean = true
    var isOmitQuotesFromNumbers: Boolean = true
    var isOmitQuotesFromBoolean: Boolean = true
    private val fields = DEFAULT
    override fun getName(): String {
        return "Json Transformation"
    }

    override fun getVariablesUsed(): Array<String> {
        var computedFields = fields;
        if(!source.isNullOrEmpty() && source != "Request" && source != "Response"){
            computedFields += " $source"
        }
        return ContextVariablesUtils.getReferencedNames(computedFields)
    }

    override fun getVariablesSet(): Array<VariableMetadata> {
        val array = arrayOf(
                VariableMetadata("source", false, false, null, true, DataType.STRING),
                VariableMetadata("destination", false, false, null, true, DataType.STRING),
                VariableMetadata("formatOutput", false, false, null, true, DataType.BOOLEAN),
                VariableMetadata("omitQuotesFromNumbers", false, false, null, true, DataType.BOOLEAN),
                VariableMetadata("omitQuotesFromBoolean", false, false, null, true, DataType.BOOLEAN))
        if(!destination.isNullOrEmpty() && destination != "Request" && destination != "Response"){
            array.plus(VariableMetadata(destination, false, false, null, true, DataType.STRING))
        }
        return array
    }

    companion object {
        private val DEFAULT = "\${source} \${destination} " +
                "\${formatOutput} \${omitQuotesFromNumbers} " +
                "\${omitQuotesFromBoolean}"
    }
}

Outcomes