|
16 | 16 |
|
17 | 17 | package org.springframework.expression.spel; |
18 | 18 |
|
| 19 | +import java.util.ArrayList; |
19 | 20 | import java.util.HashMap; |
20 | 21 | import java.util.LinkedHashMap; |
| 22 | +import java.util.List; |
21 | 23 | import java.util.Map; |
22 | 24 | import java.util.Properties; |
23 | 25 |
|
24 | 26 | import junit.framework.Assert; |
| 27 | + |
25 | 28 | import org.junit.Ignore; |
26 | 29 | import org.junit.Test; |
27 | | - |
| 30 | +import org.springframework.core.convert.TypeDescriptor; |
28 | 31 | import org.springframework.expression.AccessException; |
29 | 32 | import org.springframework.expression.BeanResolver; |
30 | 33 | import org.springframework.expression.EvaluationContext; |
|
34 | 37 | import org.springframework.expression.ParserContext; |
35 | 38 | import org.springframework.expression.PropertyAccessor; |
36 | 39 | import org.springframework.expression.TypedValue; |
| 40 | +import org.springframework.expression.spel.standard.SpelExpression; |
37 | 41 | import org.springframework.expression.spel.standard.SpelExpressionParser; |
38 | 42 | import org.springframework.expression.spel.support.ReflectivePropertyAccessor; |
39 | 43 | import org.springframework.expression.spel.support.StandardEvaluationContext; |
@@ -708,6 +712,60 @@ public void testMapOfMap_SPR7244() throws Exception { |
708 | 712 | evaluated = exp.getValue(ctx); |
709 | 713 | Assert.assertEquals("Arthur",evaluated); |
710 | 714 | } |
| 715 | + |
| 716 | + @Test |
| 717 | + public void testProjectionTypeDescriptors_1() throws Exception { |
| 718 | + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); |
| 719 | + SpelExpressionParser parser = new SpelExpressionParser(); |
| 720 | + String el1 = "ls.![#this.equals('abc')]"; |
| 721 | + SpelExpression exp = parser.parseRaw(el1); |
| 722 | + List value = (List)exp.getValue(ctx); |
| 723 | + // value is list containing [true,false] |
| 724 | + Assert.assertEquals(Boolean.class,value.get(0).getClass()); |
| 725 | + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); |
| 726 | + Assert.assertEquals(Boolean.class,evaluated.getElementType()); |
| 727 | + } |
| 728 | + |
| 729 | + @Test |
| 730 | + public void testProjectionTypeDescriptors_2() throws Exception { |
| 731 | + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); |
| 732 | + SpelExpressionParser parser = new SpelExpressionParser(); |
| 733 | + String el1 = "as.![#this.equals('abc')]"; |
| 734 | + SpelExpression exp = parser.parseRaw(el1); |
| 735 | + Object[] value = (Object[])exp.getValue(ctx); |
| 736 | + // value is array containing [true,false] |
| 737 | + Assert.assertEquals(Boolean.class,value[0].getClass()); |
| 738 | + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); |
| 739 | + Assert.assertEquals(Boolean.class,evaluated.getElementType()); |
| 740 | + } |
| 741 | + |
| 742 | + @Test |
| 743 | + public void testProjectionTypeDescriptors_3() throws Exception { |
| 744 | + StandardEvaluationContext ctx = new StandardEvaluationContext(new C()); |
| 745 | + SpelExpressionParser parser = new SpelExpressionParser(); |
| 746 | + String el1 = "ms.![key.equals('abc')]"; |
| 747 | + SpelExpression exp = parser.parseRaw(el1); |
| 748 | + List value = (List)exp.getValue(ctx); |
| 749 | + // value is list containing [true,false] |
| 750 | + Assert.assertEquals(Boolean.class,value.get(0).getClass()); |
| 751 | + TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx); |
| 752 | + Assert.assertEquals(Boolean.class,evaluated.getElementType()); |
| 753 | + } |
| 754 | + |
| 755 | + static class C { |
| 756 | + public List<String> ls; |
| 757 | + public String[] as; |
| 758 | + public Map<String,String> ms; |
| 759 | + C() { |
| 760 | + ls = new ArrayList<String>(); |
| 761 | + ls.add("abc"); |
| 762 | + ls.add("def"); |
| 763 | + as = new String[]{"abc","def"}; |
| 764 | + ms = new HashMap<String,String>(); |
| 765 | + ms.put("abc","xyz"); |
| 766 | + ms.put("def","pqr"); |
| 767 | + } |
| 768 | + } |
711 | 769 |
|
712 | 770 |
|
713 | 771 | } |
0 commit comments