Search in sources :

Example 1 with HeaderEnricher

use of org.springframework.integration.transformer.HeaderEnricher in project spring-integration by spring-projects.

the class MethodInvokingHeaderEnricherTests method overwriteTrue.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void overwriteTrue() {
    TestBean testBean = new TestBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, "process");
    HeaderEnricher enricher = new HeaderEnricher();
    enricher.setMessageProcessor(processor);
    enricher.setDefaultOverwrite(true);
    Message<?> message = MessageBuilder.withPayload("test").setHeader("bar", "XYZ").build();
    Message<?> result = enricher.transform(message);
    assertEquals("TEST", result.getHeaders().get("foo"));
    assertEquals("ABC", result.getHeaders().get("bar"));
}
Also used : HeaderEnricher(org.springframework.integration.transformer.HeaderEnricher) Test(org.junit.Test)

Example 2 with HeaderEnricher

use of org.springframework.integration.transformer.HeaderEnricher in project spring-integration by spring-projects.

the class MethodInvokingHeaderEnricherTests method overwriteId.

@Test
public void overwriteId() {
    HeaderEnricher enricher = new HeaderEnricher(Collections.singletonMap(MessageHeaders.ID, new StaticHeaderValueMessageProcessor<>("foo")));
    try {
        enricher.afterPropertiesSet();
        fail("BeanInitializationException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(BeanInitializationException.class));
        assertThat(e.getMessage(), containsString("HeaderEnricher cannot override 'id' and 'timestamp' read-only headers."));
    }
}
Also used : StaticHeaderValueMessageProcessor(org.springframework.integration.transformer.support.StaticHeaderValueMessageProcessor) HeaderEnricher(org.springframework.integration.transformer.HeaderEnricher) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Test(org.junit.Test)

Example 3 with HeaderEnricher

use of org.springframework.integration.transformer.HeaderEnricher in project spring-integration by spring-projects.

the class MethodInvokingHeaderEnricherTests method overwriteFalseExplicit.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void overwriteFalseExplicit() {
    TestBean testBean = new TestBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, "process");
    HeaderEnricher enricher = new HeaderEnricher();
    enricher.setMessageProcessor(processor);
    enricher.setDefaultOverwrite(false);
    Message<?> message = MessageBuilder.withPayload("test").setHeader("bar", "XYZ").build();
    Message<?> result = enricher.transform(message);
    assertEquals("TEST", result.getHeaders().get("foo"));
    assertEquals("XYZ", result.getHeaders().get("bar"));
}
Also used : HeaderEnricher(org.springframework.integration.transformer.HeaderEnricher) Test(org.junit.Test)

Example 4 with HeaderEnricher

use of org.springframework.integration.transformer.HeaderEnricher in project spring-integration by spring-projects.

the class MethodInvokingHeaderEnricherTests method overwriteFalseByDefault.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void overwriteFalseByDefault() {
    TestBean testBean = new TestBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, "process");
    HeaderEnricher enricher = new HeaderEnricher();
    enricher.setMessageProcessor(processor);
    Message<?> message = MessageBuilder.withPayload("test").setHeader("bar", "XYZ").build();
    Message<?> result = enricher.transform(message);
    assertEquals("TEST", result.getHeaders().get("foo"));
    assertEquals("XYZ", result.getHeaders().get("bar"));
}
Also used : HeaderEnricher(org.springframework.integration.transformer.HeaderEnricher) Test(org.junit.Test)

Example 5 with HeaderEnricher

use of org.springframework.integration.transformer.HeaderEnricher in project spring-integration by spring-projects.

the class MethodInvokingHeaderEnricherTests method emptyHeadersOnRequest.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void emptyHeadersOnRequest() {
    TestBean testBean = new TestBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, "process");
    HeaderEnricher enricher = new HeaderEnricher();
    enricher.setMessageProcessor(processor);
    enricher.setDefaultOverwrite(true);
    Message<?> message = MessageBuilder.withPayload("test").build();
    Message<?> result = enricher.transform(message);
    assertEquals("TEST", result.getHeaders().get("foo"));
    assertEquals("ABC", result.getHeaders().get("bar"));
}
Also used : HeaderEnricher(org.springframework.integration.transformer.HeaderEnricher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 HeaderEnricher (org.springframework.integration.transformer.HeaderEnricher)5 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 StaticHeaderValueMessageProcessor (org.springframework.integration.transformer.support.StaticHeaderValueMessageProcessor)1