Activated through rename to *Tests, and added method call interaction tests
Issue: SPR-7831
(cherry picked from commit 3bed6cf)
This commit is contained in:
parent
f88cbda6ef
commit
78646f1f32
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 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,10 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -27,6 +23,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
|
|
@ -36,6 +33,8 @@ import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.TypeConverter;
|
import org.springframework.expression.TypeConverter;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expression evaluation where the TypeConverter plugged in is the
|
* Expression evaluation where the TypeConverter plugged in is the
|
||||||
* {@link org.springframework.core.convert.support.GenericConversionService}.
|
* {@link org.springframework.core.convert.support.GenericConversionService}.
|
||||||
|
|
@ -43,7 +42,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCase {
|
public class ExpressionWithConversionTests extends ExpressionTestCase {
|
||||||
|
|
||||||
private static List<String> listOfString = new ArrayList<String>();
|
private static List<String> listOfString = new ArrayList<String>();
|
||||||
private static TypeDescriptor typeDescriptorForListOfString = null;
|
private static TypeDescriptor typeDescriptorForListOfString = null;
|
||||||
|
|
@ -61,8 +60,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfString = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString"));
|
ExpressionWithConversionTests.typeDescriptorForListOfString = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfString"));
|
||||||
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger"));
|
ExpressionWithConversionTests.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfInteger"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -133,45 +132,37 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Foo {
|
|
||||||
|
|
||||||
private Collection<Foo> foos;
|
|
||||||
|
|
||||||
public final String value;
|
|
||||||
|
|
||||||
public Foo(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFoos(Collection<Foo> foos) {
|
|
||||||
this.foos = foos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Foo> getFoos() {
|
|
||||||
return this.foos;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvert() {
|
public void testConvert() {
|
||||||
Foo root = new Foo("bar");
|
Foo root = new Foo("bar");
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext(root);
|
|
||||||
|
|
||||||
Collection<String> foos = Collections.singletonList("baz");
|
Collection<String> foos = Collections.singletonList("baz");
|
||||||
|
|
||||||
// property access, works
|
StandardEvaluationContext context = new StandardEvaluationContext(root);
|
||||||
|
|
||||||
|
// property access
|
||||||
Expression expression = parser.parseExpression("foos");
|
Expression expression = parser.parseExpression("foos");
|
||||||
expression.setValue(context, foos);
|
expression.setValue(context, foos);
|
||||||
Foo baz = root.getFoos().iterator().next();
|
Foo baz = root.getFoos().iterator().next();
|
||||||
assertEquals("baz", baz.value);
|
assertEquals("baz", baz.value);
|
||||||
|
|
||||||
// method call, fails (ClassCastException)
|
// method call
|
||||||
expression = parser.parseExpression("setFoos(#foos)");
|
expression = parser.parseExpression("setFoos(#foos)");
|
||||||
context.setVariable("foos", foos);
|
context.setVariable("foos", foos);
|
||||||
expression.getValue(context);
|
expression.getValue(context);
|
||||||
baz = root.getFoos().iterator().next();
|
baz = root.getFoos().iterator().next();
|
||||||
assertEquals("baz", baz.value);
|
assertEquals("baz", baz.value);
|
||||||
|
|
||||||
|
// method call with result from method call
|
||||||
|
expression = parser.parseExpression("setFoos(getFoosAsStrings())");
|
||||||
|
expression.getValue(context);
|
||||||
|
baz = root.getFoos().iterator().next();
|
||||||
|
assertEquals("baz", baz.value);
|
||||||
|
|
||||||
|
// method call with result from method call
|
||||||
|
expression = parser.parseExpression("setFoos(getFoosAsObjects())");
|
||||||
|
expression.getValue(context);
|
||||||
|
baz = root.getFoos().iterator().next();
|
||||||
|
assertEquals("baz", baz.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -193,4 +184,32 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Foo {
|
||||||
|
|
||||||
|
public final String value;
|
||||||
|
|
||||||
|
private Collection<Foo> foos;
|
||||||
|
|
||||||
|
public Foo(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFoos(Collection<Foo> foos) {
|
||||||
|
this.foos = foos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Foo> getFoos() {
|
||||||
|
return this.foos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> getFoosAsStrings() {
|
||||||
|
return Collections.singletonList("baz");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<?> getFoosAsObjects() {
|
||||||
|
return Collections.singletonList("baz");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue