public ValueResolvingContext build() { if (event == null) { return new ValueResolvingContext(null, null, null, true); } else if (manager == null) { return new ValueResolvingContext(event, null, config.orElse(null), resolveCursors); } else { return new ValueResolvingContext(event, manager.openSession(event.asBindingContext()), config.orElse(null), resolveCursors); } } }
@Benchmark public Object dwFlowVars() { return expressionManager.evaluate("vars.foo == 'bar'", event.asBindingContext()).getValue(); }
@Benchmark public Object dwPayload() { return expressionManager.evaluate("payload", event.asBindingContext()).getValue(); }
@Benchmark public Object dwGetLocale() { return expressionManager.evaluate("java!java::util::Locale::getDefault().language", event.asBindingContext()).getValue(); }
@Before public void setUp() { when(event.getError()).thenReturn(empty()); when(event.getAuthentication()).thenReturn(empty()); Message msg = of(null); when(event.getMessage()).thenReturn(msg); when(event.asBindingContext()).thenReturn(getTargetBindingContext(msg)); when(event.getItemSequenceInfo()).thenReturn(empty()); }
@Benchmark public Object addAllThreeTimes() { return BindingContext.builder(globalCtx) .addAll(childCtx) .addAll(event.asBindingContext()) .build(); }
@Test public void testPojoType() throws Exception { ExpressionManagerSession session = mock(ExpressionManagerSession.class); when(session.evaluate(eq("#[5]"), any(DataType.class))) .thenAnswer(inv -> new TypedValue<>(5, inv.getArgument(1))); when(expressionManager.openSession(any())).thenReturn(session); assertExpected(new StaticValueResolver(null), toMetadataType(DynamicPojo.class), true, new DynamicPojo(5)); verify(event, times(1)).asBindingContext(); }
@Test public void sessionWithBindingContextAndLocation() throws MuleException { ExpressionLanguageSessionAdaptor session = expressionLanguage.openSession(TEST_CONNECTOR_LOCATION, null, testEvent().asBindingContext()); assertThat(session.evaluate("payload").getValue(), is("test")); assertThat(session.evaluate("flow.name").getValue(), is("test")); }
@Test public void sessionWithBindingContext() throws MuleException { ExpressionLanguageSessionAdaptor session = expressionLanguage.openSession(null, null, testEvent().asBindingContext()); assertThat(session.evaluate("payload").getValue(), is("test")); expectedEx.expect(ExpressionRuntimeException.class); assertThat(session.evaluate("flow.name").getValue(), is(nullValue())); }
@Test public void sessionWithEventBindingContextAndLocation() throws MuleException { ExpressionLanguageSessionAdaptor session = mvel.openSession(TEST_CONNECTOR_LOCATION, testEvent(), testEvent().asBindingContext()); assertThat(session.evaluate("payload").getValue(), is("test")); assertThat(session.evaluate("flow.name").getValue(), is("test")); }
@Test public void sessionEvaluatesPayloadExpressionWithExpectedDataType() throws MuleException { TypedValue<String> stringJsonPayload = new TypedValue<>("\"string\"", JSON_STRING); CoreEvent eventWithJsonPayload = CoreEvent.builder(testEvent()).message(Message.of(stringJsonPayload)).build(); BindingContext bindingContext = eventWithJsonPayload.asBindingContext(); ExpressionLanguageSessionAdaptor session = expressionLanguage.openSession(TEST_CONNECTOR_LOCATION, null, bindingContext); assertThat(session.evaluate("payload", STRING).getValue(), is("string")); }