Currently, my team and I are unit testing our application. We have encountered an issue when we use the "executeMicroflowAs" java action to run one of our microflows. The input parameter in the java action is persistable object that requires a member value to be populated with an associated non-persistable object. We create a non-persistable object in the test and associate this value to to the persistable object, however the non-persistable object values fail to populate in the microflow being tested when the java action is executed. We tried using "EndTransaction" java actions and the "Transaction Finish" activity to hopefully commit these objects so that they may pull into the microflow using the "executeMicroflowAs" java action, but it did not work. It is important to note that if we call the microflow without the java actions that the objects pull through just fine. But we need to use the "executeMicroflowAs" java action because the microflow being tested requires a “current user”. We were wondering if anyone had suggestions for how to combat this issue?
A non-persistant entity is not stored in the database and only exists with the initial user in client memory. So using the executeMicroflowasUser java action with a different user indeed won't work. I believe that with the same user that created the Non-peristant entity this should work.
If you do need to test it with a different user either make the entity persistable and commit it for your test, or test the microflow with the correct user directly.
As you’ve noticed, you’ve lost the non-persistent entities as they aren’t owned by the same user that the microflow is running as. You need to change when your entities are created. I think you need a microflow to setup these entities, then call the SUB you need to test. Run this entire microflow as the user you test with, don’t setup the entities first then run as the different user.