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