Search in sources :

Example 1 with FlowRunner

use of org.mule.functional.api.flow.FlowRunner in project mule by mulesoft.

the class OperationExecutionTestCase method operationWithReturnValueOnTarget.

@Test
public void operationWithReturnValueOnTarget() throws Exception {
    FlowRunner runner = flowRunner("sayMyNameOnTarget").withPayload(EMPTY_STRING);
    CoreEvent responseEvent = runner.run();
    assertThat(responseEvent.getMessage().getPayload().getValue(), is(EMPTY_STRING));
    Message responseMessage = (Message) responseEvent.getVariables().get("myFace").getValue();
    assertThat(responseMessage.getPayload().getValue(), is(HEISENBERG));
}
Also used : FlowRunner(org.mule.functional.api.flow.FlowRunner) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 2 with FlowRunner

use of org.mule.functional.api.flow.FlowRunner in project mule by mulesoft.

the class DynamicConfigExpirationTestCase method invokeDynamicConfig.

private HeisenbergExtension invokeDynamicConfig(String flowName, String configName, String payload) throws Exception {
    FlowRunner runner = flowRunner(flowName).withPayload(payload);
    final CoreEvent event = runner.buildEvent();
    String returnedName = getPayloadAsString(runner.run().getMessage());
    HeisenbergExtension config = (HeisenbergExtension) muleContext.getExtensionManager().getConfiguration(configName, event).getValue();
    // validate we actually hit the correct dynamic config
    assertThat(returnedName, is(payload));
    assertThat(config.getPersonalInfo().getName(), is(payload));
    return config;
}
Also used : FlowRunner(org.mule.functional.api.flow.FlowRunner) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension)

Example 3 with FlowRunner

use of org.mule.functional.api.flow.FlowRunner in project mule by mulesoft.

the class AbstractDeploymentTestCase method executeApplicationFlow.

protected void executeApplicationFlow(String flowName) throws Exception {
    ClassLoader appClassLoader = deploymentService.getApplications().get(0).getArtifactClassLoader().getClassLoader();
    withContextClassLoader(appClassLoader, () -> {
        final FlowRunner flowRunner = new FlowRunner(deploymentService.getApplications().get(0).getRegistry(), flowName);
        CoreEvent result = flowRunner.withPayload(TEST_MESSAGE).run();
        flowRunner.dispose();
        assertThat(currentThread().getContextClassLoader(), sameInstance(appClassLoader));
        return result;
    });
}
Also used : FlowRunner(org.mule.functional.api.flow.FlowRunner) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)

Example 4 with FlowRunner

use of org.mule.functional.api.flow.FlowRunner in project mule by mulesoft.

the class FunctionalTestCase method flowRunner.

/**
 * Initializes a builder to construct an event and the running context to run it through a flow.
 *
 * @param flowName
 * @return the {@link FlowRunner}
 */
protected FlowRunner flowRunner(String flowName) {
    synchronized (runners) {
        if (tearingDown) {
            throw new IllegalStateException("Already tearing down.");
        }
        final FlowRunner flowRunner = new FlowRunner(registry, flowName);
        runners.add(flowRunner);
        return flowRunner;
    }
}
Also used : FlowRunner(org.mule.functional.api.flow.FlowRunner)

Aggregations

FlowRunner (org.mule.functional.api.flow.FlowRunner)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 Test (org.junit.Test)1 Message (org.mule.runtime.api.message.Message)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)1