use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method extensionTakesPrecedenceOverAutoResolved.
@Test
public void extensionTakesPrecedenceOverAutoResolved() throws Exception {
PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(of("")).addVariable("foo", "other").build();
((MuleContextWithRegistries) muleContext).getRegistry().registerObject("key", (ExpressionLanguageExtension) context -> context.addVariable("foo", "bar"));
mvel.initialise();
assertEquals("bar", evaluate("foo", event));
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class DefaultExpressionManagerTestCase method doNotRegistersMelWhenCompatibilityPluginIsNotInstalled.
@Test
public void doNotRegistersMelWhenCompatibilityPluginIsNotInstalled() throws Exception {
Registry registry = mock(Registry.class);
when(registry.lookupByType(DefaultExpressionLanguageFactoryService.class)).thenReturn(of(mock(DefaultExpressionLanguageFactoryService.class, RETURNS_DEEP_STUBS)));
when(registry.lookupByName(COMPATIBILITY_PLUGIN_INSTALLED)).thenReturn(empty());
final MuleContextWithRegistries mockMuleContext = MuleContextUtils.mockMuleContext();
MuleConfiguration config = mockMuleContext.getConfiguration();
doReturn(true).when(config).isValidateExpressions();
expressionManager = new DefaultExpressionManager();
((DefaultExpressionManager) expressionManager).setRegistry(registry);
((DefaultExpressionManager) expressionManager).setMuleContext(mockMuleContext);
initialiseIfNeeded(expressionManager, false, mockMuleContext);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("There is no expression language registered for 'mel'");
expressionManager.isValid("mel:'Hello'");
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class TransformDiscoveryTestCase method testSimpleDiscovery.
@Test
public void testSimpleDiscovery() throws Exception {
MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
Transformer t = registry.lookupTransformer(DataType.STRING, DataType.fromType(Apple.class));
assertNotNull(t);
assertEquals(StringToApple.class, t.getClass());
t = registry.lookupTransformer(DataType.STRING, DataType.fromType(Orange.class));
assertNotNull(t);
assertEquals(StringToOrange.class, t.getClass());
try {
registry.lookupTransformer(DataType.STRING, DataType.fromType(Banana.class));
fail("There is no transformer to go from String to Banana");
} catch (TransformerException e) {
// expected
}
registry.registerTransformer(new StringToRedApple());
t = registry.lookupTransformer(DataType.STRING, DataType.fromType(RedApple.class));
assertNotNull(t);
assertEquals(StringToRedApple.class, t.getClass());
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class DefaultPolicyManager method initialise.
@Override
public void initialise() throws InitialisationException {
operationPolicyProcessorFactory = new DefaultOperationPolicyProcessorFactory(policyStateHandler);
sourcePolicyProcessorFactory = new DefaultSourcePolicyProcessorFactory(policyStateHandler);
MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
policyProvider = registry.lookupLocalObjects(PolicyProvider.class).stream().findFirst().orElse(new NullPolicyProvider());
sourcePolicyParametersTransformerCollection = registry.lookupObjects(SourcePolicyParametersTransformer.class);
operationPolicyParametersTransformerCollection = registry.lookupObjects(OperationPolicyParametersTransformer.class);
policyPointcutParametersManager = new PolicyPointcutParametersManager(registry.lookupObjects(SourcePolicyPointcutParametersFactory.class), registry.lookupObjects(OperationPolicyPointcutParametersFactory.class));
}
use of org.mule.runtime.core.internal.context.MuleContextWithRegistries in project mule by mulesoft.
the class TransactionNotificationsTestCase method testTransactionNotifications.
@Test
public void testTransactionNotifications() throws Exception {
final CountDownLatch latch = new CountDownLatch(3);
// the code is simple and deceptive :) The trick is this dummy transaction is handled by
// a global TransactionCoordination instance, which binds it to the current thread.
Transaction transaction = new DummyTransaction(muleContext);
((MuleContextWithRegistries) muleContext).getRegistry().lookupObject(NotificationListenerRegistry.class).registerListener(new TransactionNotificationListener<TransactionNotification>() {
@Override
public boolean isBlocking() {
return false;
}
@Override
public void onNotification(TransactionNotification notification) {
if (new IntegerAction(TRANSACTION_BEGAN).equals(notification.getAction())) {
assertEquals("begin", notification.getActionName());
latch.countDown();
} else if (new IntegerAction(TRANSACTION_COMMITTED).equals(notification.getAction())) {
assertEquals("commit", notification.getActionName());
latch.countDown();
} else if (new IntegerAction(TRANSACTION_ROLLEDBACK).equals(notification.getAction())) {
assertEquals("rollback", notification.getActionName());
latch.countDown();
}
}
}, notification -> transaction.getId().equals(notification.getResourceIdentifier()));
transaction.begin();
transaction.commit();
transaction.rollback();
// Wait for the notifcation event to be fired as they are queued
latch.await(2000, MILLISECONDS);
assertEquals("There are still some notifications left unfired.", 0, latch.getCount());
}
Aggregations