Search in sources :

Example 1 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method resolvesCoreExtensionDependencies.

@Test
public void resolvesCoreExtensionDependencies() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    MuleCoreExtension extension = mock(MuleCoreExtension.class);
    extensions.add(extension);
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    coreExtensionManager.initialise();
    verify(coreExtensionDependencyResolver).resolveDependencies(extensions);
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method injectsServiceOnExtension.

@Test
public void injectsServiceOnExtension() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    InjectedTestServiceExtension extension = mock(InjectedTestServiceExtension.class);
    extensions.add(extension);
    TestService service = mock(TestService.class);
    when(service.getName()).thenReturn("testService");
    ServiceRepository serviceRepository = mock(ServiceRepository.class);
    when(serviceRepository.getServices()).thenReturn(Collections.singletonList(service));
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(extensions);
    coreExtensionManager.setServiceRepository(serviceRepository);
    coreExtensionManager.initialise();
    verify(extension).setService(service);
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) ServiceRepository(org.mule.runtime.api.service.ServiceRepository) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method disposesCoreExtensionsAfterStartFail.

@Test
public void disposesCoreExtensionsAfterStartFail() throws Exception {
    List<MuleCoreExtension> extensions = new LinkedList<>();
    MuleCoreExtension extension1 = mock(MuleCoreExtension.class);
    MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
    Exception firstStartFailure = new RuntimeException();
    doThrow(firstStartFailure).when(extension1).initialise();
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    extensions.add(extension1);
    extensions.add(extension2);
    List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
    orderedExtensions.add(extension1);
    orderedExtensions.add(extension2);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
    try {
        coreExtensionManager.initialise();
        fail();
    } catch (Exception e) {
        assertThat(e.getCause(), sameInstance(firstStartFailure));
    }
    coreExtensionManager.dispose();
    verify(extension2, never()).dispose();
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerTestCase method testAllCoreExtensionsAreStoppedAfterRuntimeException.

@Test
public void testAllCoreExtensionsAreStoppedAfterRuntimeException() throws Exception {
    TestDeploymentServiceAwareExtension extensionFailsStops = mock(TestDeploymentServiceAwareExtension.class);
    TestDeploymentServiceAwareExtension extensionStopsOk = mock(TestDeploymentServiceAwareExtension.class);
    InOrder stopsInOrder = inOrder(extensionFailsStops, extensionStopsOk);
    List<MuleCoreExtension> extensions = new LinkedList<>();
    when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
    when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(extensions);
    doThrow(RuntimeException.class).when(extensionFailsStops).stop();
    extensions.add(extensionStopsOk);
    extensions.add(extensionFailsStops);
    coreExtensionManager.initialise();
    coreExtensionManager.start();
    try {
        coreExtensionManager.stop();
    } finally {
        stopsInOrder.verify(extensionFailsStops).stop();
        stopsInOrder.verify(extensionStopsOk).stop();
    }
}
Also used : InOrder(org.mockito.InOrder) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class ReflectionMuleCoreExtensionDependencyResolverTestCase method resolvesOrderedCoreExtensionAwareExtensions.

@Test
public void resolvesOrderedCoreExtensionAwareExtensions() throws Exception {
    MuleCoreExtension coreExtensionsAwareExtension1 = mockCoreExtension(EXTENSION1);
    MuleCoreExtension coreExtensionsAwareExtension2 = mockCoreExtension(EXTENSION2);
    List<MuleCoreExtension> coreExtensions = new LinkedList<>();
    coreExtensions.add(coreExtensionsAwareExtension1);
    coreExtensions.add(coreExtensionsAwareExtension2);
    final List<MuleCoreExtension> resolvedCoreExtensions = dependencyResolver.resolveDependencies(coreExtensions);
    assertThat(resolvedCoreExtensions.size(), equalTo(2));
    assertThat(resolvedCoreExtensions.get(0), sameInstance(coreExtensionsAwareExtension1));
    assertThat(resolvedCoreExtensions.get(1), sameInstance(coreExtensionsAwareExtension2));
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

MuleCoreExtension (org.mule.runtime.container.api.MuleCoreExtension)23 LinkedList (java.util.LinkedList)17 Test (org.junit.Test)15 SmallTest (org.mule.tck.size.SmallTest)14 InOrder (org.mockito.InOrder)5 MuleException (org.mule.runtime.api.exception.MuleException)4 URL (java.net.URL)2 ExpectedException (org.junit.rules.ExpectedException)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 Map (java.util.Map)1 Properties (java.util.Properties)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ServiceRepository (org.mule.runtime.api.service.ServiceRepository)1 ArtifactClassLoaderManagerAware (org.mule.runtime.container.api.ArtifactClassLoaderManagerAware)1 CoreExtensionsAware (org.mule.runtime.container.api.CoreExtensionsAware)1 Injector (org.mule.runtime.core.api.Injector)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 PropertiesUtils.loadProperties (org.mule.runtime.core.api.util.PropertiesUtils.loadProperties)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1 ArtifactDeploymentListener (org.mule.runtime.module.deployment.api.ArtifactDeploymentListener)1