Search in sources :

Example 1 with RegistrationException

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
    }
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) Test(org.junit.Test)

Example 2 with RegistrationException

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;
}
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 3 with RegistrationException

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;
}
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 4 with RegistrationException

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;
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 5 with RegistrationException

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);
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder) Transformer(org.mule.runtime.core.api.transformer.Transformer) DiscoverableTransformer(org.mule.runtime.core.api.transformer.DiscoverableTransformer) DiscoverableTransformer(org.mule.runtime.core.api.transformer.DiscoverableTransformer)

Aggregations

RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)8 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)3 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)3 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)3 SchedulerService (org.mule.runtime.api.scheduler.SchedulerService)2 StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)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 ComponentInitialStateManager (org.mule.runtime.api.deployment.management.ComponentInitialStateManager)1 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)1 MuleException (org.mule.runtime.api.exception.MuleException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 DataTypeParamsBuilder (org.mule.runtime.api.metadata.DataTypeParamsBuilder)1 NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)1 ObjectStoreManager (org.mule.runtime.api.store.ObjectStoreManager)1