@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()); }
private CoreEvent getEventWithError(Optional<Error> error) { CoreEvent event = mock(CoreEvent.class, RETURNS_DEEP_STUBS); doReturn(error).when(event).getError(); when(event.getMessage().getPayload()).thenReturn(new TypedValue<>(null, OBJECT)); when(event.getMessage().getAttributes()).thenReturn(new TypedValue<>(null, OBJECT)); when(event.getAuthentication()).thenReturn(empty()); when(event.getItemSequenceInfo()).thenReturn(empty()); return event; }
@Test public void authenticationBinding() throws Exception { CoreEvent event = spy(testEvent()); Authentication authentication = new DefaultMuleAuthentication(new DefaultMuleCredentials("username", "password".toCharArray())); when(event.getAuthentication()).thenReturn(of(authentication)); TypedValue result = expressionLanguage.evaluate(AUTHENTICATION, event, BindingContext.builder().build()); assertThat(result.getValue(), is(instanceOf(Authentication.class))); assertThat(result.getValue(), is(authentication)); assertThat(result.getDataType().getType(), is(equalTo(Authentication.class))); }
private CoreEvent getEventWithError(Optional<Error> error) { CoreEvent event = mock(CoreEvent.class, RETURNS_DEEP_STUBS); doReturn(error).when(event).getError(); when(event.getMessage().getPayload()).thenReturn(new TypedValue<>(null, OBJECT)); when(event.getMessage().getAttributes()).thenReturn(new TypedValue<>(null, OBJECT)); when(event.getAuthentication()).thenReturn(empty()); when(event.getItemSequenceInfo()).thenReturn(empty()); return event; }
@Test public void authenticationBinding() throws Exception { CoreEvent event = spy(testEvent()); Authentication authentication = new DefaultMuleAuthentication(new DefaultMuleCredentials("username", "password".toCharArray())); when(event.getAuthentication()).thenReturn(of(authentication)); TypedValue result = expressionLanguage.evaluate(AUTHENTICATION, event, BindingContext.builder().build()); assertThat(result.getValue(), is(instanceOf(Authentication.class))); assertThat(result.getValue(), is(authentication)); assertThat(result.getDataType().getType(), is(equalTo(Authentication.class))); }