@Test public void attributes() throws Exception { Object attributes = mock(Object.class); when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, DataType.OBJECT)); assertThat(evaluate(ATTRIBUTES, event), sameInstance(attributes)); }
protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) { InternalMessage message = mock(InternalMessage.class); when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType)); when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType)); try { return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build(); } catch (MuleException e) { throw new MuleRuntimeException(e); } }
@Test public void payloadBinding() throws Exception { CoreEvent event = getEventWithError(empty()); InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS); when(event.getMessage()).thenReturn(message); TypedValue payload = new TypedValue<>("hey", STRING); TypedValue attributes = new TypedValue<>(null, OBJECT); when(message.getPayload()).thenReturn(payload); when(message.getAttributes()).thenReturn(attributes); TypedValue result = expressionLanguage.evaluate(PAYLOAD, event, BindingContext.builder().build()); assertThat(result.getValue(), is(equalTo(payload.getValue()))); assertThat(result.getDataType(), is(equalTo(payload.getDataType()))); }
@Test public void dataTypeBinding() throws Exception { CoreEvent event = getEventWithError(empty()); InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS); when(event.getMessage()).thenReturn(message); TypedValue payload = new TypedValue<>("hey", STRING); TypedValue attributes = new TypedValue<>(null, OBJECT); when(message.getPayload()).thenReturn(payload); when(message.getAttributes()).thenReturn(attributes); TypedValue result = expressionLanguage.evaluate(DATA_TYPE, event, BindingContext.builder().build()); assertThat(result.getValue(), is(equalTo(STRING))); assertThat(result.getDataType(), is(assignableTo(fromType(DataType.class)))); }
@Test public void parseTemplateFromLocation() throws InitialisationException, IOException { parseTemplateProcessor.setLocation(LOCATION); parseTemplateProcessor.initialise(); when(mockMuleMessage.getInboundProperty("errorMessage")).thenReturn("ERROR!!!"); String expectedExpression = IOUtils.getResourceAsString(LOCATION, this.getClass()); when(mockMuleMessage.getPayload()).thenReturn(of("Parsed")); when(mockMuleMessage.getAttributes()).thenReturn(of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed"); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals("Parsed", response.getMessage().getPayload().getValue()); // Call a second time to make sure the template is stored once the transformer has been initialized response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals("Parsed", response.getMessage().getPayload().getValue()); }
@Test public void parseTemplateToTarget() throws InitialisationException { String payload = "Payload"; String template = "Template"; parseTemplateProcessor.setContent(template); parseTemplateProcessor.setTarget("some_target_variable"); parseTemplateProcessor.initialise(); when(mockMuleMessage.getPayload()).thenReturn(of(payload)); when(mockMuleMessage.getAttributes()).thenReturn(of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(any(), any(), any(), any())).thenReturn("Parsed"); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(payload, response.getMessage().getPayload().getValue()); assertEquals("Parsed", ((Message) response.getVariables().get("some_target_variable").getValue()).getPayload().getValue()); } }
protected CoreEvent configureEvent() throws Exception { when(message.getPayload()) .thenReturn(new TypedValue<>(TEST_PAYLOAD, DataType.builder().mediaType(MediaType.create("*", "*", defaultCharset())).build())); when(message.getAttributes()) .thenReturn(new TypedValue<>(null, DataType.builder().fromObject(null).build())); return eventBuilder(muleContext).message(message).build(); }
@Test public void parseTemplateFromContent() throws InitialisationException { String template = "This is a template"; parseTemplateProcessor.setContent(template); parseTemplateProcessor.initialise(); when(mockMuleMessage.getPayload()).thenReturn(of(template)); when(mockMuleMessage.getAttributes()).thenReturn(of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(eq(template), eq(event), any(), any())).thenReturn(template); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(template, response.getMessage().getPayload().getValue()); // Call a second time to make sure the template is stored once the transformer has been initialized response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(template, response.getMessage().getPayload().getValue()); }
@Test public void attributes() throws Exception { Object attributes = mock(Object.class); when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, DataType.OBJECT)); assertThat(evaluate(ATTRIBUTES, event), sameInstance(attributes)); }
protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) { InternalMessage message = mock(InternalMessage.class); when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType)); when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType)); try { return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build(); } catch (MuleException e) { throw new MuleRuntimeException(e); } }
@Test public void payloadBinding() throws Exception { CoreEvent event = getEventWithError(empty()); InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS); when(event.getMessage()).thenReturn(message); TypedValue payload = new TypedValue<>("hey", STRING); TypedValue attributes = new TypedValue<>(null, OBJECT); when(message.getPayload()).thenReturn(payload); when(message.getAttributes()).thenReturn(attributes); TypedValue result = expressionLanguage.evaluate(PAYLOAD, event, BindingContext.builder().build()); assertThat(result.getValue(), is(equalTo(payload.getValue()))); assertThat(result.getDataType(), is(equalTo(payload.getDataType()))); }
@Test public void dataTypeBinding() throws Exception { CoreEvent event = getEventWithError(empty()); InternalMessage message = mock(InternalMessage.class, RETURNS_DEEP_STUBS); when(event.getMessage()).thenReturn(message); TypedValue payload = new TypedValue<>("hey", STRING); TypedValue attributes = new TypedValue<>(null, OBJECT); when(message.getPayload()).thenReturn(payload); when(message.getAttributes()).thenReturn(attributes); TypedValue result = expressionLanguage.evaluate(DATA_TYPE, event, BindingContext.builder().build()); assertThat(result.getValue(), is(equalTo(STRING))); assertThat(result.getDataType(), is(assignableTo(fromType(DataType.class)))); }
@Test public void testParseTemplateFromLocation() throws InitialisationException, IOException { parseTemplateProcessor.setLocation(LOCATION); parseTemplateProcessor.initialise(); when(mockMuleMessage.getInboundProperty("errorMessage")).thenReturn("ERROR!!!"); String expectedExpression = IOUtils.getResourceAsString(LOCATION, this.getClass()); when(mockMuleMessage.getPayload()).thenReturn(TypedValue.of("Parsed")); when(mockMuleMessage.getAttributes()).thenReturn(TypedValue.of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(eq(expectedExpression), eq(event), any(), any())).thenReturn("Parsed"); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals("Parsed", response.getMessage().getPayload().getValue()); // Call a second time to make sure the template is stored once the transformer has been initialized response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals("Parsed", response.getMessage().getPayload().getValue()); }
@Test public void testParseTemplateToTarget() throws InitialisationException { String payload = "Payload"; String template = "Template"; parseTemplateProcessor.setContent(template); parseTemplateProcessor.setTarget("some_target_variable"); parseTemplateProcessor.initialise(); when(mockMuleMessage.getPayload()).thenReturn(TypedValue.of(payload)); when(mockMuleMessage.getAttributes()).thenReturn(TypedValue.of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(any(), any(), any(), any())).thenReturn("Parsed"); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(payload, response.getMessage().getPayload().getValue()); assertEquals("Parsed", ((Message) response.getVariables().get("some_target_variable").getValue()).getPayload().getValue()); } }
@Test public void testParseTemplateFromContent() throws InitialisationException { String template = "This is a template"; parseTemplateProcessor.setContent(template); parseTemplateProcessor.initialise(); when(mockMuleMessage.getPayload()).thenReturn(TypedValue.of(template)); when(mockMuleMessage.getAttributes()).thenReturn(TypedValue.of(new HashMap<>())); when(mockExpressionManager.parseLogTemplate(eq(template), eq(event), any(), any())).thenReturn(template); CoreEvent response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(template, response.getMessage().getPayload().getValue()); // Call a second time to make sure the template is stored once the transformer has been initialized response = parseTemplateProcessor.process(event); assertNotNull(response); assertEquals(template, response.getMessage().getPayload().getValue()); }