Search in sources :

Example 31 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class AbstractMuleContextTestCase method verifyAndStopSchedulers.

protected static void verifyAndStopSchedulers() throws MuleException {
    final SchedulerService serviceImpl = muleContext.getSchedulerService();
    Set<String> schedulersOnInitNames = schedulersOnInit.stream().map(s -> s.getName()).collect(toSet());
    try {
        assertThat(muleContext.getSchedulerService().getSchedulers().stream().filter(s -> !schedulersOnInitNames.contains(s.getName())).collect(toList()), empty());
    } finally {
        if (serviceImpl instanceof SimpleUnitTestSupportSchedulerService) {
            stopIfNeeded(serviceImpl);
        }
    }
}
Also used : Message(org.mule.runtime.api.message.Message) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) Thread.currentThread(java.lang.Thread.currentThread) Assert.assertThat(org.junit.Assert.assertThat) LifecycleUtils.setMuleContextIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.setMuleContextIfNeeded) Map(java.util.Map) After(org.junit.After) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) StringUtils(org.mule.runtime.core.api.util.StringUtils) Collectors.toSet(java.util.stream.Collectors.toSet) AfterClass(org.junit.AfterClass) MuleContextFactory(org.mule.runtime.core.api.context.MuleContextFactory) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) DefaultMuleContextFactory(org.mule.runtime.core.api.context.DefaultMuleContextFactory) Set(java.util.Set) FileUtils.newFile(org.mule.runtime.core.api.util.FileUtils.newFile) List(java.util.List) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) Optional(java.util.Optional) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) QName(javax.xml.namespace.QName) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Mockito.mock(org.mockito.Mockito.mock) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) TestsLogConfigurationHelper.configureLoggingForTest(org.mule.tck.junit4.TestsLogConfigurationHelper.configureLoggingForTest) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) TestsLogConfigurationHelper.clearLoggingConfig(org.mule.tck.junit4.TestsLogConfigurationHelper.clearLoggingConfig) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) FileUtils.deleteTree(org.mule.runtime.core.api.util.FileUtils.deleteTree) ExpressionExecutor(org.mule.runtime.core.internal.el.ExpressionExecutor) ArrayList(java.util.ArrayList) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) MuleException(org.mule.runtime.api.exception.MuleException) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) JavaObjectSerializer(org.mule.runtime.core.internal.serialization.JavaObjectSerializer) Properties(java.util.Properties) Logger(org.slf4j.Logger) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) APPLE_FLOW(org.mule.tck.MuleTestUtils.APPLE_FLOW) SchedulerView(org.mule.runtime.api.scheduler.SchedulerView) File(java.io.File) MuleContextBuilder(org.mule.runtime.core.api.context.MuleContextBuilder) Collectors.toList(java.util.stream.Collectors.toList) Latch(org.mule.runtime.api.util.concurrent.Latch) HttpService(org.mule.runtime.http.api.HttpService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) ObjectSerializer(org.mule.runtime.api.serialization.ObjectSerializer) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemporaryFolder(org.junit.rules.TemporaryFolder) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService)

Example 32 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class DefaultFlowTestCase method lifecycleOrder.

@Test
public void lifecycleOrder() throws MuleException {
    Sink sink = mock(Sink.class, withSettings().extraInterfaces(Disposable.class));
    Processor processor = mock(Processor.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
    when(processingStrategy.createSink(any(FlowConstruct.class), any(ReactiveProcessor.class))).thenReturn(sink);
    flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(directInboundMessageSource).processors(singletonList(processor)).processingStrategyFactory((muleContext, s) -> processingStrategy).build();
    flow.initialise();
    flow.start();
    InOrder inOrder = inOrder(sink, processor, processingStrategy);
    inOrder.verify((Startable) processingStrategy).start();
    inOrder.verify(processingStrategy).createSink(any(FlowConstruct.class), any(ReactiveProcessor.class));
    inOrder.verify((Startable) processor).start();
    flow.stop();
    inOrder.verify((Disposable) sink).dispose();
    inOrder.verify((Stoppable) processor).stop();
    inOrder.verify((Stoppable) processingStrategy).stop();
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) INITIAL_STATE_STOPPED(org.mule.runtime.core.api.construct.Flow.INITIAL_STATE_STOPPED) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) BiFunction(java.util.function.BiFunction) DefaultFlow(org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow) Thread.currentThread(java.lang.Thread.currentThread) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Mono.just(reactor.core.publisher.Mono.just) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Assert.fail(org.junit.Assert.fail) Parameterized(org.junit.runners.Parameterized) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessage(org.mule.runtime.api.i18n.I18nMessage) StringAppendTransformer(org.mule.runtime.core.internal.transformer.simple.StringAppendTransformer) Collection(java.util.Collection) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Message.of(org.mule.runtime.api.message.Message.of) Flow(org.mule.runtime.core.api.construct.Flow) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) ResponseMessageProcessorAdapter(org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) Mockito.withSettings(org.mockito.Mockito.withSettings) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.mock(org.mockito.Mockito.mock) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) MessageSource(org.mule.runtime.core.api.source.MessageSource) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Mockito.spy(org.mockito.Mockito.spy) Processor(org.mule.runtime.core.api.processor.Processor) BLOCKING(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.BLOCKING) ArrayList(java.util.ArrayList) DEFAULT_MAX_CONCURRENCY(org.mule.runtime.core.api.processor.strategy.AsyncProcessingStrategyFactory.DEFAULT_MAX_CONCURRENCY) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Disposable(org.mule.runtime.api.lifecycle.Disposable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) BlockingProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.BlockingProcessingStrategyFactory) InOrder(org.mockito.InOrder) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Sink(org.mule.runtime.core.api.processor.Sink) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) Startable(org.mule.runtime.api.lifecycle.Startable) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) LifecycleTrackerProcessor(org.mule.tck.core.lifecycle.LifecycleTrackerProcessor) Processor(org.mule.runtime.core.api.processor.Processor) InOrder(org.mockito.InOrder) Sink(org.mule.runtime.core.api.processor.Sink) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) Test(org.junit.Test)

Example 33 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method createEvent.

protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) {
    InternalMessage message = mock(InternalMessage.class);
    when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType));
    when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType));
    try {
        return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build();
    } catch (MuleException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 34 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class ErrorHandlerTestCase method before.

@Before
public void before() throws MuleException {
    Error mockError = mock(Error.class);
    when(mockError.getErrorType()).thenReturn(mockErrorType);
    event = getEventBuilder().message(Message.of("")).error(mockError).build();
    mockException = new MessagingException(event, new Exception());
    CoreEvent handledEvent = testEvent();
    when(mockTestExceptionStrategy1.accept(any(CoreEvent.class))).thenReturn(true);
    when(mockTestExceptionStrategy1.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
    when(mockTestExceptionStrategy2.accept(any(CoreEvent.class))).thenReturn(true);
    when(mockTestExceptionStrategy2.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before)

Example 35 with MuleException

use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method returnsNullWhenInterruptedWhileWaitingForReply.

@Test
@Ignore("See MULE-8830")
public void returnsNullWhenInterruptedWhileWaitingForReply() throws Exception {
    final Latch fakeLatch = new Latch() {

        @Override
        public void await() throws InterruptedException {
            throw new InterruptedException();
        }
    };
    asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext) {

        @Override
        protected Latch createEventLock() {
            return fakeLatch;
        }
    };
    final CountDownLatch processingLatch = new CountDownLatch(1);
    Processor target = mock(Processor.class);
    asyncReplyMP.setListener(target);
    MessageSource messageSource = mock(MessageSource.class);
    asyncReplyMP.setReplySource(messageSource);
    asyncReplyMP.setMuleContext(muleContext);
    final boolean[] exceptionThrown = new boolean[1];
    final Object[] responseEvent = new Object[1];
    Thread thread = new Thread(() -> {
        try {
            responseEvent[0] = asyncReplyMP.process(testEvent());
        } catch (MuleException e) {
            exceptionThrown[0] = true;
        } finally {
            processingLatch.countDown();
        }
    });
    thread.start();
    assertTrue(processingLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
    assertFalse(exceptionThrown[0]);
    assertNull(responseEvent[0]);
}
Also used : SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Processor(org.mule.runtime.core.api.processor.Processor) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) CountDownLatch(java.util.concurrent.CountDownLatch) Latch(org.mule.runtime.api.util.concurrent.Latch) MessageSource(org.mule.runtime.core.api.source.MessageSource) CountDownLatch(java.util.concurrent.CountDownLatch) MuleException(org.mule.runtime.api.exception.MuleException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4