use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class PropertyAccessTests method testAccessingOnNullObject.
/**
* The standard reflection resolver cannot find properties on null objects but some
* supplied resolver might be able to - so null shouldn't crash the reflection resolver.
*/
@Test
public void testAccessingOnNullObject() throws Exception {
SpelExpression expr = (SpelExpression) parser.parseExpression("madeup");
EvaluationContext context = new StandardEvaluationContext(null);
try {
expr.getValue(context);
fail("Should have failed - default property resolver cannot resolve on null");
} catch (Exception ex) {
checkException(ex, SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
}
assertFalse(expr.isWritable(context));
try {
expr.setValue(context, "abc");
fail("Should have failed - default property resolver cannot resolve on null");
} catch (Exception ex) {
checkException(ex, SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
}
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-framework by spring-projects.
the class SpelReproTests method reservedWordProperties_9862.
@Test
public void reservedWordProperties_9862() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext();
SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
Object value = expression.getValue(ctx);
assertEquals(value, Reserver.CONST);
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.
the class WebFluxInboundGatewayParserTests 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"));
assertTrue((boolean) endpointAccessor.getPropertyValue("expectReply"));
assertEquals("'504'", ((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"));
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.
the class MongoDbOutboundChannelAdapterParserTests method fullConfigWithCollectionExpression.
@Test
public void fullConfigWithCollectionExpression() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-parser-config.xml", this.getClass());
MongoDbStoringMessageHandler handler = TestUtils.getPropertyValue(context.getBean("fullConfigWithCollectionExpression.adapter"), "handler", MongoDbStoringMessageHandler.class);
assertEquals("fullConfigWithCollectionExpression.adapter", TestUtils.getPropertyValue(handler, "componentName"));
assertEquals(false, TestUtils.getPropertyValue(handler, "shouldTrack"));
assertNotNull(TestUtils.getPropertyValue(handler, "mongoTemplate"));
assertEquals(context.getBean("mongoDbFactory"), TestUtils.getPropertyValue(handler, "mongoDbFactory"));
assertNotNull(TestUtils.getPropertyValue(handler, "evaluationContext"));
assertTrue(TestUtils.getPropertyValue(handler, "collectionNameExpression") instanceof SpelExpression);
assertEquals("headers.collectionName", TestUtils.getPropertyValue(handler, "collectionNameExpression.expression"));
context.close();
}
use of org.springframework.expression.spel.standard.SpelExpression in project spring-integration by spring-projects.
the class OutboundChannelAdapterParserTests method testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression.
@Test
public void testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
Object consumer = context.getBean("sftpOutboundAdapterWithExpression");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("sftpOutboundAdapterWithExpression", ((EventDrivenConsumer) consumer).getComponentName());
FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class);
SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor.expression");
assertNotNull(remoteDirectoryExpression);
assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
FileNameGenerator generator = (FileNameGenerator) TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator");
Expression fileNameGeneratorExpression = TestUtils.getPropertyValue(generator, "expression", Expression.class);
assertNotNull(fileNameGeneratorExpression);
assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression.getExpressionString());
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
assertNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
context.close();
}
Aggregations