use of org.mule.runtime.core.privileged.registry.RegistrationException in project mule by mulesoft.
the class TransientRegistryTestCase method testLifecycleStateOutOfSequenceDisposeFirstWithTransientRegistryDirectly.
@Test
public void testLifecycleStateOutOfSequenceDisposeFirstWithTransientRegistryDirectly() throws Exception {
TransientRegistry reg = new TransientRegistry(UUID.getUUID(), muleContext, new MuleLifecycleInterceptor());
reg.fireLifecycle(Disposable.PHASE_NAME);
InterfaceBasedTracker tracker = new InterfaceBasedTracker();
try {
reg.registerObject(TEST_KEY, tracker);
fail("Cannot register objects on a disposed registry");
} catch (RegistrationException e) {
// Expected
}
}
use of org.mule.runtime.core.privileged.registry.RegistrationException 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.privileged.registry.RegistrationException 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.privileged.registry.RegistrationException in project mule by mulesoft.
the class DefaultMuleContext method getSchedulerService.
@Override
public SchedulerService getSchedulerService() {
if (this.schedulerService == null) {
try {
this.schedulerService = this.getRegistry().lookupObject(SchedulerService.class);
requireNonNull(schedulerService);
} catch (RegistrationException e) {
throw new MuleRuntimeException(e);
}
}
return this.schedulerService;
}
use of org.mule.runtime.core.privileged.registry.RegistrationException in project mule by mulesoft.
the class SimpleRegistryBootstrap method doRegisterTransformer.
@Override
protected void doRegisterTransformer(TransformerBootstrapProperty bootstrapProperty, Class<?> returnClass, Class<? extends Transformer> transformerClass) throws Exception {
Transformer trans = ClassUtils.instantiateClass(transformerClass);
if (!(trans instanceof DiscoverableTransformer)) {
throw new RegistrationException(CoreMessages.transformerNotImplementDiscoverable(trans));
}
if (returnClass != null) {
DataTypeParamsBuilder builder = DataType.builder().type(returnClass);
if (isNotEmpty(bootstrapProperty.getMimeType())) {
builder = builder.mediaType(bootstrapProperty.getMimeType());
}
trans.setReturnDataType(builder.build());
}
if (bootstrapProperty.getName() != null) {
trans.setName(bootstrapProperty.getName());
} else {
// Prefixes the generated default name to ensure there is less chance of conflict if the user registers
// the transformer with the same name
trans.setName("_" + trans.getName());
}
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(trans);
}
Aggregations