Search in sources :

Example 31 with SpelExpression

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

the class HttpOutboundGatewayParserTests method withUrlExpression.

@Test
public void withUrlExpression() {
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) new DirectFieldAccessor(this.withUrlExpressionEndpoint).getPropertyValue("handler");
    MessageChannel requestChannel = (MessageChannel) new DirectFieldAccessor(this.withUrlExpressionEndpoint).getPropertyValue("inputChannel");
    assertEquals(this.applicationContext.getBean("requests"), requestChannel);
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    Object replyChannel = handlerAccessor.getPropertyValue("outputChannel");
    assertNull(replyChannel);
    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"));
    assertEquals(false, handlerAccessor.getPropertyValue("transferCookies"));
    // INT-3055
    Object uriVariablesExpression = handlerAccessor.getPropertyValue("uriVariablesExpression");
    assertNotNull(uriVariablesExpression);
    assertEquals("@uriVariables", ((Expression) uriVariablesExpression).getExpressionString());
    Object uriVariableExpressions = handlerAccessor.getPropertyValue("uriVariableExpressions");
    assertNotNull(uriVariableExpressions);
    assertTrue(((Map<?, ?>) uriVariableExpressions).isEmpty());
}
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) MessageChannel(org.springframework.messaging.MessageChannel) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 32 with SpelExpression

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

the class MongoDbInboundChannelAdapterParserTests method fullConfigWithQueryExpression.

@Test
public void fullConfigWithQueryExpression() {
    MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithQueryExpressionAdapter);
    assertTrue(TestUtils.getPropertyValue(source, "queryExpression") instanceof SpelExpression);
    assertEquals("new BasicQuery('{''address.state'' : ''PA''}').limit(2)", TestUtils.getPropertyValue(source, "queryExpression.expression"));
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) MongoDbMessageSource(org.springframework.integration.mongodb.inbound.MongoDbMessageSource) Test(org.junit.Test)

Example 33 with SpelExpression

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

the class MongoDbInboundChannelAdapterParserTests method fullConfigWithCollectionExpression.

@Test
public void fullConfigWithCollectionExpression() {
    MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithCollectionExpressionAdapter);
    assertTrue(TestUtils.getPropertyValue(source, "collectionNameExpression") instanceof SpelExpression);
    assertEquals("'foo'", TestUtils.getPropertyValue(source, "collectionNameExpression.expression"));
}
Also used : SpelExpression(org.springframework.expression.spel.standard.SpelExpression) MongoDbMessageSource(org.springframework.integration.mongodb.inbound.MongoDbMessageSource) Test(org.junit.Test)

Example 34 with SpelExpression

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

the class WebFluxInboundChannelAdapterParserTests method reactiveFullConfig.

@Test
@SuppressWarnings("unchecked")
public void reactiveFullConfig() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.reactiveFullConfig);
    assertSame(this.requests, endpointAccessor.getPropertyValue("requestChannel"));
    assertNotNull(endpointAccessor.getPropertyValue("errorChannel"));
    assertFalse((boolean) endpointAccessor.getPropertyValue("autoStartup"));
    assertEquals(101, endpointAccessor.getPropertyValue("phase"));
    assertFalse((boolean) endpointAccessor.getPropertyValue("expectReply"));
    assertEquals("'202'", ((SpelExpression) endpointAccessor.getPropertyValue("statusCodeExpression")).getExpressionString());
    assertEquals("payload", ((SpelExpression) endpointAccessor.getPropertyValue("payloadExpression")).getExpressionString());
    Map<String, Expression> headerExpressions = (Map<String, Expression>) endpointAccessor.getPropertyValue("headerExpressions");
    assertTrue(headerExpressions.containsKey("foo"));
    assertEquals("foo", headerExpressions.get("foo").getValue());
    CrossOrigin crossOrigin = (CrossOrigin) endpointAccessor.getPropertyValue("crossOrigin");
    assertNotNull(crossOrigin);
    assertArrayEquals(new String[] { "foo" }, crossOrigin.getOrigin());
    assertEquals(ResolvableType.forClass(byte[].class), endpointAccessor.getPropertyValue("requestPayloadType"));
    assertSame(this.headerMapper, endpointAccessor.getPropertyValue("headerMapper"));
    assertSame(this.serverCodecConfigurer, endpointAccessor.getPropertyValue("codecConfigurer"));
    assertSame(this.requestedContentTypeResolver, endpointAccessor.getPropertyValue("requestedContentTypeResolver"));
    assertSame(this.reactiveAdapterRegistry, endpointAccessor.getPropertyValue("adapterRegistry"));
}
Also used : CrossOrigin(org.springframework.integration.http.inbound.CrossOrigin) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) Test(org.junit.Test)

Example 35 with SpelExpression

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

the class SpelQueryCreatorUnitTests method createQueryForMethodWithArgs.

private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args) throws NoSuchMethodException, SecurityException {
    Class<?>[] argTypes = new Class<?>[args.length];
    if (!ObjectUtils.isEmpty(args)) {
        for (int i = 0; i < args.length; i++) {
            argTypes[i] = args[i].getClass();
        }
    }
    Method method = PersonRepository.class.getMethod(methodName, argTypes);
    doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
    PartTree partTree = new PartTree(method.getName(), method.getReturnType());
    SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));
    KeyValueQuery<SpelExpression> q = creator.createQuery();
    q.getCriteria().setEvaluationContext(new StandardEvaluationContext(args));
    return q;
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) QueryMethod(org.springframework.data.repository.query.QueryMethod) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) QueryMethod(org.springframework.data.repository.query.QueryMethod) Method(java.lang.reflect.Method) PartTree(org.springframework.data.repository.query.parser.PartTree)

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