Search in sources :

Example 6 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class TestServicesConfigurationBuilder method doConfigure.

@Override
public void doConfigure(MuleContext muleContext) throws Exception {
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    registry.registerObject(schedulerService.getName(), spy(schedulerService));
    registry.registerObject(OBJECT_SCHEDULER_BASE_CONFIG, config());
    if (mockExpressionExecutor) {
        DefaultExpressionLanguageFactoryService expressionExecutor = mock(DefaultExpressionLanguageFactoryService.class, RETURNS_DEEP_STUBS);
        registry.registerObject(MOCK_EXPR_EXECUTOR, expressionExecutor);
    } else {
        // Avoid doing the DW warm-up for every test, reusing the ExpressionLanguage implementation
        if (cachedExprLanguageFactory == null) {
            final DefaultExpressionLanguageFactoryService exprExecutor = new WeaveDefaultExpressionLanguageFactoryService();
            ExpressionLanguage exprLanguage = exprExecutor.create();
            // Force initialization of internal DataWeave stuff
            // This way we avoid doing some heavy initialization on the test itself,
            // which may cause trouble when evaluation expressions in places with small timeouts
            exprLanguage.evaluate("{dataWeave: 'is'} ++ {mule: 'default EL'}", NULL_BINDING_CONTEXT);
            cachedExprLanguageFactory = new DefaultExpressionLanguageFactoryService() {

                @Override
                public ExpressionLanguage create() {
                    return exprLanguage;
                }

                @Override
                public String getName() {
                    return exprExecutor.getName();
                }
            };
        }
        registry.registerObject(cachedExprLanguageFactory.getName(), cachedExprLanguageFactory);
    }
    if (mockHttpService) {
        registry.registerObject(MOCK_HTTP_SERVICE, mock(HttpService.class));
    }
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) HttpService(org.mule.runtime.http.api.HttpService) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) ExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage)

Example 7 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class MuleContextUtils method mockContextWithServices.

/**
 * Creates and configures a mock {@link MuleContext} to return testing services implementations.
 *
 * @return the created {@code muleContext}.
 */
public static MuleContextWithRegistries mockContextWithServices() {
    final MuleContextWithRegistries muleContext = mockMuleContext();
    SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
    when(muleContext.getSchedulerService()).thenReturn(schedulerService);
    ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
    when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
    when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
    final MuleRegistry registry = muleContext.getRegistry();
    NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
    ConfigurationProperties configProps = mock(ConfigurationProperties.class);
    when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
    ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
    when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
    when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
    try {
        when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
        Map<Class, Object> injectableObjects = new HashMap<>();
        injectableObjects.put(MuleContext.class, muleContext);
        injectableObjects.put(SchedulerService.class, schedulerService);
        injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
        injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
        injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
        injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
        injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
        injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
        injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
        injectableObjects.put(ConfigurationProperties.class, configProps);
        // Ensure injection of consistent mock objects
        when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
    } catch (RegistrationException e1) {
        throw new MuleRuntimeException(e1);
    }
    return muleContext;
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) HashMap(java.util.HashMap) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Location(org.mule.runtime.api.component.location.Location)

Example 8 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class MuleContextUtils method mockMuleContext.

public static MuleContextWithRegistries mockMuleContext() {
    final MuleContextWithRegistries muleContext = mock(DefaultMuleContext.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS).extraInterfaces(PrivilegedMuleContext.class));
    when(muleContext.getUniqueIdString()).thenReturn(UUID.getUUID());
    when(muleContext.getDefaultErrorHandler(empty())).thenReturn(new OnErrorPropagateHandler());
    StreamingManager streamingManager = mock(StreamingManager.class, RETURNS_DEEP_STUBS);
    try {
        MuleRegistry registry = mock(MuleRegistry.class);
        when(muleContext.getRegistry()).thenReturn(registry);
        ComponentInitialStateManager componentInitialStateManager = mock(ComponentInitialStateManager.class);
        when(componentInitialStateManager.mustStartMessageSource(any())).thenReturn(true);
        when(registry.lookupObject(ComponentInitialStateManager.SERVICE_ID)).thenReturn(componentInitialStateManager);
        doReturn(streamingManager).when(registry).lookupObject(StreamingManager.class);
        doReturn(mock(NotificationDispatcher.class)).when(registry).lookupObject(NotificationDispatcher.class);
        doReturn(mock(ObjectStoreManager.class, RETURNS_DEEP_STUBS)).when(registry).lookupObject(OBJECT_STORE_MANAGER);
    } catch (RegistrationException e) {
        throw new RuntimeException(e);
    }
    return muleContext;
}
Also used : ComponentInitialStateManager(org.mule.runtime.api.deployment.management.ComponentInitialStateManager) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectStoreManager(org.mule.runtime.api.store.ObjectStoreManager) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OnErrorPropagateHandler(org.mule.runtime.core.internal.exception.OnErrorPropagateHandler) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext)

Example 9 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class AbstractAsyncRequestReplyRequester method initialise.

@Override
public void initialise() throws InitialisationException {
    name = format(NAME_TEMPLATE, storePrefix, muleContext.getConfiguration().getId(), getLocation().getRootContainerName());
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    store = ((ObjectStoreManager) registry.get(OBJECT_STORE_MANAGER)).createObjectStore(name, ObjectStoreSettings.builder().persistent(false).maxEntries(MAX_PROCESSED_GROUPS).entryTtl(UNCLAIMED_TIME_TO_LIVE).expirationInterval(UNCLAIMED_INTERVAL).build());
    try {
        notificationFirer = registry.lookupObject(NotificationDispatcher.class);
    } catch (RegistrationException e) {
        throw new InitialisationException(e, this);
    }
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException)

Example 10 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class ExtensionPluginMetadataGenerator method createExtensionManager.

/**
 * Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
 * the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
 * created as result of the classification process.
 *
 * @return an {@link ExtensionManager} that would be used to register the extensions.
 */
private ExtensionManager createExtensionManager() {
    DefaultExtensionManager extensionManager = new DefaultExtensionManager();
    extensionManager.setMuleContext(new DefaultMuleContext() {

        private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();

        private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);

        @Override
        public MuleRegistry getRegistry() {
            return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
        }

        @Override
        public ErrorTypeLocator getErrorTypeLocator() {
            return errorTypeLocator;
        }

        @Override
        public ErrorTypeRepository getErrorTypeRepository() {
            return errorTypeRepository;
        }
    });
    try {
        extensionManager.initialise();
    } catch (InitialisationException e) {
        throw new RuntimeException("Error while initialising the extension manager", e);
    }
    return extensionManager;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Aggregations

MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)11 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)8 Test (org.junit.Test)3 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)3 StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)3 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)3 ComponentInitialStateManager (org.mule.runtime.api.deployment.management.ComponentInitialStateManager)2 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 Transformer (org.mule.runtime.core.api.transformer.Transformer)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Component (org.mule.runtime.api.component.Component)1 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)1 ConfigurationProperties (org.mule.runtime.api.component.ConfigurationProperties)1 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)1 Location (org.mule.runtime.api.component.location.Location)1 DefaultExpressionLanguageFactoryService (org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)1