Search in sources :

Example 6 with DefaultsConfigurationBuilder

use of org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder in project mule by mulesoft.

the class MuleContextLifecycleTestCase method disposeOnStopped.

@Test
public void disposeOnStopped() throws Exception {
    ctx.initialise();
    new DefaultsConfigurationBuilder().configure(ctx);
    ctx.start();
    ctx.stop();
    ctx.dispose();
    assertFalse(ctx.isInitialised());
    assertFalse(ctx.isInitialising());
    assertFalse(ctx.isStarted());
    assertTrue(ctx.isDisposed());
    assertFalse(ctx.isDisposing());
    assertLifecycleManagerDidApplyAllPhases();
}
Also used : DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) Test(org.junit.Test)

Example 7 with DefaultsConfigurationBuilder

use of org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder in project mule by mulesoft.

the class MuleContextLifecycleTestCase method notificationHasMuleContextRef.

@Test
public void notificationHasMuleContextRef() throws Exception {
    ctx.initialise();
    new DefaultsConfigurationBuilder().configure(ctx);
    final AtomicReference<MuleContext> contextFromNotification = new AtomicReference<>();
    final AtomicReference<String> resourceId = new AtomicReference<>();
    MuleContextNotificationListener<MuleContextNotification> listener = notification -> {
        contextFromNotification.set(notification.getMuleContext());
        resourceId.set(notification.getResourceIdentifier());
    };
    notificationListenerRegistry.registerListener(listener);
    ctx.start();
    assertNotNull(contextFromNotification.get());
    assertSame(ctx, contextFromNotification.get());
    assertEquals(ctx.getConfiguration().getId(), resourceId.get());
}
Also used : Arrays(java.util.Arrays) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) MuleContextListener(org.mule.runtime.core.api.context.notification.MuleContextListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleAssert.assertTrue(org.mule.tck.MuleAssert.assertTrue) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) CONTEXT_STARTED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STARTED) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) DefaultMuleContextBuilder(org.mule.runtime.core.internal.context.DefaultMuleContextBuilder) MuleException(org.mule.runtime.api.exception.MuleException) After(org.junit.After) CONTEXT_STOPPED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPED) Assert.fail(org.junit.Assert.fail) Registry(org.mule.runtime.api.artifact.Registry) MuleContextLifecycleManager(org.mule.runtime.core.internal.lifecycle.MuleContextLifecycleManager) JdkVersionUtils(org.mule.runtime.core.internal.util.JdkVersionUtils) Before(org.junit.Before) Disposable(org.mule.runtime.api.lifecycle.Disposable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Startable(org.mule.runtime.api.lifecycle.Startable) Assert.assertNotNull(org.junit.Assert.assertNotNull) CONTEXT_STOPPING(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPING) UUID(org.mule.runtime.core.api.util.UUID) Assert.assertTrue(org.junit.Assert.assertTrue) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) Test(org.junit.Test) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) CONTEXT_STARTING(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STARTING) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) DefaultNotificationListenerRegistry(org.mule.runtime.core.internal.context.notification.DefaultNotificationListenerRegistry) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) SecurityManager(org.mule.runtime.core.api.security.SecurityManager) MuleContext(org.mule.runtime.core.api.MuleContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) Test(org.junit.Test)

Example 8 with DefaultsConfigurationBuilder

use of org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder in project mule by mulesoft.

the class MuleContextLifecycleTestCase method disposeOnStarted.

@Test
public void disposeOnStarted() throws Exception {
    ctx.initialise();
    assertTrue("onInitialization never called on listener", callbackListener.wasInitialized);
    new DefaultsConfigurationBuilder().configure(ctx);
    final TestNotificationListener notificationListener = new TestNotificationListener();
    notificationListenerRegistry.registerListener(notificationListener);
    ctx.start();
    assertTrue("onStart never called on listener", callbackListener.wasStarted);
    ctx.dispose();
    assertFalse(ctx.isInitialised());
    assertFalse(ctx.isInitialising());
    assertFalse(ctx.isStarted());
    assertTrue(ctx.isDisposed());
    assertFalse(ctx.isDisposing());
    // disposing started must go through stop
    assertLifecycleManagerDidApplyAllPhases();
    assertTrue("CONTEXT_STOPPING notification never fired", notificationListener.stoppingNotificationFired.get());
    assertTrue("CONTEXT_STOPPED notification never fired", notificationListener.stoppedNotificationFired.get());
    assertTrue("onStop never called on listener", callbackListener.wasStopped);
}
Also used : DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) Test(org.junit.Test)

Example 9 with DefaultsConfigurationBuilder

use of org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder in project mule by mulesoft.

the class MuleContextLifecycleTestCase method initialiseOnDisposed.

@Test(expected = IllegalStateException.class)
public void initialiseOnDisposed() throws Exception {
    ctx.initialise();
    new DefaultsConfigurationBuilder().configure(ctx);
    ctx.start();
    ctx.stop();
    ctx.dispose();
    // Attempt to initialise once disposed should fail!
    ctx.initialise();
}
Also used : DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) Test(org.junit.Test)

Example 10 with DefaultsConfigurationBuilder

use of org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder in project mule by mulesoft.

the class MuleContextLifecycleTestCase method startOnInitialised.

@Test
public void startOnInitialised() throws Exception {
    ctx.initialise();
    new DefaultsConfigurationBuilder().configure(ctx);
    TestNotificationListener notificationListener = new TestNotificationListener();
    notificationListenerRegistry.registerListener(notificationListener);
    ctx.start();
    assertTrue(ctx.isInitialised());
    assertFalse(ctx.isInitialising());
    assertTrue(ctx.isStarted());
    assertFalse(ctx.isDisposed());
    assertFalse(ctx.isDisposing());
    assertTrue("CONTEXT_STARTING notification never fired", notificationListener.startingNotificationFired);
    assertTrue("CONTEXT_STARTED notification never fired", notificationListener.startedNotificationFired);
    assertTrue("onInitialization never called on listener", callbackListener.wasInitialized);
    assertTrue("onStart never called on listener", callbackListener.wasStarted);
}
Also used : DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) Test(org.junit.Test)

Aggregations

DefaultsConfigurationBuilder (org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)2 DefaultMuleContextFactory (org.mule.runtime.core.api.context.DefaultMuleContextFactory)2 TestServicesConfigurationBuilder (org.mule.tck.config.TestServicesConfigurationBuilder)2 Arrays (java.util.Arrays)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 TransactionManager (javax.transaction.TransactionManager)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Mockito.mock (org.mockito.Mockito.mock)1