Search in sources :

Example 1 with JSON

use of org.mule.runtime.api.metadata.MediaType.JSON in project mule by mulesoft.

the class MessageEnricherTestCase method doEnrichDataTypePropagationTest.

private void doEnrichDataTypePropagationTest(EnrichExpressionPair pair) throws Exception {
    final DataType dataType = DataType.builder().type(String.class).mediaType(JSON).charset(UTF_16.name()).build();
    MessageEnricher enricher = baseEnricher();
    enricher.addEnrichExpressionPair(pair);
    enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("bar").mediaType(dataType.getMediaType()).build()).build());
    CoreEvent out = process(enricher, testEvent());
    assertEquals("bar", out.getVariables().get("foo").getValue());
    assertThat(out.getVariables().get("foo").getDataType(), like(String.class, JSON, UTF_16));
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType)

Aggregations

UTF_16 (java.nio.charset.StandardCharsets.UTF_16)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertThat (org.junit.Assert.assertThat)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 ExpectedException.none (org.junit.rules.ExpectedException.none)1 Message (org.mule.runtime.api.message.Message)1 Message.of (org.mule.runtime.api.message.Message.of)1 DataType (org.mule.runtime.api.metadata.DataType)1 JSON (org.mule.runtime.api.metadata.MediaType.JSON)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 LifecycleUtils.initialiseIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded)1 Processor (org.mule.runtime.core.api.processor.Processor)1 EnrichExpressionPair (org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair)1