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));
}
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);
}
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;
}
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;
}
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"));
}
Aggregations