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));
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations