/** * @return the first {@code test:processor} from a flow with the provided name. */ public static FunctionalTestProcessor getFromFlow(ConfigurationComponentLocator locator, String flowName) throws Exception { return locator.find(ComponentIdentifier.builder().namespace("test").name("processor").build()) .stream() .filter(c -> flowName.equals(c.getRootContainerLocation().toString())) .map(c -> (FunctionalTestProcessor) c) .findAny().get(); }
/** * Returns the {@link FlowConstruct} of the root container element if there is one. Otherwise return {@link Optional#empty()} * * @param componentLocator the locator for the {@link FlowConstruct} * @param component the component that may be configured within a {@link FlowConstruct} * @return the {@link FlowConstruct} of the root container element if there is one. Otherwise return {@link Optional#empty()} */ static Optional<FlowConstruct> getFromAnnotatedObject(ConfigurationComponentLocator componentLocator, Component component) { Optional<Component> objectFoundOptional = componentLocator.find(component.getRootContainerLocation()); Optional<FlowConstruct> flowConstruct = objectFoundOptional.flatMap(objectFound -> objectFound instanceof FlowConstruct ? of((FlowConstruct) objectFound) : empty()).filter(object -> object != null); return flowConstruct; }
/** * Returns the {@link FlowConstruct} of the root container element. If the root container is not a {@link FlowConstruct} then it * fails. * * @param componentLocator the locator for the {@link FlowConstruct} * @param component the component that may be configured within a {@link FlowConstruct} * @return the {@link FlowConstruct} of the root container element. If the root container is not a {@link FlowConstruct} then it * fails. */ static FlowConstruct getFromAnnotatedObjectOrFail(ConfigurationComponentLocator componentLocator, Component component) { return getFromAnnotatedObject(componentLocator, component) .orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format( "Couldn't find FlowConstruct with global name %s or it was not an instance of FlowConstruct", component.getRootContainerLocation() .toString())))); }