use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class SourceConfigurer method configure.
/**
* Performs the configuration of the given {@code source} and returns the result
*
* @param source a {@link Source}
* @param config the {@link ConfigurationInstance config instance} associated to {@code this} source object.
* @return the configured instance
* @throws MuleException
*/
public Source configure(Source source, Optional<ConfigurationInstance> config) throws MuleException {
ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet) {
@Override
protected Source instantiateObject() {
return source;
}
@Override
public Source build(ValueResolvingContext context) throws MuleException {
Source source = build(resolverSet.resolve(context));
injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding());
injectComponentLocation(source, componentLocation);
config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache()));
return source;
}
};
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
Source configuredSource = builder.build(from(initialiserEvent, config));
if (configuredSource instanceof PollingSource) {
Scheduler scheduler = (Scheduler) resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME).resolve(ValueResolvingContext.from(initialiserEvent));
configuredSource = new PollingSourceWrapper((PollingSource) configuredSource, scheduler);
}
return configuredSource;
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e);
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultEventContextTestCase method multipleLevelsGrandchildFirst.
@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child and grandchild contexts are complete.")
public void multipleLevelsGrandchildFirst() throws Exception {
child = addChild(parent);
BaseEventContext grandchild = child(child, empty());
grandchild.success(testEvent());
assertChild(is(nullValue()), is(nullValue()), false);
assertParent(is(nullValue()), is(nullValue()), false, false);
child.success(testEvent());
assertChild(is(testEvent()), is(nullValue()), true);
assertParent(is(nullValue()), is(nullValue()), false, false);
parent.success(testEvent());
assertChild(is(testEvent()), is(nullValue()), true);
assertParent(is(testEvent()), is(nullValue()), true, true);
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultEventContextTestCase method componentDataFromSingleComponent.
@Test
@Description("Verify that a single component location produces connector and source data.")
public void componentDataFromSingleComponent() throws Exception {
BaseEventContext context = this.context.get();
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is(CORE_PREFIX));
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("test"));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultEventContextTestCase method multipleLevelsParentFirst.
@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child and grandchild contexts are complete, even if parent response is available earlier.")
public void multipleLevelsParentFirst() throws Exception {
child = addChild(parent);
BaseEventContext grandchild = child(child, empty());
parent.success(testEvent());
assertChild(is(nullValue()), is(nullValue()), false);
assertParent(is(testEvent()), is(nullValue()), false, false);
child.success(testEvent());
assertChild(is(testEvent()), is(nullValue()), false);
assertParent(is(testEvent()), is(nullValue()), false, false);
grandchild.success();
assertChild(is(testEvent()), is(nullValue()), true);
assertParent(is(testEvent()), is(nullValue()), true, true);
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class ExecutableComponentTestCase method testExecuteWithInputEvent.
@Test
public void testExecuteWithInputEvent() throws Exception {
ExecutionResult executionResult = executableComponent.execute(InputEvent.create().message(requestMessage)).get();
Event response = executionResult.getEvent();
assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage));
assertThat(response.getMessage(), equalTo(responseMessage));
assertThat(componentInEvent.get().getContext(), equalTo(response.getContext()));
BaseEventContext eventContext = (BaseEventContext) componentInEvent.get().getContext();
assertThat(eventContext.isTerminated(), is(false));
executionResult.complete();
assertThat(eventContext.isTerminated(), is(true));
}
Aggregations