Search in sources :

Example 26 with ComponentLocation

use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.

the class AbstractMuleTestCase method addMockComponentLocation.

/**
 * Utility method to add a mock component location.
 *
 * @param component object to add the location.
 */
protected void addMockComponentLocation(Component component) {
    ComponentLocation componentLocation = mock(ComponentLocation.class, RETURNS_DEEP_STUBS);
    Mockito.when(componentLocation.getLineInFile()).thenReturn(empty());
    Mockito.when(componentLocation.getFileName()).thenReturn(empty());
    component.setAnnotations(Collections.singletonMap(LOCATION_KEY, componentLocation));
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation)

Example 27 with ComponentLocation

use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.

the class MessageProcessingFlowTraceManagerTestCase method before.

@Before
public void before() {
    manager = new MessageProcessingFlowTraceManager();
    MuleContext context = mock(MuleContext.class);
    MuleConfiguration config = mock(MuleConfiguration.class);
    when(config.getId()).thenReturn(APP_ID);
    when(context.getConfiguration()).thenReturn(config);
    manager.setMuleContext(context);
    rootFlowConstruct = mock(FlowConstruct.class);
    ComponentLocation mockComponentLocation = mock(ComponentLocation.class);
    when(mockComponentLocation.getFileName()).thenReturn(of(CONFIG_FILE_NAME));
    when(mockComponentLocation.getLineInFile()).thenReturn(of(LINE_NUMBER));
    when(rootFlowConstruct.getLocation()).thenReturn(mockComponentLocation);
    when(rootFlowConstruct.getName()).thenReturn(ROOT_FLOW_NAME);
    when(rootFlowConstruct.getMuleContext()).thenReturn(context);
    nestedFlowConstruct = mock(FlowConstruct.class);
    when(nestedFlowConstruct.getLocation()).thenReturn(mockComponentLocation);
    when(nestedFlowConstruct.getName()).thenReturn(NESTED_FLOW_NAME);
    when(nestedFlowConstruct.getMuleContext()).thenReturn(context);
    messageContext = create(rootFlowConstruct, TEST_CONNECTOR_LOCATION);
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Before(org.junit.Before)

Example 28 with ComponentLocation

use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.

the class AbstractMessageTransformer method transform.

@Override
public final Object transform(Object src, Charset enc, CoreEvent event) throws MessageTransformerException {
    DataType sourceType = DataType.fromType(src.getClass());
    if (!isSourceDataTypeSupported(sourceType)) {
        if (isIgnoreBadInput()) {
            logger.debug("Source type is incompatible with this transformer and property 'ignoreBadInput' is set to true, so the transformer chain will continue.");
            return src;
        } else {
            I18nMessage msg = CoreMessages.transformOnObjectUnsupportedTypeOfEndpoint(getName(), src.getClass());
            throw new MessageTransformerException(msg, this, event.getMessage());
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug(format("Applying transformer %s (%s)", getName(), getClass().getName()));
        logger.debug(format("Object before transform: %s", StringMessageUtils.toString(src)));
    }
    Message message;
    if (src instanceof Message) {
        message = (Message) src;
    } else // TODO MULE-9342 Clean up transformer vs message transformer confusion
    if (src instanceof CoreEvent) {
        event = (CoreEvent) src;
        message = event.getMessage();
    } else if (muleContext.getConfiguration().isAutoWrapMessageAwareTransform()) {
        message = of(src);
    } else {
        if (event == null) {
            throw new MessageTransformerException(CoreMessages.noCurrentEventForTransformer(), this, null);
        }
        message = event.getMessage();
    }
    Object result;
    // TODO MULE-9342 Clean up transformer vs message transformer confusion
    if (event == null) {
        MuleClientFlowConstruct flowConstruct = new MuleClientFlowConstruct(muleContext);
        ComponentLocation location = getLocation() != null ? getLocation() : fromSingleComponent("AbstractMessageTransformer");
        event = InternalEvent.builder(create(flowConstruct, location)).message(message).build();
    }
    result = transformMessage(event, enc);
    if (logger.isDebugEnabled()) {
        logger.debug(format("Object after transform: %s", StringMessageUtils.toString(result)));
    }
    result = checkReturnClass(result, event);
    return result;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleClientFlowConstruct(org.mule.runtime.core.privileged.client.MuleClientFlowConstruct) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) I18nMessage(org.mule.runtime.api.i18n.I18nMessage)

Example 29 with ComponentLocation

use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.

the class ReactiveInterceptorAdapter method apply.

// TODO MULE-13449 Loggers in this method must be INFO
@Override
public ReactiveProcessor apply(Processor component, ReactiveProcessor next) {
    if (!isInterceptable(component)) {
        return next;
    }
    final ComponentLocation componentLocation = ((Component) component).getLocation();
    if (!interceptorFactory.intercept(componentLocation)) {
        return next;
    }
    final ProcessorInterceptor interceptor = interceptorFactory.get();
    Map<String, String> dslParameters = (Map<String, String>) ((Component) component).getAnnotation(ANNOTATION_PARAMETERS);
    ReactiveProcessor interceptedProcessor = doApply(component, next, componentLocation, interceptor, dslParameters);
    LOGGER.debug("Interceptor '{}' for processor '{}' configured.", interceptor, componentLocation.getLocation());
    return interceptedProcessor;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Component(org.mule.runtime.api.component.Component) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) LazyMap(org.apache.commons.collections.map.LazyMap)

Example 30 with ComponentLocation

use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.

the class SourceWithComponentLocationTestCase method injectedComponentLocation.

@Test
public void injectedComponentLocation() throws Exception {
    ComponentLocation location = SentientSource.capturedLocation;
    assertThat(location, is(notNullValue()));
    assertThat(location.getRootContainerName(), equalTo("sentient"));
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) Test(org.junit.Test)

Aggregations

ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)54 Test (org.junit.Test)46 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)44 SmallTest (org.mule.tck.size.SmallTest)44 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)43 InOrder (org.mockito.InOrder)41 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)41 ProcessorParameterValue (org.mule.runtime.api.interception.ProcessorParameterValue)35 CompletableFuture (java.util.concurrent.CompletableFuture)29 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)28 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)26 InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)24 ExpressionRuntimeException (org.mule.runtime.core.api.expression.ExpressionRuntimeException)23 Map (java.util.Map)7 Component (org.mule.runtime.api.component.Component)7 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)7 HashMap (java.util.HashMap)6 MuleException (org.mule.runtime.api.exception.MuleException)6 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)6 Message (org.mule.runtime.api.message.Message)6