From fb2e3af50ccf4b917fbb4e16a5234d5e82669d81 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 7 Jan 2011 19:14:42 +0000 Subject: [PATCH] more projection tests - verifying the typedescriptor changes made by Keith git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3891 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../expression/spel/SpringEL300Tests.java | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java index d47fe5ae102..f92a4b23e63 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java @@ -16,15 +16,18 @@ package org.springframework.expression.spel; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import junit.framework.Assert; + import org.junit.Ignore; import org.junit.Test; - +import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.BeanResolver; import org.springframework.expression.EvaluationContext; @@ -34,6 +37,7 @@ import org.springframework.expression.ExpressionParser; import org.springframework.expression.ParserContext; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypedValue; +import org.springframework.expression.spel.standard.SpelExpression; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.ReflectivePropertyAccessor; import org.springframework.expression.spel.support.StandardEvaluationContext; @@ -708,6 +712,60 @@ public class SpringEL300Tests extends ExpressionTestCase { evaluated = exp.getValue(ctx); Assert.assertEquals("Arthur",evaluated); } + + @Test + public void testProjectionTypeDescriptors_1() throws Exception { + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); + SpelExpressionParser parser = new SpelExpressionParser(); + String el1 = "ls.![#this.equals('abc')]"; + SpelExpression exp = parser.parseRaw(el1); + List value = (List)exp.getValue(ctx); + // value is list containing [true,false] + Assert.assertEquals(Boolean.class,value.get(0).getClass()); + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); + Assert.assertEquals(Boolean.class,evaluated.getElementType()); + } + + @Test + public void testProjectionTypeDescriptors_2() throws Exception { + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); + SpelExpressionParser parser = new SpelExpressionParser(); + String el1 = "as.![#this.equals('abc')]"; + SpelExpression exp = parser.parseRaw(el1); + Object[] value = (Object[])exp.getValue(ctx); + // value is array containing [true,false] + Assert.assertEquals(Boolean.class,value[0].getClass()); + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); + Assert.assertEquals(Boolean.class,evaluated.getElementType()); + } + + @Test + public void testProjectionTypeDescriptors_3() throws Exception { + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); + SpelExpressionParser parser = new SpelExpressionParser(); + String el1 = "ms.![key.equals('abc')]"; + SpelExpression exp = parser.parseRaw(el1); + List value = (List)exp.getValue(ctx); + // value is list containing [true,false] + Assert.assertEquals(Boolean.class,value.get(0).getClass()); + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); + Assert.assertEquals(Boolean.class,evaluated.getElementType()); + } + + static class C { + public List ls; + public String[] as; + public Map ms; + C() { + ls = new ArrayList(); + ls.add("abc"); + ls.add("def"); + as = new String[]{"abc","def"}; + ms = new HashMap(); + ms.put("abc","xyz"); + ms.put("def","pqr"); + } + } }