From dcb52dbbc17fc9eda8d180eede222247322aa96b Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Tue, 7 Jul 2009 20:13:18 +0000 Subject: [PATCH] SPR-5906: test and fix for using expressions in property list keys and values --- .../ExpressionUsageTests-context.xml | 44 +++++++++++ .../expression/ExpressionUsageTests.java | 74 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests-context.xml create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests-context.xml b/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests-context.xml new file mode 100644 index 00000000000..f8f0d5eb858 --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests-context.xml @@ -0,0 +1,44 @@ + + + + + + + Dave + Andy + + + + + + + + + + #{properties['user.name']} + #{properties['username']} + #{properties[username]} + #{properties.username} + exists + exists also + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java new file mode 100644 index 00000000000..a9a28e84608 --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java @@ -0,0 +1,74 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.test.context.expression; + +import static junit.framework.Assert.*; + +import java.util.Properties; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +/** + * @author Andy Clement + * @author Dave Syer + */ +@ContextConfiguration +public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests { + + @Test + public void testSpr5906() throws Exception { + Properties props = (Properties)applicationContext.getBean("derived"); + + // verify the property values have been evaluated as expressions + assertEquals("Dave",props.getProperty("user.name")); + assertEquals("Andy",props.getProperty("username")); + + // verify the property keys have been evaluated as expressions + assertEquals("exists",props.getProperty("Dave")); + assertEquals("exists also",props.getProperty("Andy")); + } + + public static class Foo { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } + + @Autowired + @Qualifier("andy2") + private Foo andy2; + + @Autowired + @Qualifier("andy") + private Foo andy; + + @Test + public void testSpr5847() throws Exception { + assertEquals("Andy", andy2.getName()); + assertEquals("Andy", andy.getName()); + } + +} \ No newline at end of file