Search in sources :

Example 1 with Component

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

the class MessageProcessingFlowTraceManagerTestCase method createMockProcessor.

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;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) Processor(org.mule.runtime.core.api.processor.Processor) Component(org.mule.runtime.api.component.Component)

Example 2 with Component

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

the class MessageProcessingFlowTraceManagerTestCase method newAnnotatedComponentCall.

@Test
public void newAnnotatedComponentCall() {
    CoreEvent event = buildEvent("newAnnotatedComponentCall");
    PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName());
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
    manager.onPipelineNotificationStart(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName()));
    Component annotatedMessageProcessor = (Component) createMockProcessor("/comp", true);
    when(annotatedMessageProcessor.getAnnotation(docNameAttrName)).thenReturn("annotatedName");
    manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, (Processor) annotatedMessageProcessor));
    assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":muleApp.xml:10 (annotatedName))"));
    manager.onPipelineNotificationComplete(pipelineNotification);
    assertThat(getContextInfo(event, rootFlowConstruct), is(""));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) PipelineMessageNotification(org.mule.runtime.api.notification.PipelineMessageNotification) Component(org.mule.runtime.api.component.Component) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with Component

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

the class ComponentInvocationHandlerTestCase method notAnnotated.

@Test
public void notAnnotated() throws Exception {
    Component annotated = addAnnotationsToClass(NotAnnotated.class).newInstance();
    assertThat(annotated.getAnnotations().keySet(), empty());
    annotated.setAnnotations(singletonMap(LOCATION_KEY, "value"));
    assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY));
    assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true));
    assertThat(removeDynamicAnnotations(annotated), instanceOf(NotAnnotated.class));
    assertThat(removeDynamicAnnotations(annotated), not(instanceOf(Component.class)));
}
Also used : Inject(javax.inject.Inject) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with Component

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

the class ComponentInvocationHandlerTestCase method implementsInitialisable.

@Test
public void implementsInitialisable() throws Exception {
    Component annotated = addAnnotationsToClass(ImplementsInitialisable.class).newInstance();
    assertThat(annotated.getAnnotations().keySet(), empty());
    annotated.setAnnotations(singletonMap(LOCATION_KEY, "value"));
    assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY));
}
Also used : Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with Component

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

the class ComponentInvocationHandlerTestCase method extendsAbstractAnnotated.

@Test
public void extendsAbstractAnnotated() throws Exception {
    Component annotated = addAnnotationsToClass(ExtendsAnnotated.class).newInstance();
    assertThat(annotated.getAnnotations().keySet(), empty());
    annotated.setAnnotations(singletonMap(LOCATION_KEY, "value"));
    assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY));
    assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true));
}
Also used : Inject(javax.inject.Inject) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Component (org.mule.runtime.api.component.Component)39 Test (org.junit.Test)15 Map (java.util.Map)12 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)12 SmallTest (org.mule.tck.size.SmallTest)11 Optional (java.util.Optional)9 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 List (java.util.List)8 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)8 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 HashMap (java.util.HashMap)6 String.format (java.lang.String.format)5 Optional.empty (java.util.Optional.empty)5 Optional.of (java.util.Optional.of)5 Set (java.util.Set)5 Inject (javax.inject.Inject)5 Arrays.asList (java.util.Arrays.asList)4 Collection (java.util.Collection)4