Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have a flexible Step description for a custom Task #2954

Closed
Mo0rBy opened this issue Oct 21, 2022 · 2 comments
Closed

How to have a flexible Step description for a custom Task #2954

Mo0rBy opened this issue Oct 21, 2022 · 2 comments

Comments

@Mo0rBy
Copy link

Mo0rBy commented Oct 21, 2022

I've created a custom Task for a REST API interaction. In one instance, I want to send the request with a pathParameter (of the processInstanceId) only and in another instance, I want to send the request with the pathParameter (of the processInstanceId) as well as 2 query parameters (firstResult and maxResults). Now because I have these 2 slightly different situations, I want to be able to modify the value of the @Step annotation so that I don't see this in my report:

Screenshot 2022-10-21 at 15 25 08

Below you can see my custom Task code and notice the stepString class attribute. I hoped that this solution would allow me to have a flexible @Step annotation, depending on which method (withId() or withIdAndQueryParams()) was called, but I get the error The value for annotation attribute Step.value must be a constant expression. Is there any way that I can modify the Step value depending on which method is called?

public class GetSubtasksForProcessInstance implements Task {

    private static final String SERVICE_BASEURL = {myServiceBaseUrl}

    private final String processInstanceid;
    private final String firstResult;
    private final String maxResults;
    private final String stepString;

    public GetSubtasksForProcessInstance(String processInstanceid) {
        this.processInstanceid = processInstanceid;
        this.firstResult = null;
        this.maxResults = null;
        this.stepString = "{0} fetches the Subtasks associated with the process instance with id: #processInstanceid";
    }

    public static GetSubtasksForProcessInstance withId(String processInstanceid) {
        return instrumented(GetSubtasksForProcessInstance.class, processInstanceid);
    }

    public GetSubtasksForProcessInstance(String processInstanceid, String firstResult, String maxResults) {
        this.processInstanceid = processInstanceid;
        this.firstResult = firstResult;
        this.maxResults = maxResults;
        this.stepString = "{0} fetches the Subtasks associated with the process instance with id:#processInstanceid and query parameters firstResult:#firstResult and maxResults:#maxResults";
    }

    public static GetSubtasksForProcessInstance withIdAndQueryParams(String processInstanceid, String firstResult, String maxResults) {
        return instrumented(GetSubtasksForProcessInstance.class, processInstanceid, firstResult, maxResults);
    }

    @Override
    @Step(this.stepString)
    public <T extends Actor> void performAs(T actor) {
        actor.can(CallAnApi.at(SERVICE_BASEURL));
        if ((firstResult == null) && (maxResults == null)) {
            actor.attemptsTo(
                Get.resource("/{processInstanceId}/subtasks")
                    .with(request -> request
                        .pathParam("processInstanceId", processInstanceid)));
        } else {
            actor.attemptsTo(
                Get.resource("/{processInstanceId}/subtasks")
                    .with(request -> request
                        .pathParam("processInstanceId", processInstanceid)
                        .queryParam("firstResult", firstResult)
                        .queryParam("maxResults", maxResults)));
        }
    }
}
@ricardorlg
Copy link
Contributor

ricardorlg commented Oct 21, 2022

just use @Step("#stepString")

@Mo0rBy
Copy link
Author

Mo0rBy commented Oct 23, 2022

@ricardorlg Oh wow thanks! I really missed the obvious there.

@Mo0rBy Mo0rBy closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants