@Test public void createsContextListener() throws Exception { MuleContextListener contextListener = factory.create(APP_NAME); contextListener.onCreation(muleContext); verify(deploymentListener).onArtifactCreated(eq(APP_NAME), any(CustomizationService.class)); } }
@Test public void notifiesMuleContextEvents() throws InitialisationException, ConfigurationException { MuleContextListener listener = mock(MuleContextListener.class); ConfigurationBuilder configurationBuilder = mock(ConfigurationBuilder.class); context = mockMuleContext(); context = mockMuleContext(); doAnswer(invocation -> { listener.onInitialization(context, mock(Registry.class)); return null; }).when(context).initialise(); MuleContextBuilder contextBuilder = mock(MuleContextBuilder.class); when(contextBuilder.buildMuleContext()).thenReturn(context); muleContextFactory.addListener(listener); muleContextFactory.createMuleContext(configurationBuilder, contextBuilder); InOrder inOrder = inOrder(listener); inOrder.verify(listener).onCreation(context); inOrder.verify(listener).onInitialization(eq(context), any(Registry.class)); }
getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISED)); listeners.forEach(l -> l.onInitialization(this, getApiRegistry()));
/** * Stops the <code>MuleContext</code> which stops all sessions and connectors * * @throws MuleException if either any of the sessions or connectors fail to stop */ @Override public void stop() throws MuleException { synchronized (lifecycleStateLock) { startLatch.release(); stopIfNeeded(extensionManager); getLifecycleManager().checkPhase(Stoppable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_STOPPING)); getLifecycleManager().fireLifecycle(Stoppable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_STOPPED)); listeners.forEach(l -> l.onStop(this, getApiRegistry())); } }
@Override public void start() throws MuleException { synchronized (lifecycleStateLock) { getLifecycleManager().checkPhase(Startable.PHASE_NAME); if (getQueueManager() == null) { throw new MuleRuntimeException(objectIsNull("queueManager")); } componentInitialStateManager = muleRegistryHelper.get(OBJECT_COMPONENT_INITIAL_STATE_MANAGER); startDate = System.currentTimeMillis(); startIfNeeded(extensionManager); fireNotification(new MuleContextNotification(this, CONTEXT_STARTING)); getLifecycleManager().fireLifecycle(Startable.PHASE_NAME); overridePollingController(); overrideClusterConfiguration(); startMessageSources(); fireNotification(new MuleContextNotification(this, CONTEXT_STARTED)); listeners.forEach(l -> l.onStart(this, getApiRegistry())); startLatch.release(); if (logger.isInfoEnabled()) { SplashScreen startupScreen = buildStartupSplash(); logger.info(startupScreen.toString()); } } }
verify(muleContextListener).onCreation(muleContextCaptor.capture());
@Test public void notifiesMuleContextEvents() throws InitialisationException, ConfigurationException { MuleContextListener listener = mock(MuleContextListener.class); ConfigurationBuilder configurationBuilder = mock(ConfigurationBuilder.class); context = mockMuleContext(); context = mockMuleContext(); doAnswer(invocation -> { listener.onInitialization(context, null); return null; }).when(context).initialise(); MuleContextBuilder contextBuilder = mock(MuleContextBuilder.class); when(contextBuilder.buildMuleContext()).thenReturn(context); muleContextFactory.addListener(listener); muleContextFactory.createMuleContext(configurationBuilder, contextBuilder); InOrder inOrder = inOrder(listener); inOrder.verify(listener, times(1)).onCreation(context); inOrder.verify(listener, times(1)).onInitialization(eq(context), any(Registry.class)); }
private MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder, ContextConfigurator configurator) throws InitialisationException, ConfigurationException { MuleContext muleContext = buildMuleContext(muleContextBuilder); listeners.forEach(l -> l.onCreation(muleContext)); try { configurator.configure(muleContext); muleContext.initialise(); } catch (ConfigurationException e) { if (muleContext != null && !muleContext.isDisposed()) { try { muleContext.dispose(); } catch (Exception e1) { logger.warn("Can not dispose context. " + getMessage(e1)); if (logger.isDebugEnabled()) { logger.debug("Can not dispose context. " + getStackTrace(e1)); } } } throw e; } return muleContext; }
@Test public void createsContextListener() throws Exception { MuleContextListener contextListener = factory.create(APP_NAME); MuleContext context = mock(MuleContext.class); contextListener.onCreation(context); verify(deploymentListener).onArtifactCreated(eq(APP_NAME), any(CustomizationService.class)); } }
verify(muleContextListener).onCreation(muleContextCaptor.capture());