|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,13 +16,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.expression.spel; |
|
|
|
package org.springframework.expression.spel; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.expression.AccessException; |
|
|
|
import org.springframework.expression.AccessException; |
|
|
|
import org.springframework.expression.EvaluationContext; |
|
|
|
import org.springframework.expression.EvaluationContext; |
|
|
|
import org.springframework.expression.Expression; |
|
|
|
import org.springframework.expression.Expression; |
|
|
|
@ -32,6 +30,8 @@ import org.springframework.expression.TypedValue; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.standard.SpelExpressionParser; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Testing variations on map access. |
|
|
|
* Testing variations on map access. |
|
|
|
* |
|
|
|
* |
|
|
|
@ -73,64 +73,60 @@ public class MapAccessTests extends ExpressionTestCase { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetValue(){ |
|
|
|
public void testGetValue(){ |
|
|
|
|
|
|
|
Map<String,String> props1 = new HashMap<String,String>(); |
|
|
|
Map props1= new HashMap<String,String>(); |
|
|
|
|
|
|
|
props1.put("key1", "value1"); |
|
|
|
props1.put("key1", "value1"); |
|
|
|
props1.put("key2", "value2"); |
|
|
|
props1.put("key2", "value2"); |
|
|
|
props1.put("key3", "value3"); |
|
|
|
props1.put("key3", "value3"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object bean = new TestBean("name1", new TestBean("name2", null, "Description 2", 15, props1), "description 1", 6, props1); |
|
|
|
Object bean = new TestBean("name1",new TestBean("name2",null,"Description 2",15,props1),"description 1", 6,props1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExpressionParser parser = new SpelExpressionParser(); |
|
|
|
ExpressionParser parser = new SpelExpressionParser(); |
|
|
|
Expression exp = parser.parseExpression("testBean.properties['key2']"); |
|
|
|
Expression exp = parser.parseExpression("testBean.properties['key2']"); |
|
|
|
String key = (String) exp.getValue(bean); |
|
|
|
String key = (String) exp.getValue(bean); |
|
|
|
assertNotNull(key); |
|
|
|
assertNotNull(key); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static class TestBean |
|
|
|
|
|
|
|
{ |
|
|
|
public static class TestBean { |
|
|
|
|
|
|
|
|
|
|
|
private String name; |
|
|
|
private String name; |
|
|
|
private TestBean testBean; |
|
|
|
private TestBean testBean; |
|
|
|
private String description; |
|
|
|
private String description; |
|
|
|
private Integer priority; |
|
|
|
private Integer priority; |
|
|
|
private Map properties; |
|
|
|
private Map<String, String> properties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TestBean(String name, TestBean testBean, String description, Integer priority, Map<String, String> props) { |
|
|
|
public TestBean() { |
|
|
|
|
|
|
|
super(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TestBean(String name, TestBean testBean, String description,Integer priority,Map props) { |
|
|
|
|
|
|
|
super(); |
|
|
|
|
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
this.testBean = testBean; |
|
|
|
this.testBean = testBean; |
|
|
|
this.description = description; |
|
|
|
this.description = description; |
|
|
|
this.priority=priority; |
|
|
|
this.priority = priority; |
|
|
|
this.properties=props; |
|
|
|
this.properties = props; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
public String getName() { |
|
|
|
return name; |
|
|
|
return name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setName(String name) { |
|
|
|
public void setName(String name) { |
|
|
|
this.name = name; |
|
|
|
this.name = name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TestBean getTestBean() { |
|
|
|
public TestBean getTestBean() { |
|
|
|
return testBean; |
|
|
|
return testBean; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setTestBean(TestBean testBean) { |
|
|
|
public void setTestBean(TestBean testBean) { |
|
|
|
this.testBean = testBean; |
|
|
|
this.testBean = testBean; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getDescription() { |
|
|
|
public String getDescription() { |
|
|
|
return description; |
|
|
|
return description; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setDescription(String description) { |
|
|
|
public void setDescription(String description) { |
|
|
|
this.description = description; |
|
|
|
this.description = description; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Integer getPriority() { |
|
|
|
public Integer getPriority() { |
|
|
|
return priority; |
|
|
|
return priority; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -168,16 +164,14 @@ public class MapAccessTests extends ExpressionTestCase { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void write(EvaluationContext context, Object target, String name, Object newValue) |
|
|
|
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException { |
|
|
|
throws AccessException { |
|
|
|
|
|
|
|
((Map) target).put(name, newValue); |
|
|
|
((Map) target).put(name, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Class<?>[] getSpecificTargetClasses() { |
|
|
|
public Class<?>[] getSpecificTargetClasses() { |
|
|
|
return new Class[] { Map.class }; |
|
|
|
return new Class<?>[] {Map.class}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|