@Override public Supplier<ComponentLocation> resolve(ExecutionContext executionContext) { return () -> ((ExecutionContextAdapter) executionContext).getComponent().getLocation(); } }
/** * Adds a new component to the locator. * * @param component the component to be added */ public void addComponent(Component component) { this.componentsMap.put(component.getLocation().getLocation(), component); }
@Override public Object postProcessAfterInitialization(Object o, String s) throws BeansException { // We check for instanceof Component because this method may be called for spring objects if ((!(o instanceof FactoryBean) || o instanceof ComponentFactory) && o instanceof Component && ((Component) o).getLocation() != null) { componentLocator.addComponent((Component) o); } return o; } }
private boolean isInterceptedComponent(ComponentLocation location, InternalEvent event) { final Component component = event.getInternalParameter(INTERCEPTION_COMPONENT); if (component != null) { return location.equals(component.getLocation()); } return false; } }
/** * {@inheritDoc} */ @Override public List<Component> find(ComponentIdentifier componentIdentifier) { return componentsMap.values().stream() .filter(component -> component.getLocation().getComponentIdentifier().getIdentifier().equals(componentIdentifier)) .collect(toList()); }
private void rollback() { try { context.getTransactionHandle().rollback(); } catch (TransactionException e) { LOGGER.error(format("Failed to rollback transaction for message source at '%s': %s", component.getLocation().toString(), e.getMessage()), e); } }
private void injectComponentLocation(Source source) { // ComponentLocationModelValidator assures that there's at most one field List<Field> fields = getFieldsOfType(source.getClass(), ComponentLocation.class); if (fields.isEmpty()) { return; } new FieldSetter<>(fields.get(0)).set(source, component.getLocation()); }
private void commit() { try { context.getTransactionHandle().commit(); } catch (TransactionException e) { LOGGER.error(format("Failed to commit transaction for message source at '%s': %s", component.getLocation().toString(), e.getMessage()), e); } }
@Override public boolean mustStartMessageSource(Component component) { if (configurationProperties.resolveProperty(DISABLE_SCHEDULER_SOURCES_PROPERTY).isPresent()) { if (component.getLocation().getComponentIdentifier().getIdentifier().equals(SCHEDULER_MESSAGE_SOURCE_IDENTIFIER)) { return !configurationProperties.resolveBooleanProperty(DISABLE_SCHEDULER_SOURCES_PROPERTY).orElse(false); } } return true; }
private ExtendedExpressionManager buildExpressionManager() { ExtendedExpressionManager expressionLanguage = mock(ExtendedExpressionManager.class); when(expressionLanguage.parseLogTemplate(anyString(), any(CoreEvent.class), eq(((Component) flow).getLocation()), any( BindingContext.class))) .thenReturn("text to log"); return expressionLanguage; }
private void configureProcessorLocation(Component component) { when(component.getLocation()).thenReturn(mockComponentLocation); when(mockComponentLocation.getFileName()).thenReturn(Optional.of("muleApp.xml")); when(mockComponentLocation.getLineInFile()).thenReturn(Optional.of(10)); } }
private void mockComponent() { component = mock(Component.class, RETURNS_DEEP_STUBS); identifier = mock(ComponentIdentifier.class); when(component.getLocation().getComponentIdentifier().getIdentifier()).thenReturn(identifier); }
@Override public String toString() { return "{action={" + getAction().getNamespace() + ":" + getAction().getIdentifier() + "}, location: " + component.getLocation() + "}"; }
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) { ComponentLocation componentLocation = mock(ComponentLocation.class); when(componentLocation.getLocation()).thenReturn(processorPath); when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty()); when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty()); Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS)); when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null); when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation); return (Processor) annotatedMessageProcessor; }
@Before public void setupMVEL() throws InitialisationException { mvel = new MVELExpressionLanguage(muleContext); mvel.initialise(); flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getName()).thenReturn("myFlow"); final DefaultComponentLocation location = fromSingleComponent("myFlow"); when(((Component) flowConstruct).getAnnotation(LOCATION_KEY)).thenReturn(location); when(((Component) flowConstruct).getLocation()).thenReturn(location); }
protected Object evaluate(String expression, PrivilegedEvent event) throws Exception { if (variant.equals(Variant.EXPRESSION_WITH_DELIMITER)) { return mvel.evaluateUntyped("#[mel:" + expression + "]", event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null); } else { return mvel.evaluateUntyped(expression, event, PrivilegedEvent.builder(event), ((Component) flowConstruct).getLocation(), null); } }
private void assertConnectorMessageNotification(ServerNotificationHandler notificationHandler, MessageSource messageSource, ComponentLocation location, int action) { ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationHandler).fireNotification(notificationCaptor.capture()); ConnectorMessageNotification notification = notificationCaptor.getValue(); assertThat(notification.getComponent(), is(messageSource)); assertThat(notification.getAction().getActionId(), is(action)); assertThat(notification.getComponent().getLocation(), is(location)); }
private FirstSuccessful createFirstSuccessfulRouter(Processor... processors) throws Exception { FirstSuccessful fs = new FirstSuccessful(); fs.setAnnotations(getAppleFlowComponentLocationAnnotations()); final FlowConstruct flow = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flow.getMuleContext()).thenReturn(muleContext); when(((Component) flow).getLocation()).thenReturn(TEST_CONNECTOR_LOCATION); fs.setMuleContext(muleContext); fs.setRoutes(asList(processors)); return fs; }
@SuppressWarnings("deprecation") protected Object evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder) { return expressionLanguage.evaluate(expression, event, eventBuilder, ((Component) flowConstruct).getLocation(), BindingContext.builder().build()) .getValue(); }
protected TypedValue evaluateTyped(String expression, CoreEvent event) throws Exception { if (variant.equals(Variant.EXPRESSION_WITH_DELIMITER)) { return mvel.evaluate("#[mel:" + expression + "]", event, CoreEvent.builder(event), ((Component) flowConstruct).getLocation(), BindingContext.builder().build()); } else { return mvel.evaluate(expression, event, CoreEvent.builder(event), ((Component) flowConstruct).getLocation(), BindingContext.builder().build()); } }