Back Forum Reply New

Subflow Integration Tests

Greetings!

I have a subflow that depends on a object (loaded from a database) in flow scope. This object is automaically inserted in flow scope when the parent flow starts up, and is mapped down to the subflow using an attribute mapper.

How can I independently test my subflow? The test is not a quot;stand alonequot; test, but an integration test that uses the database.  Therefore, I will be going from subflow to database, and back again.

Testing my top level flow and going from end to end works fine! But to independtly test the flows in between (subflows) causes object dependency problems.

I thought of executing an action that loads the object I need (normally executed by my parent flow). Code:
CatalogAction catalogAction = (CatalogAction)getFlowArtifactFactory().getAction(new FlowArtifactParameters(CatalogAction.ACTION_ID));
However, that will not work. The request context is needed. Also, this will have to be executed before my flow starts. No flow, no context.

So, how can I independently, without starting the parent flow, put this object in flow scope for the subflow? Keep in mind, this object needs to be loaded from the database first!Curtney

Ok, in my test method I added a start action to the flow I am testing. It is like a setup action that loads up the database object that I need. It works, but wondering if anyone has any alternatives or see issues with this.Code:
//Helper Method   private void addFlowTestStartAction (String actionId, String methodName) {   Map properties = new HashMap(1);   MethodKey methodKey = new MethodKey(methodName);   properties.put(AnnotatedAction.METHOD_PROPERTY, methodKey);   AnnotatedAction action = new AnnotatedAction(getFlowArtifactFactory().getAction(new FlowArtifactParameters(actionId)), properties);   getFlow().addStartAction(action);   }
However, testing to see if the flow is a root flow in my flow listener fails. Got the idea of testing for this in the MockFlowExecutionListener code from SWF.Code:
public void sessionStarted(RequestContext context) {
if (context.getFlowExecutionContext().getActiveSession().isRoot()) {

Assert.state(!started, quot;The flow execution was already startedquot;);
started = true;
}
else {
assertStarted();
flowNestingLevel++;
}
}
Although technically I know in production it is a subflow, why under testing would it not be root, since I am testing this flow in isolation?_Curtney

I would consider loading the object you need as input into your flow BEFORE the flow execution starts--perhaps using a FlowExecutionListener in the sessionStarting callback, then pass in that object as input by adding it to the input map (ultimately just like a parent flow attribute mapper would).

I'm not sure why your listener above says your flow is not the quot;root flowquot;.  Certainly, if your flow is the top-level flow of the execution spawned, isRoot should return true.  Perhaps some debugging is in order?
¥
Back Forum Reply New