Search in sources :

Example 1 with SimpleUnitTestSupportSchedulerService

use of org.mule.tck.SimpleUnitTestSupportSchedulerService in project mule by mulesoft.

the class MuleObjectStoreManagerTestCase method setup.

@Before
public void setup() {
    schedulerService = new SimpleUnitTestSupportSchedulerService();
    muleContext = mock(MuleContextWithRegistries.class);
    MuleConfiguration muleConfiguration = mock(MuleConfiguration.class);
    when(muleConfiguration.getWorkingDirectory()).thenReturn(tempWorkDir.getRoot().getAbsolutePath());
    when(muleContext.getConfiguration()).thenReturn(muleConfiguration);
    Registry registry = mock(Registry.class);
    createRegistryAndBaseStore(muleContext, registry);
    when(muleContext.getSchedulerBaseConfig()).thenReturn(config().withPrefix(MuleObjectStoreManagerTestCase.class.getName() + "#" + name.getMethodName()));
    storeManager = new MuleObjectStoreManager();
    storeManager.setSchedulerService(schedulerService);
    storeManager.setRegistry(registry);
    storeManager.setMuleContext(muleContext);
}
Also used : MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) Registry(org.mule.runtime.api.artifact.Registry) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Before(org.junit.Before)

Example 2 with SimpleUnitTestSupportSchedulerService

use of org.mule.tck.SimpleUnitTestSupportSchedulerService in project mule by mulesoft.

the class AbstractMuleContextTestCase method verifyAndStopSchedulers.

protected static void verifyAndStopSchedulers() throws MuleException {
    final SchedulerService serviceImpl = muleContext.getSchedulerService();
    Set<String> schedulersOnInitNames = schedulersOnInit.stream().map(s -> s.getName()).collect(toSet());
    try {
        assertThat(muleContext.getSchedulerService().getSchedulers().stream().filter(s -> !schedulersOnInitNames.contains(s.getName())).collect(toList()), empty());
    } finally {
        if (serviceImpl instanceof SimpleUnitTestSupportSchedulerService) {
            stopIfNeeded(serviceImpl);
        }
    }
}
Also used : Message(org.mule.runtime.api.message.Message) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) Thread.currentThread(java.lang.Thread.currentThread) Assert.assertThat(org.junit.Assert.assertThat) LifecycleUtils.setMuleContextIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.setMuleContextIfNeeded) Map(java.util.Map) After(org.junit.After) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) StringUtils(org.mule.runtime.core.api.util.StringUtils) Collectors.toSet(java.util.stream.Collectors.toSet) AfterClass(org.junit.AfterClass) MuleContextFactory(org.mule.runtime.core.api.context.MuleContextFactory) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) DefaultMuleContextFactory(org.mule.runtime.core.api.context.DefaultMuleContextFactory) Set(java.util.Set) FileUtils.newFile(org.mule.runtime.core.api.util.FileUtils.newFile) List(java.util.List) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) TriggerableMessageSource(org.mule.tck.TriggerableMessageSource) Optional(java.util.Optional) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) QName(javax.xml.namespace.QName) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Mockito.mock(org.mockito.Mockito.mock) SimpleConfigurationBuilder(org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder) TestsLogConfigurationHelper.configureLoggingForTest(org.mule.tck.junit4.TestsLogConfigurationHelper.configureLoggingForTest) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) TestsLogConfigurationHelper.clearLoggingConfig(org.mule.tck.junit4.TestsLogConfigurationHelper.clearLoggingConfig) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) FileUtils.deleteTree(org.mule.runtime.core.api.util.FileUtils.deleteTree) ExpressionExecutor(org.mule.runtime.core.internal.el.ExpressionExecutor) ArrayList(java.util.ArrayList) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) MuleException(org.mule.runtime.api.exception.MuleException) ConfigurationBuilder(org.mule.runtime.core.api.config.ConfigurationBuilder) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) JavaObjectSerializer(org.mule.runtime.core.internal.serialization.JavaObjectSerializer) Properties(java.util.Properties) Logger(org.slf4j.Logger) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) APPLE_FLOW(org.mule.tck.MuleTestUtils.APPLE_FLOW) SchedulerView(org.mule.runtime.api.scheduler.SchedulerView) File(java.io.File) MuleContextBuilder(org.mule.runtime.core.api.context.MuleContextBuilder) Collectors.toList(java.util.stream.Collectors.toList) Latch(org.mule.runtime.api.util.concurrent.Latch) HttpService(org.mule.runtime.http.api.HttpService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) ObjectSerializer(org.mule.runtime.api.serialization.ObjectSerializer) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemporaryFolder(org.junit.rules.TemporaryFolder) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService)

Example 3 with SimpleUnitTestSupportSchedulerService

use of org.mule.tck.SimpleUnitTestSupportSchedulerService 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)

Aggregations

SimpleUnitTestSupportSchedulerService (org.mule.tck.SimpleUnitTestSupportSchedulerService)3 Before (org.junit.Before)2 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)2 SchedulerService (org.mule.runtime.api.scheduler.SchedulerService)2 MuleConfiguration (org.mule.runtime.core.api.config.MuleConfiguration)2 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 Thread.currentThread (java.lang.Thread.currentThread)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Set (java.util.Set)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1