Simplifying Workflow Testing

When testing workflows for various scenarios like joiners, movers, or leavers, we often encounter complexities. One major hurdle is creating realistic test scenarios due to data dependencies on other systems.

To tackle this challenge, here is a sample rule/beanshell that can trigger any workflow. The best part? You can pass workflow arguments as parameters in the rule and trigger it using a request definition. This streamlined approach makes testing more efficient and effective.

					String caseName = "Testing for <insert workflow name here> "

                    long launchTime = System.currentTimeMillis() + 1000;
                    caseName = caseName + " (" + launchTime + ")";
					
					//Arguments to create reques defintion
                    Attributes requestArgs = new Attributes();
                    requestArgs.put(StandardWorkflowHandler.ARG_REQUEST_DEFINITION, sailpoint.request.WorkflowRequestExecutor.DEFINITION_NAME);
                    requestArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_WORKFLOW, workflowName);
                    requestArgs.put(sailpoint.workflow.StandardWorkflowHandler.ARG_REQUEST_NAME, caseName);
                    requestArgs.put( "requestName", caseName );

                    // arguments to pass to the workflow
                    Attributes wfArgs = new Attributes();
                    wfArgs.put("workflow", workflowName);
                    wfArgs.put("example", "example");
					wfArgs.put("identityName", "Abhishek Chowdhury");
					
                    requestArgs.putAll(wfArgs);

                    Request request = new Request();
                    RequestDefinition requestDef = context.getObjectByName(RequestDefinition.class, "Workflow Request");
                    request.setDefinition(requestDef);
                    request.setEventDate( new Date( launchTime ) );
                    request.setOwner(requestOwner);
                    request.setName(caseName);
                    request.setAttributes( requestDef, requestArgs );

                    RequestManager.addRequest(context,request);
4 Likes

Maybe it is simple to make an API call for workflow passing the arguments in body.

3 Likes

Thanks @abhishek_chowdhury for sharing, will bookmark for future reference :slight_smile:

1 Like

Thanks for sharing !
I use the similar code for most of my testing .

1 Like

Thank you @abhishek_chowdhury

1 Like