Cristian Deac
08/09/2022, 9:16 AMvalueFromProviderState syntax in a test and i was wondering if there is any trick to apply a function on the value return by the state provider
i.e the state populates the map with userId
in the test to use something like
newJsonBody((payload) ->
payload.valueFromProviderState("id", () -> Base64.encode("${userId}"), "MTIzCg=="))
.build()Cristian Deac
08/09/2022, 9:17 AMuglyog
Cristian Deac
08/09/2022, 10:11 AMvalueFromProviderState("id", "${userId}", "whatever")) but i would like to be able to manipulate/change the injected value of userId (for example, encode it)Cristian Deac
08/09/2022, 10:12 AMuglyog
valueFromProviderState("id", "${userId}", "whatever") does not invoke anything, it configures things so that when provider state callback is invoked on the provider side, it will use the values returned from that instead of the example one. On the consumer side, it uses the example value.uglyog
whatever), and then, in the provider verification test, you base 64 encode the returned userId value in the provider state callback.Cristian Deac
08/10/2022, 7:32 AMuserId) in the provider state callback.
i managed to do this by adding a new generator to LambdaDslJsonBody which works almost the same as ProviderStateGenerator but before returning the value, applies a function which is provided as param.
so the provider state callback does not duplicate returned values (with different flavours).
not sure if would be widely used but seems like a simple addition to ProviderStateGenerator and valueFromProviderState
i.e. default no op function as param for valueFromProviderState and ProviderStateGenerator class attribute which would be applied on value returned by
this.ep.containsExpressions(this.expression, true)
? this.ep.parseExpression(this.expression, this.dataType, (ValueResolver)(new MapValueResolver(map)), true)
: map.get(this.expression);
and on example value