Search in sources :

Example 26 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.

the class TransactionSynchronizationFactoryParserTests method validateFullConfiguration.

@Test
public void validateFullConfiguration() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("TransactionSynchronizationFactoryParserTests-config.xml", this.getClass());
    DefaultTransactionSynchronizationFactory syncFactory = context.getBean("syncFactoryComplete", DefaultTransactionSynchronizationFactory.class);
    assertNotNull(syncFactory);
    TransactionSynchronizationProcessor processor = TestUtils.getPropertyValue(syncFactory, "processor", ExpressionEvaluatingTransactionSynchronizationProcessor.class);
    assertNotNull(processor);
    MessageChannel beforeCommitResultChannel = TestUtils.getPropertyValue(processor, "beforeCommitChannel", MessageChannel.class);
    assertNotNull(beforeCommitResultChannel);
    assertEquals(beforeCommitResultChannel, context.getBean("beforeCommitChannel"));
    Object beforeCommitExpression = TestUtils.getPropertyValue(processor, "beforeCommitExpression");
    assertNull(beforeCommitExpression);
    MessageChannel afterCommitResultChannel = TestUtils.getPropertyValue(processor, "afterCommitChannel", MessageChannel.class);
    assertNotNull(afterCommitResultChannel);
    assertEquals(afterCommitResultChannel, context.getBean("nullChannel"));
    Expression afterCommitExpression = TestUtils.getPropertyValue(processor, "afterCommitExpression", Expression.class);
    assertNotNull(afterCommitExpression);
    assertEquals("'afterCommit'", ((SpelExpression) afterCommitExpression).getExpressionString());
    MessageChannel afterRollbackResultChannel = TestUtils.getPropertyValue(processor, "afterRollbackChannel", MessageChannel.class);
    assertNotNull(afterRollbackResultChannel);
    assertEquals(afterRollbackResultChannel, context.getBean("afterRollbackChannel"));
    Expression afterRollbackExpression = TestUtils.getPropertyValue(processor, "afterRollbackExpression", Expression.class);
    assertNotNull(afterRollbackExpression);
    assertEquals("'afterRollback'", ((SpelExpression) afterRollbackExpression).getExpressionString());
    context.close();
}
Also used : DefaultTransactionSynchronizationFactory(org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) TransactionSynchronizationProcessor(org.springframework.integration.transaction.TransactionSynchronizationProcessor) ExpressionEvaluatingTransactionSynchronizationProcessor(org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 27 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method withUrlExpressionAndTemplate.

@Test
public void withUrlExpressionAndTemplate() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.withUrlExpressionAndTemplate);
    RestTemplate restTemplate = TestUtils.getPropertyValue(this.withUrlExpressionAndTemplate, "handler.restTemplate", RestTemplate.class);
    assertSame(customRestTemplate, restTemplate);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    SpelExpression expression = (SpelExpression) handlerAccessor.getPropertyValue("uriExpression");
    assertNotNull(expression);
    assertEquals("'http://localhost/test1'", expression.getExpressionString());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 28 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method withUrlExpression.

@Test
public void withUrlExpression() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.withUrlExpression);
    RestTemplate restTemplate = TestUtils.getPropertyValue(this.withUrlExpression, "handler.restTemplate", RestTemplate.class);
    assertNotSame(customRestTemplate, restTemplate);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    SpelExpression expression = (SpelExpression) handlerAccessor.getPropertyValue("uriExpression");
    assertNotNull(expression);
    assertEquals("'http://localhost/test1'", expression.getExpressionString());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 29 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.

the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParserWithMaxResultsExpression.

@Test
public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws Exception {
    AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "outputChannel", AbstractMessageChannel.class);
    assertEquals("out", outputChannel.getComponentName());
    JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "source.jpaExecutor", JpaExecutor.class);
    assertNotNull(jpaExecutor);
    Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
    assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
    final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
    assertNotNull(jpaOperations);
    SpelExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", SpelExpression.class);
    assertNotNull(expression);
    assertEquals("@maxNumberOfResults", TestUtils.getPropertyValue(expression, "expression"));
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Test(org.junit.Test)

Example 30 with SpelExpression

use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.

the class HttpInboundGatewayParserTests method testControllerViewExp.

@Test
public void testControllerViewExp() throws Exception {
    DirectFieldAccessor accessor = new DirectFieldAccessor(inboundControllerViewExp);
    String errorCode = (String) accessor.getPropertyValue("errorCode");
    assertEquals("oops", errorCode);
    SpelExpression viewExpression = (SpelExpression) accessor.getPropertyValue("viewExpression");
    assertNotNull(viewExpression);
    assertEquals("'bar'", viewExpression.getExpressionString());
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

SpelExpression (org.springframework.expression.spel.standard.SpelExpression)56 Test (org.junit.jupiter.api.Test)30 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)27 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)18 Test (org.junit.Test)15 Expression (org.springframework.expression.Expression)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 EvaluationContext (org.springframework.expression.EvaluationContext)4 HashMap (java.util.HashMap)3 List (java.util.List)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)3 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)3 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)3 HttpRequestExecutingMessageHandler (org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler)3 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 LinkedHashMap (java.util.LinkedHashMap)2