Merge branch '3.2.x' into master
* 3.2.x: Exclude spring-build-src from maven publish Move spring-build-junit into spring-core Relocate MergePlugin package Develop a gradle plugin to add test dependencies Expose Gradle buildSrc for IDE support Fix [deprecation] compiler warnings Upgrade to xmlunit version 1.3 Improve 'build' folder ignores Fix regression in static setter method support Fix SpEL JavaBean compliance for setters Conflicts: spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java
This commit is contained in:
@@ -311,15 +311,10 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
*/
|
||||
protected Method findGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) {
|
||||
Method[] ms = clazz.getMethods();
|
||||
String propertyWriteMethodSuffix;
|
||||
if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
|
||||
propertyWriteMethodSuffix = propertyName;
|
||||
}
|
||||
else {
|
||||
propertyWriteMethodSuffix = StringUtils.capitalize(propertyName);
|
||||
}
|
||||
String propertyMethodSuffix = getPropertyMethodSuffix(propertyName);
|
||||
|
||||
// Try "get*" method...
|
||||
String getterName = "get" + propertyWriteMethodSuffix;
|
||||
String getterName = "get" + propertyMethodSuffix;
|
||||
for (Method method : ms) {
|
||||
if (!method.isBridge() && method.getName().equals(getterName) && method.getParameterTypes().length == 0 &&
|
||||
(!mustBeStatic || Modifier.isStatic(method.getModifiers()))) {
|
||||
@@ -327,7 +322,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
}
|
||||
// Try "is*" method...
|
||||
getterName = "is" + propertyWriteMethodSuffix;
|
||||
getterName = "is" + propertyMethodSuffix;
|
||||
for (Method method : ms) {
|
||||
if (!method.isBridge() && method.getName().equals(getterName) && method.getParameterTypes().length == 0 &&
|
||||
(boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType())) &&
|
||||
@@ -343,7 +338,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
*/
|
||||
protected Method findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic) {
|
||||
Method[] methods = clazz.getMethods();
|
||||
String setterName = "set" + StringUtils.capitalize(propertyName);
|
||||
String setterName = "set" + getPropertyMethodSuffix(propertyName);
|
||||
for (Method method : methods) {
|
||||
if (!method.isBridge() && method.getName().equals(setterName) && method.getParameterTypes().length == 1 &&
|
||||
(!mustBeStatic || Modifier.isStatic(method.getModifiers()))) {
|
||||
@@ -353,6 +348,15 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getPropertyMethodSuffix(String propertyName) {
|
||||
if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
|
||||
return propertyName;
|
||||
}
|
||||
else {
|
||||
return StringUtils.capitalize(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a field of a certain name on a specified class
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -33,57 +34,57 @@ public class DefaultComparatorUnitTests {
|
||||
public void testPrimitives() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
// primitive int
|
||||
Assert.assertTrue(comparator.compare(1, 2) < 0);
|
||||
Assert.assertTrue(comparator.compare(1, 1) == 0);
|
||||
Assert.assertTrue(comparator.compare(2, 1) > 0);
|
||||
assertTrue(comparator.compare(1, 2) < 0);
|
||||
assertTrue(comparator.compare(1, 1) == 0);
|
||||
assertTrue(comparator.compare(2, 1) > 0);
|
||||
|
||||
Assert.assertTrue(comparator.compare(1.0d, 2) < 0);
|
||||
Assert.assertTrue(comparator.compare(1.0d, 1) == 0);
|
||||
Assert.assertTrue(comparator.compare(2.0d, 1) > 0);
|
||||
assertTrue(comparator.compare(1.0d, 2) < 0);
|
||||
assertTrue(comparator.compare(1.0d, 1) == 0);
|
||||
assertTrue(comparator.compare(2.0d, 1) > 0);
|
||||
|
||||
Assert.assertTrue(comparator.compare(1.0f, 2) < 0);
|
||||
Assert.assertTrue(comparator.compare(1.0f, 1) == 0);
|
||||
Assert.assertTrue(comparator.compare(2.0f, 1) > 0);
|
||||
assertTrue(comparator.compare(1.0f, 2) < 0);
|
||||
assertTrue(comparator.compare(1.0f, 1) == 0);
|
||||
assertTrue(comparator.compare(2.0f, 1) > 0);
|
||||
|
||||
Assert.assertTrue(comparator.compare(1L, 2) < 0);
|
||||
Assert.assertTrue(comparator.compare(1L, 1) == 0);
|
||||
Assert.assertTrue(comparator.compare(2L, 1) > 0);
|
||||
assertTrue(comparator.compare(1L, 2) < 0);
|
||||
assertTrue(comparator.compare(1L, 1) == 0);
|
||||
assertTrue(comparator.compare(2L, 1) > 0);
|
||||
|
||||
Assert.assertTrue(comparator.compare(1, 2L) < 0);
|
||||
Assert.assertTrue(comparator.compare(1, 1L) == 0);
|
||||
Assert.assertTrue(comparator.compare(2, 1L) > 0);
|
||||
assertTrue(comparator.compare(1, 2L) < 0);
|
||||
assertTrue(comparator.compare(1, 1L) == 0);
|
||||
assertTrue(comparator.compare(2, 1L) > 0);
|
||||
|
||||
Assert.assertTrue(comparator.compare(1L, 2L) < 0);
|
||||
Assert.assertTrue(comparator.compare(1L, 1L) == 0);
|
||||
Assert.assertTrue(comparator.compare(2L, 1L) > 0);
|
||||
assertTrue(comparator.compare(1L, 2L) < 0);
|
||||
assertTrue(comparator.compare(1L, 1L) == 0);
|
||||
assertTrue(comparator.compare(2L, 1L) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNulls() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
Assert.assertTrue(comparator.compare(null,"abc")<0);
|
||||
Assert.assertTrue(comparator.compare(null,null)==0);
|
||||
Assert.assertTrue(comparator.compare("abc",null)>0);
|
||||
assertTrue(comparator.compare(null,"abc")<0);
|
||||
assertTrue(comparator.compare(null,null)==0);
|
||||
assertTrue(comparator.compare("abc",null)>0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjects() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
Assert.assertTrue(comparator.compare("a","a")==0);
|
||||
Assert.assertTrue(comparator.compare("a","b")<0);
|
||||
Assert.assertTrue(comparator.compare("b","a")>0);
|
||||
assertTrue(comparator.compare("a","a")==0);
|
||||
assertTrue(comparator.compare("a","b")<0);
|
||||
assertTrue(comparator.compare("b","a")>0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanCompare() throws EvaluationException {
|
||||
TypeComparator comparator = new StandardTypeComparator();
|
||||
Assert.assertTrue(comparator.canCompare(null,1));
|
||||
Assert.assertTrue(comparator.canCompare(1,null));
|
||||
assertTrue(comparator.canCompare(null,1));
|
||||
assertTrue(comparator.canCompare(1,null));
|
||||
|
||||
Assert.assertTrue(comparator.canCompare(2,1));
|
||||
Assert.assertTrue(comparator.canCompare("abc","def"));
|
||||
Assert.assertTrue(comparator.canCompare("abc",3));
|
||||
Assert.assertFalse(comparator.canCompare(String.class,3));
|
||||
assertTrue(comparator.canCompare(2,1));
|
||||
assertTrue(comparator.canCompare("abc","def"));
|
||||
assertTrue(comparator.canCompare("abc",3));
|
||||
assertFalse(comparator.canCompare(String.class,3));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -23,8 +26,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -76,14 +77,14 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
// They are reusable
|
||||
value = expr.getValue();
|
||||
|
||||
Assert.assertEquals("hello world", value);
|
||||
Assert.assertEquals(String.class, value.getClass());
|
||||
assertEquals("hello world", value);
|
||||
assertEquals(String.class, value.getClass());
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,16 +104,16 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
|
||||
Expression expr = parser.parseRaw("#favouriteColour");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("blue", value);
|
||||
assertEquals("blue", value);
|
||||
|
||||
expr = parser.parseRaw("#primes.get(1)");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(3, value);
|
||||
assertEquals(3, value);
|
||||
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
expr = parser.parseRaw("#primes.?[#this>10]");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("[11, 13, 17]", value.toString());
|
||||
assertEquals("[11, 13, 17]", value.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -141,30 +142,30 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
// read it, set it, read it again
|
||||
Expression expr = parser.parseRaw("str");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wibble", value);
|
||||
assertEquals("wibble", value);
|
||||
expr = parser.parseRaw("str");
|
||||
expr.setValue(ctx, "wobble");
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wobble", value);
|
||||
assertEquals("wobble", value);
|
||||
// or using assignment within the expression
|
||||
expr = parser.parseRaw("str='wabble'");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseRaw("str");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals("wabble", value);
|
||||
assertEquals("wabble", value);
|
||||
|
||||
// private property will be accessed through getter()
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(42, value);
|
||||
assertEquals(42, value);
|
||||
|
||||
// ... and set through setter
|
||||
expr = parser.parseRaw("property=4");
|
||||
value = expr.getValue(ctx);
|
||||
expr = parser.parseRaw("property");
|
||||
value = expr.getValue(ctx);
|
||||
Assert.assertEquals(4,value);
|
||||
assertEquals(4,value);
|
||||
}
|
||||
|
||||
public static String repeat(String s) { return s+s; }
|
||||
@@ -183,14 +184,14 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
|
||||
Expression expr = parser.parseRaw("#repeat('hello')");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals("hellohello", value);
|
||||
assertEquals("hellohello", value);
|
||||
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,13 +208,13 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
ctx.addPropertyAccessor(new FruitColourAccessor());
|
||||
Expression expr = parser.parseRaw("orange");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals(Color.orange, value);
|
||||
assertEquals(Color.orange, value);
|
||||
|
||||
try {
|
||||
expr.setValue(ctx, Color.blue);
|
||||
Assert.fail("Should not be allowed to set oranges to be blue !");
|
||||
fail("Should not be allowed to set oranges to be blue !");
|
||||
} catch (SpelEvaluationException ee) {
|
||||
Assert.assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||
assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,14 +228,14 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
||||
ctx.addPropertyAccessor(new VegetableColourAccessor());
|
||||
Expression expr = parser.parseRaw("pea");
|
||||
Object value = expr.getValue(ctx);
|
||||
Assert.assertEquals(Color.green, value);
|
||||
assertEquals(Color.green, value);
|
||||
|
||||
try {
|
||||
expr.setValue(ctx, Color.blue);
|
||||
Assert.fail("Should not be allowed to set peas to be blue !");
|
||||
fail("Should not be allowed to set peas to be blue !");
|
||||
}
|
||||
catch (SpelEvaluationException ee) {
|
||||
Assert.assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||
assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -42,7 +45,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
public void testConstruction() {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
ExpressionState state = new ExpressionState(context);
|
||||
Assert.assertEquals(context,state.getEvaluationContext());
|
||||
assertEquals(context,state.getEvaluationContext());
|
||||
}
|
||||
|
||||
// Local variables are in variable scopes which come and go during evaluation. Normal variables are
|
||||
@@ -53,129 +56,129 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
ExpressionState state = getState();
|
||||
|
||||
Object value = state.lookupLocalVariable("foo");
|
||||
Assert.assertNull(value);
|
||||
assertNull(value);
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
value = state.lookupLocalVariable("foo");
|
||||
Assert.assertEquals(34,value);
|
||||
assertEquals(34,value);
|
||||
|
||||
state.setLocalVariable("foo",null);
|
||||
value = state.lookupLocalVariable("foo");
|
||||
Assert.assertEquals(null,value);
|
||||
assertEquals(null,value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariables() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(34,typedValue.getValue());
|
||||
Assert.assertEquals(Integer.class,typedValue.getTypeDescriptor().getType());
|
||||
assertEquals(34,typedValue.getValue());
|
||||
assertEquals(Integer.class,typedValue.getTypeDescriptor().getType());
|
||||
|
||||
state.setVariable("foo","abc");
|
||||
typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals("abc",typedValue.getValue());
|
||||
Assert.assertEquals(String.class,typedValue.getTypeDescriptor().getType());
|
||||
assertEquals("abc",typedValue.getValue());
|
||||
assertEquals(String.class,typedValue.getTypeDescriptor().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoVariableInteference() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setVariable("goo","hello");
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalVariableNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(null,state.lookupLocalVariable("foo"));
|
||||
assertEquals(null,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.enterScope(null);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in upper scope
|
||||
assertEquals(12,state.lookupLocalVariable("foo")); // found in upper scope
|
||||
|
||||
state.setLocalVariable("foo","abc");
|
||||
Assert.assertEquals("abc",state.lookupLocalVariable("foo")); // found in nested scope
|
||||
assertEquals("abc",state.lookupLocalVariable("foo")); // found in nested scope
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in nested scope
|
||||
assertEquals(12,state.lookupLocalVariable("foo")); // found in nested scope
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootContextObject() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
|
||||
assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
|
||||
|
||||
// although the root object is being set on the evaluation context, the value in the 'state' remains what it was when constructed
|
||||
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
|
||||
Assert.assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
|
||||
// Assert.assertEquals(null, state.getRootContextObject().getValue());
|
||||
assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
|
||||
// assertEquals(null, state.getRootContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getRootContextObject());
|
||||
assertEquals(TypedValue.NULL,state.getRootContextObject());
|
||||
|
||||
|
||||
((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null);
|
||||
Assert.assertEquals(null,state.getRootContextObject().getValue());
|
||||
assertEquals(null,state.getRootContextObject().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActiveContextObject() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
|
||||
try {
|
||||
state.popActiveContextObject();
|
||||
Assert.fail("stack should be empty...");
|
||||
fail("stack should be empty...");
|
||||
} catch (EmptyStackException ese) {
|
||||
// success
|
||||
}
|
||||
|
||||
state.pushActiveContextObject(new TypedValue(34));
|
||||
Assert.assertEquals(34,state.getActiveContextObject().getValue());
|
||||
assertEquals(34,state.getActiveContextObject().getValue());
|
||||
|
||||
state.pushActiveContextObject(new TypedValue("hello"));
|
||||
Assert.assertEquals("hello",state.getActiveContextObject().getValue());
|
||||
assertEquals("hello",state.getActiveContextObject().getValue());
|
||||
|
||||
state.popActiveContextObject();
|
||||
Assert.assertEquals(34,state.getActiveContextObject().getValue());
|
||||
assertEquals(34,state.getActiveContextObject().getValue());
|
||||
|
||||
state.popActiveContextObject();
|
||||
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getActiveContextObject());
|
||||
assertEquals(TypedValue.NULL,state.getActiveContextObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopes() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
|
||||
state.enterScope("foo",34);
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
|
||||
state.exitScope();
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,33 +188,33 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
// supplied should override root on context
|
||||
ExpressionState state = new ExpressionState(ctx,new TypedValue("i am a string"));
|
||||
TypedValue stateRoot = state.getRootContextObject();
|
||||
Assert.assertEquals(String.class,stateRoot.getTypeDescriptor().getType());
|
||||
Assert.assertEquals("i am a string",stateRoot.getValue());
|
||||
assertEquals(String.class,stateRoot.getTypeDescriptor().getType());
|
||||
assertEquals("i am a string",stateRoot.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulatedNestedScopesMap() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
|
||||
Map<String,Object> m = new HashMap<String,Object>();
|
||||
m.put("foo",34);
|
||||
m.put("goo","abc");
|
||||
|
||||
state.enterScope(m);
|
||||
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
Assert.assertEquals("abc",state.lookupLocalVariable("goo"));
|
||||
assertEquals(34,state.lookupLocalVariable("foo"));
|
||||
assertEquals("abc",state.lookupLocalVariable("goo"));
|
||||
|
||||
state.enterScope(null);
|
||||
state.setLocalVariable("foo",12);
|
||||
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
Assert.assertEquals("abc",state.lookupLocalVariable("goo"));
|
||||
assertEquals(12,state.lookupLocalVariable("foo"));
|
||||
assertEquals("abc",state.lookupLocalVariable("goo"));
|
||||
|
||||
state.exitScope();
|
||||
state.exitScope();
|
||||
Assert.assertNull(state.lookupLocalVariable("foo"));
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
assertNull(state.lookupLocalVariable("foo"));
|
||||
assertNull(state.lookupLocalVariable("goo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,38 +222,38 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
ExpressionState state = getState();
|
||||
try {
|
||||
state.operate(Operation.ADD,1,2);
|
||||
Assert.fail("should have failed");
|
||||
fail("should have failed");
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException sEx = (SpelEvaluationException)ee;
|
||||
Assert.assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
|
||||
assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
|
||||
}
|
||||
|
||||
try {
|
||||
state.operate(Operation.ADD,null,null);
|
||||
Assert.fail("should have failed");
|
||||
fail("should have failed");
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException sEx = (SpelEvaluationException)ee;
|
||||
Assert.assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
|
||||
assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparator() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getEvaluationContext().getTypeComparator(),state.getTypeComparator());
|
||||
assertEquals(state.getEvaluationContext().getTypeComparator(),state.getTypeComparator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeLocator() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertNotNull(state.getEvaluationContext().getTypeLocator());
|
||||
Assert.assertEquals(Integer.class,state.findType("java.lang.Integer"));
|
||||
assertNotNull(state.getEvaluationContext().getTypeLocator());
|
||||
assertEquals(Integer.class,state.findType("java.lang.Integer"));
|
||||
try {
|
||||
state.findType("someMadeUpName");
|
||||
Assert.fail("Should have failed to find it");
|
||||
fail("Should have failed to find it");
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException sEx = (SpelEvaluationException)ee;
|
||||
Assert.assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
|
||||
assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,16 +261,16 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
||||
public void testTypeConversion() throws EvaluationException {
|
||||
ExpressionState state = getState();
|
||||
String s = (String)state.convertValue(34, TypeDescriptor.valueOf(String.class));
|
||||
Assert.assertEquals("34",s);
|
||||
assertEquals("34",s);
|
||||
|
||||
s = (String)state.convertValue(new TypedValue(34), TypeDescriptor.valueOf(String.class));
|
||||
Assert.assertEquals("34",s);
|
||||
assertEquals("34",s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAccessors() {
|
||||
ExpressionState state = getState();
|
||||
Assert.assertEquals(state.getEvaluationContext().getPropertyAccessors(),state.getPropertyAccessors());
|
||||
assertEquals(state.getEvaluationContext().getPropertyAccessors(),state.getPropertyAccessors());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
@@ -54,13 +55,13 @@ public abstract class ExpressionTestCase {
|
||||
try {
|
||||
Expression expr = parser.parseExpression(expression);
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||
}
|
||||
// Class<?> expressionType = expr.getValueType();
|
||||
// Assert.assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
||||
// assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
||||
// '"+expressionType+"'",
|
||||
// expectedResultType,expressionType);
|
||||
|
||||
@@ -71,12 +72,12 @@ public abstract class ExpressionTestCase {
|
||||
if (expectedValue == null) {
|
||||
return; // no point doing other checks
|
||||
}
|
||||
Assert.assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
null);
|
||||
}
|
||||
|
||||
Class<?> resultType = value.getClass();
|
||||
Assert.assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType
|
||||
assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType
|
||||
+ "' but result was of type '" + resultType + "'", expectedResultType, resultType);
|
||||
// .equals/* isAssignableFrom */(resultType), truers);
|
||||
|
||||
@@ -84,17 +85,17 @@ public abstract class ExpressionTestCase {
|
||||
// in the above expression...
|
||||
|
||||
if (expectedValue instanceof String) {
|
||||
Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
ExpressionTestCase.stringValueOf(value));
|
||||
} else {
|
||||
Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
}
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +103,13 @@ public abstract class ExpressionTestCase {
|
||||
try {
|
||||
Expression expr = parser.parseExpression(expression);
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||
}
|
||||
// Class<?> expressionType = expr.getValueType();
|
||||
// Assert.assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
||||
// assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
||||
// '"+expressionType+"'",
|
||||
// expectedResultType,expressionType);
|
||||
|
||||
@@ -116,23 +117,23 @@ public abstract class ExpressionTestCase {
|
||||
if (value == null) {
|
||||
if (expectedValue == null)
|
||||
return; // no point doing other checks
|
||||
Assert.assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
null);
|
||||
}
|
||||
|
||||
Class<?> resultType = value.getClass();
|
||||
Assert.assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType
|
||||
assertEquals("Type of the actual result was not as expected. Expected '" + expectedResultType
|
||||
+ "' but result was of type '" + resultType + "'", expectedResultType, resultType);
|
||||
// .equals/* isAssignableFrom */(resultType), truers);
|
||||
Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
// isAssignableFrom would allow some room for compatibility
|
||||
// in the above expression...
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Unexpected EvaluationException: " + ex.getMessage());
|
||||
fail("Unexpected EvaluationException: " + ex.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
Assert.fail("Unexpected ParseException: " + pe.getMessage());
|
||||
fail("Unexpected ParseException: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ public abstract class ExpressionTestCase {
|
||||
try {
|
||||
Expression e = parser.parseExpression(expression);
|
||||
if (e == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
@@ -161,19 +162,19 @@ public abstract class ExpressionTestCase {
|
||||
if (expectedValue == null)
|
||||
return; // no point doing other
|
||||
// checks
|
||||
Assert.assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue,
|
||||
null);
|
||||
}
|
||||
Class<? extends Object> resultType = value.getClass();
|
||||
if (expectedValue instanceof String) {
|
||||
Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
ExpressionTestCase.stringValueOf(value));
|
||||
} else {
|
||||
Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||
}
|
||||
// Assert.assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
// assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||
// ExpressionTestCase.stringValueOf(value));
|
||||
Assert.assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult
|
||||
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult
|
||||
+ "' but result was of type '" + resultType + "'", expectedClassOfResult
|
||||
.equals/* isAssignableFrom */(resultType), true);
|
||||
// TODO isAssignableFrom would allow some room for compatibility
|
||||
@@ -182,16 +183,16 @@ public abstract class ExpressionTestCase {
|
||||
boolean isWritable = e.isWritable(eContext);
|
||||
if (isWritable != shouldBeWritable) {
|
||||
if (shouldBeWritable)
|
||||
Assert.fail("Expected the expression to be writable but it is not");
|
||||
fail("Expected the expression to be writable but it is not");
|
||||
else
|
||||
Assert.fail("Expected the expression to be readonly but it is not");
|
||||
fail("Expected the expression to be readonly but it is not");
|
||||
}
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +223,7 @@ public abstract class ExpressionTestCase {
|
||||
try {
|
||||
Expression expr = parser.parseExpression(expression);
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (expectedReturnType != null) {
|
||||
@SuppressWarnings("unused")
|
||||
@@ -231,18 +232,18 @@ public abstract class ExpressionTestCase {
|
||||
@SuppressWarnings("unused")
|
||||
Object value = expr.getValue(eContext);
|
||||
}
|
||||
Assert.fail("Should have failed with message " + expectedMessage);
|
||||
fail("Should have failed with message " + expectedMessage);
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
||||
if (ex.getMessageCode() != expectedMessage) {
|
||||
// System.out.println(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
Assert.assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||
}
|
||||
if (otherProperties != null && otherProperties.length != 0) {
|
||||
// first one is expected position of the error within the string
|
||||
int pos = ((Integer) otherProperties[0]).intValue();
|
||||
Assert.assertEquals("Did not get correct position reported in error ", pos, ex.getPosition());
|
||||
assertEquals("Did not get correct position reported in error ", pos, ex.getPosition());
|
||||
if (otherProperties.length > 1) {
|
||||
// Check inserts match
|
||||
Object[] inserts = ex.getInserts();
|
||||
@@ -251,25 +252,25 @@ public abstract class ExpressionTestCase {
|
||||
}
|
||||
if (inserts.length < otherProperties.length - 1) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Cannot check " + (otherProperties.length - 1)
|
||||
fail("Cannot check " + (otherProperties.length - 1)
|
||||
+ " properties of the exception, it only has " + inserts.length + " inserts");
|
||||
}
|
||||
for (int i = 1; i < otherProperties.length; i++) {
|
||||
if (otherProperties[i] == null) {
|
||||
if (inserts[i - 1] != null) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Insert does not match, expected 'null' but insert value was '" + inserts[i - 1]
|
||||
fail("Insert does not match, expected 'null' but insert value was '" + inserts[i - 1]
|
||||
+ "'");
|
||||
}
|
||||
} else if (inserts[i - 1] == null) {
|
||||
if (otherProperties[i] != null) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Insert does not match, expected '" + otherProperties[i]
|
||||
fail("Insert does not match, expected '" + otherProperties[i]
|
||||
+ "' but insert value was 'null'");
|
||||
}
|
||||
} else if (!inserts[i - 1].equals(otherProperties[i])) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
||||
fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
||||
+ inserts[i - 1] + "'");
|
||||
}
|
||||
}
|
||||
@@ -277,7 +278,7 @@ public abstract class ExpressionTestCase {
|
||||
}
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,16 +294,16 @@ public abstract class ExpressionTestCase {
|
||||
try {
|
||||
Expression expr = parser.parseExpression(expression);
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||
Assert.fail("Parsing should have failed!");
|
||||
fail("Parsing should have failed!");
|
||||
} catch (ParseException pe) {
|
||||
// pe.printStackTrace();
|
||||
// Throwable t = pe.getCause();
|
||||
// if (t == null) {
|
||||
// Assert.fail("ParseException caught with no defined cause");
|
||||
// fail("ParseException caught with no defined cause");
|
||||
// }
|
||||
// if (!(t instanceof SpelEvaluationException)) {
|
||||
// t.printStackTrace();
|
||||
// Assert.fail("Cause of parse exception is not a SpelException");
|
||||
// fail("Cause of parse exception is not a SpelException");
|
||||
// }
|
||||
// SpelEvaluationException ex = (SpelEvaluationException) t;
|
||||
// pe.printStackTrace();
|
||||
@@ -310,12 +311,12 @@ public abstract class ExpressionTestCase {
|
||||
if (ex.getMessageCode() != expectedMessage) {
|
||||
// System.out.println(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
Assert.assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||
}
|
||||
if (otherProperties != null && otherProperties.length != 0) {
|
||||
// first one is expected position of the error within the string
|
||||
int pos = ((Integer) otherProperties[0]).intValue();
|
||||
Assert.assertEquals("Did not get correct position reported in error ", pos, ex.getPosition());
|
||||
assertEquals("Did not get correct position reported in error ", pos, ex.getPosition());
|
||||
if (otherProperties.length > 1) {
|
||||
// Check inserts match
|
||||
Object[] inserts = ex.getInserts();
|
||||
@@ -324,13 +325,13 @@ public abstract class ExpressionTestCase {
|
||||
}
|
||||
if (inserts.length < otherProperties.length - 1) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Cannot check " + (otherProperties.length - 1)
|
||||
fail("Cannot check " + (otherProperties.length - 1)
|
||||
+ " properties of the exception, it only has " + inserts.length + " inserts");
|
||||
}
|
||||
for (int i = 1; i < otherProperties.length; i++) {
|
||||
if (!inserts[i - 1].equals(otherProperties[i])) {
|
||||
ex.printStackTrace();
|
||||
Assert.fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
||||
fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
||||
+ inserts[i - 1] + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
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.Collection;
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class InProgressTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testProjection06() throws Exception {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.![true]");
|
||||
Assert.assertEquals("'abc'.![true]", expr.toStringAST());
|
||||
assertEquals("'abc'.![true]", expr.toStringAST());
|
||||
}
|
||||
|
||||
// SELECTION
|
||||
@@ -141,11 +141,11 @@ public class InProgressTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testSelectionAST() throws Exception {
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
|
||||
Assert.assertEquals("'abc'.^[true]", expr.toStringAST());
|
||||
assertEquals("'abc'.^[true]", expr.toStringAST());
|
||||
expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
|
||||
Assert.assertEquals("'abc'.?[true]", expr.toStringAST());
|
||||
assertEquals("'abc'.?[true]", expr.toStringAST());
|
||||
expr = (SpelExpression) parser.parseExpression("'abc'.$[true]");
|
||||
Assert.assertEquals("'abc'.$[true]", expr.toStringAST());
|
||||
assertEquals("'abc'.$[true]", expr.toStringAST());
|
||||
}
|
||||
|
||||
// Constructor invocation
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -41,10 +43,10 @@ public class LiteralExpressionTests {
|
||||
checkString("somevalue", lEx.getValue(new Rooty(), String.class));
|
||||
checkString("somevalue", lEx.getValue(ctx, new Rooty()));
|
||||
checkString("somevalue", lEx.getValue(ctx, new Rooty(),String.class));
|
||||
Assert.assertEquals("somevalue", lEx.getExpressionString());
|
||||
Assert.assertFalse(lEx.isWritable(new StandardEvaluationContext()));
|
||||
Assert.assertFalse(lEx.isWritable(new Rooty()));
|
||||
Assert.assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
assertEquals("somevalue", lEx.getExpressionString());
|
||||
assertFalse(lEx.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(lEx.isWritable(new Rooty()));
|
||||
assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
}
|
||||
|
||||
static class Rooty {}
|
||||
@@ -54,51 +56,51 @@ public class LiteralExpressionTests {
|
||||
try {
|
||||
LiteralExpression lEx = new LiteralExpression("somevalue");
|
||||
lEx.setValue(new StandardEvaluationContext(), "flibble");
|
||||
Assert.fail("Should have got an exception that the value cannot be set");
|
||||
fail("Should have got an exception that the value cannot be set");
|
||||
}
|
||||
catch (EvaluationException ee) {
|
||||
// success, not allowed - whilst here, check the expression value in the exception
|
||||
Assert.assertEquals(ee.getExpressionString(), "somevalue");
|
||||
assertEquals(ee.getExpressionString(), "somevalue");
|
||||
}
|
||||
try {
|
||||
LiteralExpression lEx = new LiteralExpression("somevalue");
|
||||
lEx.setValue(new Rooty(), "flibble");
|
||||
Assert.fail("Should have got an exception that the value cannot be set");
|
||||
fail("Should have got an exception that the value cannot be set");
|
||||
}
|
||||
catch (EvaluationException ee) {
|
||||
// success, not allowed - whilst here, check the expression value in the exception
|
||||
Assert.assertEquals(ee.getExpressionString(), "somevalue");
|
||||
assertEquals(ee.getExpressionString(), "somevalue");
|
||||
}
|
||||
try {
|
||||
LiteralExpression lEx = new LiteralExpression("somevalue");
|
||||
lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble");
|
||||
Assert.fail("Should have got an exception that the value cannot be set");
|
||||
fail("Should have got an exception that the value cannot be set");
|
||||
}
|
||||
catch (EvaluationException ee) {
|
||||
// success, not allowed - whilst here, check the expression value in the exception
|
||||
Assert.assertEquals(ee.getExpressionString(), "somevalue");
|
||||
assertEquals(ee.getExpressionString(), "somevalue");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueType() throws Exception {
|
||||
LiteralExpression lEx = new LiteralExpression("somevalue");
|
||||
Assert.assertEquals(String.class, lEx.getValueType());
|
||||
Assert.assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext()));
|
||||
Assert.assertEquals(String.class, lEx.getValueType(new Rooty()));
|
||||
Assert.assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext(), new Rooty()));
|
||||
Assert.assertEquals(String.class, lEx.getValueTypeDescriptor().getType());
|
||||
Assert.assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType());
|
||||
Assert.assertEquals(String.class, lEx.getValueTypeDescriptor(new Rooty()).getType());
|
||||
Assert.assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType());
|
||||
assertEquals(String.class, lEx.getValueType());
|
||||
assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext()));
|
||||
assertEquals(String.class, lEx.getValueType(new Rooty()));
|
||||
assertEquals(String.class, lEx.getValueType(new StandardEvaluationContext(), new Rooty()));
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor().getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext()).getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new Rooty()).getType());
|
||||
assertEquals(String.class, lEx.getValueTypeDescriptor(new StandardEvaluationContext(), new Rooty()).getType());
|
||||
}
|
||||
|
||||
private void checkString(String expectedString, Object value) {
|
||||
if (!(value instanceof String)) {
|
||||
Assert.fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");
|
||||
fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");
|
||||
}
|
||||
if (!((String) value).equals(expectedString)) {
|
||||
Assert.fail("Did not get expected result. Should have been '" + expectedString + "' but was '" + value + "'");
|
||||
fail("Did not get expected result. Should have been '" + expectedString + "' but was '" + value + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
@@ -163,10 +164,10 @@ public class LiteralTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testNotWritable() throws Exception {
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("37");
|
||||
Assert.assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
expr = (SpelExpression)parser.parseExpression("37L");
|
||||
Assert.assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
expr = (SpelExpression)parser.parseExpression("true");
|
||||
Assert.assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(expr.isWritable(new StandardEvaluationContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.AccessException;
|
||||
@@ -56,7 +56,7 @@ public class MapAccessTests extends ExpressionTestCase {
|
||||
|
||||
Expression expr = parser.parseExpression("testMap.monday");
|
||||
Object value = expr.getValue(ctx, String.class);
|
||||
Assert.assertEquals("montag", value);
|
||||
assertEquals("montag", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ public class MapAccessTests extends ExpressionTestCase {
|
||||
|
||||
Expression expr = parser.parseExpression("testMap[#day]");
|
||||
Object value = expr.getValue(ctx, String.class);
|
||||
Assert.assertEquals("samstag", value);
|
||||
assertEquals("samstag", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -64,12 +64,12 @@ public class OperatorOverloaderTests extends ExpressionTestCase {
|
||||
eContext.setOperatorOverloader(new StringAndBooleanAddition());
|
||||
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("'abc'+true");
|
||||
Assert.assertEquals("abctrue",expr.getValue(eContext));
|
||||
assertEquals("abctrue",expr.getValue(eContext));
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'-true");
|
||||
Assert.assertEquals("abc",expr.getValue(eContext));
|
||||
assertEquals("abc",expr.getValue(eContext));
|
||||
|
||||
expr = (SpelExpression)parser.parseExpression("'abc'+null");
|
||||
Assert.assertEquals("abcnull",expr.getValue(eContext));
|
||||
assertEquals("abcnull",expr.getValue(eContext));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.ast.Operator;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
@@ -208,9 +209,9 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
|
||||
// AST:
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("+3");
|
||||
Assert.assertEquals("+3",expr.toStringAST());
|
||||
assertEquals("+3",expr.toStringAST());
|
||||
expr = (SpelExpression)parser.parseExpression("2+3");
|
||||
Assert.assertEquals("(2 + 3)",expr.toStringAST());
|
||||
assertEquals("(2 + 3)",expr.toStringAST());
|
||||
|
||||
// use as a unary operator
|
||||
evaluate("+5d",5d,Double.class);
|
||||
@@ -232,9 +233,9 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
evaluateAndCheckError("'ab' - 2", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
evaluateAndCheckError("2-'ab'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
|
||||
SpelExpression expr = (SpelExpression)parser.parseExpression("-3");
|
||||
Assert.assertEquals("-3",expr.toStringAST());
|
||||
assertEquals("-3",expr.toStringAST());
|
||||
expr = (SpelExpression)parser.parseExpression("2-3");
|
||||
Assert.assertEquals("(2 - 3)",expr.toStringAST());
|
||||
assertEquals("(2 - 3)",expr.toStringAST());
|
||||
|
||||
evaluate("-5d",-5d,Double.class);
|
||||
evaluate("-5L",-5L,Long.class);
|
||||
@@ -286,40 +287,40 @@ public class OperatorTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testOperatorNames() throws Exception {
|
||||
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
|
||||
Assert.assertEquals("==",node.getOperatorName());
|
||||
assertEquals("==",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
|
||||
Assert.assertEquals("!=",node.getOperatorName());
|
||||
assertEquals("!=",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
|
||||
Assert.assertEquals("/",node.getOperatorName());
|
||||
assertEquals("/",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
|
||||
Assert.assertEquals("+",node.getOperatorName());
|
||||
assertEquals("+",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
|
||||
Assert.assertEquals("-",node.getOperatorName());
|
||||
assertEquals("-",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
|
||||
Assert.assertEquals("<",node.getOperatorName());
|
||||
assertEquals("<",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
|
||||
Assert.assertEquals("<=",node.getOperatorName());
|
||||
assertEquals("<=",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
|
||||
Assert.assertEquals("*",node.getOperatorName());
|
||||
assertEquals("*",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
|
||||
Assert.assertEquals("%",node.getOperatorName());
|
||||
assertEquals("%",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
|
||||
Assert.assertEquals(">=",node.getOperatorName());
|
||||
assertEquals(">=",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
|
||||
Assert.assertEquals("between",node.getOperatorName());
|
||||
assertEquals("between",node.getOperatorName());
|
||||
|
||||
node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
|
||||
Assert.assertEquals("^",node.getOperatorName());
|
||||
assertEquals("^",node.getOperatorName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.ParseException;
|
||||
@@ -462,12 +463,12 @@ public class ParsingTests {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.err, e);
|
||||
}
|
||||
if (e == null) {
|
||||
Assert.fail("Parsed exception was null");
|
||||
fail("Parsed exception was null");
|
||||
}
|
||||
Assert.assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
|
||||
assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
|
||||
} catch (ParseException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.build.junit.Assume;
|
||||
import org.springframework.build.junit.TestGroup;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
@@ -54,7 +55,7 @@ public class PerformanceTests {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("placeOfBirth.city");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
expr.getValue(eContext);
|
||||
}
|
||||
@@ -63,7 +64,7 @@ public class PerformanceTests {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("placeOfBirth.city");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
expr.getValue(eContext);
|
||||
}
|
||||
@@ -75,7 +76,7 @@ public class PerformanceTests {
|
||||
|
||||
Expression expr = parser.parseExpression("placeOfBirth.city");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
starttime = System.currentTimeMillis();
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
@@ -89,7 +90,7 @@ public class PerformanceTests {
|
||||
if (reuseTime > freshParseTime) {
|
||||
System.out.println("Fresh parse every time, ITERATIONS iterations = " + freshParseTime + "ms");
|
||||
System.out.println("Reuse SpelExpression, ITERATIONS iterations = " + reuseTime + "ms");
|
||||
Assert.fail("Should have been quicker to reuse!");
|
||||
fail("Should have been quicker to reuse!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ public class PerformanceTests {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("getPlaceOfBirth().getCity()");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
expr.getValue(eContext);
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class PerformanceTests {
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
Expression expr = parser.parseExpression("getPlaceOfBirth().getCity()");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
expr.getValue(eContext);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ public class PerformanceTests {
|
||||
|
||||
Expression expr = parser.parseExpression("getPlaceOfBirth().getCity()");
|
||||
if (expr == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
starttime = System.currentTimeMillis();
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
@@ -140,7 +141,7 @@ public class PerformanceTests {
|
||||
if (reuseTime > freshParseTime) {
|
||||
System.out.println("Fresh parse every time, ITERATIONS iterations = " + freshParseTime + "ms");
|
||||
System.out.println("Reuse SpelExpression, ITERATIONS iterations = " + reuseTime + "ms");
|
||||
Assert.fail("Should have been quicker to reuse!");
|
||||
fail("Should have been quicker to reuse!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
@@ -78,14 +80,14 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
EvaluationContext context = new StandardEvaluationContext(null);
|
||||
try {
|
||||
expr.getValue(context);
|
||||
Assert.fail("Should have failed - default property resolver cannot resolve on null");
|
||||
fail("Should have failed - default property resolver cannot resolve on null");
|
||||
} catch (Exception e) {
|
||||
checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
|
||||
}
|
||||
Assert.assertFalse(expr.isWritable(context));
|
||||
assertFalse(expr.isWritable(context));
|
||||
try {
|
||||
expr.setValue(context,"abc");
|
||||
Assert.fail("Should have failed - default property resolver cannot resolve on null");
|
||||
fail("Should have failed - default property resolver cannot resolve on null");
|
||||
} catch (Exception e) {
|
||||
checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
|
||||
}
|
||||
@@ -94,9 +96,9 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
private void checkException(Exception e, SpelMessage expectedMessage) {
|
||||
if (e instanceof SpelEvaluationException) {
|
||||
SpelMessage sm = ((SpelEvaluationException)e).getMessageCode();
|
||||
Assert.assertEquals("Expected exception type did not occur",expectedMessage,sm);
|
||||
assertEquals("Expected exception type did not occur",expectedMessage,sm);
|
||||
} else {
|
||||
Assert.fail("Should be a SpelException "+e);
|
||||
fail("Should be a SpelException "+e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,22 +114,22 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
ctx.addPropertyAccessor(new StringyPropertyAccessor());
|
||||
Expression expr = parser.parseRaw("new String('hello').flibbles");
|
||||
Integer i = expr.getValue(ctx, Integer.class);
|
||||
Assert.assertEquals((int) i, 7);
|
||||
assertEquals((int) i, 7);
|
||||
|
||||
// The reflection one will be used for other properties...
|
||||
expr = parser.parseRaw("new String('hello').CASE_INSENSITIVE_ORDER");
|
||||
Object o = expr.getValue(ctx);
|
||||
Assert.assertNotNull(o);
|
||||
assertNotNull(o);
|
||||
|
||||
expr = parser.parseRaw("new String('hello').flibbles");
|
||||
expr.setValue(ctx, 99);
|
||||
i = expr.getValue(ctx, Integer.class);
|
||||
Assert.assertEquals((int) i, 99);
|
||||
assertEquals((int) i, 99);
|
||||
|
||||
// Cannot set it to a string value
|
||||
try {
|
||||
expr.setValue(ctx, "not allowed");
|
||||
Assert.fail("Should not have been allowed");
|
||||
fail("Should not have been allowed");
|
||||
} catch (EvaluationException e) {
|
||||
// success - message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property
|
||||
// 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
|
||||
@@ -141,20 +143,20 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
|
||||
// reflective property accessor is the only one by default
|
||||
List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors();
|
||||
Assert.assertEquals(1,propertyAccessors.size());
|
||||
assertEquals(1,propertyAccessors.size());
|
||||
|
||||
StringyPropertyAccessor spa = new StringyPropertyAccessor();
|
||||
ctx.addPropertyAccessor(spa);
|
||||
Assert.assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
|
||||
List<PropertyAccessor> copy = new ArrayList<PropertyAccessor>();
|
||||
copy.addAll(ctx.getPropertyAccessors());
|
||||
Assert.assertTrue(ctx.removePropertyAccessor(spa));
|
||||
Assert.assertFalse(ctx.removePropertyAccessor(spa));
|
||||
Assert.assertEquals(1,ctx.getPropertyAccessors().size());
|
||||
assertTrue(ctx.removePropertyAccessor(spa));
|
||||
assertFalse(ctx.removePropertyAccessor(spa));
|
||||
assertEquals(1,ctx.getPropertyAccessors().size());
|
||||
|
||||
ctx.setPropertyAccessors(copy);
|
||||
Assert.assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
@@ -54,15 +56,15 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
ctx.setRootObject(new Person("Ben"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
assertFalse(value);
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
assertTrue(value);
|
||||
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected SpelException: " + ee.getMessage());
|
||||
fail("Unexpected SpelException: " + ee.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,11 +81,11 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
ctx.setRootObject(new Person("Andy"));
|
||||
Boolean value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
assertTrue(value);
|
||||
|
||||
ctx.setRootObject(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
assertFalse(value);
|
||||
|
||||
// (2) Or register an accessor that can understand 'p' and return the right person
|
||||
expr = parser.parseRaw("p.name == principal.name");
|
||||
@@ -94,11 +96,11 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
pAccessor.setPerson(new Person("Andy"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
assertTrue(value);
|
||||
|
||||
pAccessor.setPerson(new Person("Christian"));
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,12 +117,12 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
assertTrue(value);
|
||||
|
||||
ctx.setRootObject(new Manager("Luke"));
|
||||
ctx.setVariable("a",1.043d);
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertFalse(value);
|
||||
assertFalse(value);
|
||||
}
|
||||
|
||||
// Here i'm going to change which hasRole() executes and make it one of my own Java methods
|
||||
@@ -141,7 +143,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
||||
|
||||
ctx.setVariable("a",1.0d); // referenced as #a in the expression
|
||||
value = expr.getValue(ctx,Boolean.class);
|
||||
Assert.assertTrue(value);
|
||||
assertTrue(value);
|
||||
|
||||
// ctx.setRootObject(new Manager("Luke"));
|
||||
// ctx.setVariable("a",1.043d);
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -146,8 +150,8 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
public void testAssign() throws Exception {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("publicName='Andy'");
|
||||
Assert.assertFalse(e.isWritable(eContext));
|
||||
Assert.assertEquals("Andy",e.getValue(eContext));
|
||||
assertFalse(e.isWritable(eContext));
|
||||
assertEquals("Andy",e.getValue(eContext));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -157,7 +161,7 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
public void testSetGenericMapElementRequiresCoercion() throws Exception {
|
||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Expression e = parse("mapOfStringToBoolean[42]");
|
||||
Assert.assertNull(e.getValue(eContext));
|
||||
assertNull(e.getValue(eContext));
|
||||
|
||||
// Key should be coerced to string representation of 42
|
||||
e.setValue(eContext, "true");
|
||||
@@ -165,18 +169,18 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
// All keys should be strings
|
||||
Set ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext,Set.class);
|
||||
for (Object o: ks) {
|
||||
Assert.assertEquals(String.class,o.getClass());
|
||||
assertEquals(String.class,o.getClass());
|
||||
}
|
||||
|
||||
// All values should be booleans
|
||||
Collection vs = parse("mapOfStringToBoolean.values()").getValue(eContext,Collection.class);
|
||||
for (Object o: vs) {
|
||||
Assert.assertEquals(Boolean.class,o.getClass());
|
||||
assertEquals(Boolean.class,o.getClass());
|
||||
}
|
||||
|
||||
// One final test check coercion on the key for a map lookup
|
||||
Object o = e.getValue(eContext);
|
||||
Assert.assertEquals(Boolean.TRUE,o);
|
||||
assertEquals(Boolean.TRUE,o);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,17 +195,17 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
try {
|
||||
Expression e = parser.parseExpression(expression);
|
||||
if (e == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
e.setValue(lContext, value);
|
||||
Assert.fail("expected an error");
|
||||
fail("expected an error");
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
} catch (EvaluationException ee) {
|
||||
// success!
|
||||
}
|
||||
@@ -211,21 +215,21 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
try {
|
||||
Expression e = parser.parseExpression(expression);
|
||||
if (e == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Assert.assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
e.setValue(lContext, value);
|
||||
Assert.assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
|
||||
assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,26 +241,26 @@ public class SetValueTests extends ExpressionTestCase {
|
||||
try {
|
||||
Expression e = parser.parseExpression(expression);
|
||||
if (e == null) {
|
||||
Assert.fail("Parser returned null for expression");
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
|
||||
Assert.assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
|
||||
e.setValue(lContext, value);
|
||||
Object a = expectedValue;
|
||||
Object b = e.getValue(lContext);
|
||||
if (!a.equals(b)) {
|
||||
Assert.fail("Not the same: ["+a+"] type="+a.getClass()+" ["+b+"] type="+b.getClass());
|
||||
// Assert.assertEquals("Retrieved value was not equal to set value", expectedValue, e.getValue(lContext));
|
||||
fail("Not the same: ["+a+"] type="+a.getClass()+" ["+b+"] type="+b.getClass());
|
||||
// assertEquals("Retrieved value was not equal to set value", expectedValue, e.getValue(lContext));
|
||||
}
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + ee.getMessage());
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
Assert.fail("Unexpected Exception: " + pe.getMessage());
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -24,8 +29,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -122,7 +125,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
context.setRootObject(tesla);
|
||||
|
||||
String name = (String) exp.getValue(context);
|
||||
Assert.assertEquals("Nikola Tesla",name);
|
||||
assertEquals("Nikola Tesla",name);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,7 +137,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
|
||||
boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true
|
||||
Assert.assertTrue(isEqual);
|
||||
assertTrue(isEqual);
|
||||
}
|
||||
|
||||
// Section 7.4.1
|
||||
@@ -150,29 +153,29 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
|
||||
Assert.assertEquals("Hello World",helloWorld);
|
||||
assertEquals("Hello World",helloWorld);
|
||||
|
||||
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
|
||||
Assert.assertEquals(6.0221415E+23,avogadrosNumber);
|
||||
assertEquals(6.0221415E+23, avogadrosNumber, 0);
|
||||
|
||||
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue(); // evals to 2147483647
|
||||
Assert.assertEquals(Integer.MAX_VALUE,maxValue);
|
||||
assertEquals(Integer.MAX_VALUE,maxValue);
|
||||
|
||||
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
|
||||
Assert.assertTrue(trueValue);
|
||||
assertTrue(trueValue);
|
||||
|
||||
Object nullValue = parser.parseExpression("null").getValue();
|
||||
Assert.assertNull(nullValue);
|
||||
assertNull(nullValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAccess() throws Exception {
|
||||
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
|
||||
int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
|
||||
Assert.assertEquals(1856,year);
|
||||
assertEquals(1856,year);
|
||||
|
||||
String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);
|
||||
Assert.assertEquals("SmilJan",city);
|
||||
assertEquals("SmilJan",city);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,7 +188,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// evaluates to "Induction motor"
|
||||
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
|
||||
Assert.assertEquals("Induction motor",invention);
|
||||
assertEquals("Induction motor",invention);
|
||||
|
||||
// Members List
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
@@ -195,12 +198,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// evaluates to "Nikola Tesla"
|
||||
String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Nikola Tesla",name);
|
||||
assertEquals("Nikola Tesla",name);
|
||||
|
||||
// List and Array navigation
|
||||
// evaluates to "Wireless communication"
|
||||
invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Wireless communication",invention);
|
||||
assertEquals("Wireless communication",invention);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,12 +219,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// setting values
|
||||
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
Assert.assertEquals("Nikola Tesla",i.getName());
|
||||
assertEquals("Nikola Tesla",i.getName());
|
||||
|
||||
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
|
||||
|
||||
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext,Inventor.class);
|
||||
Assert.assertEquals("Nikola Tesla",i2.getName());
|
||||
assertEquals("Nikola Tesla",i2.getName());
|
||||
|
||||
}
|
||||
|
||||
@@ -231,13 +234,13 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
public void testMethodInvocation2() throws Exception {
|
||||
// string literal, evaluates to "bc"
|
||||
String c = parser.parseExpression("'abc'.substring(1, 3)").getValue(String.class);
|
||||
Assert.assertEquals("bc",c);
|
||||
assertEquals("bc",c);
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
// evaluates to true
|
||||
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
|
||||
Assert.assertTrue(isMember);
|
||||
assertTrue(isMember);
|
||||
}
|
||||
|
||||
// 7.5.4.1
|
||||
@@ -245,29 +248,29 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testRelationalOperators() throws Exception {
|
||||
boolean result = parser.parseExpression("2 == 2").getValue(Boolean.class);
|
||||
Assert.assertTrue(result);
|
||||
assertTrue(result);
|
||||
// evaluates to false
|
||||
result = parser.parseExpression("2 < -5.0").getValue(Boolean.class);
|
||||
Assert.assertFalse(result);
|
||||
assertFalse(result);
|
||||
|
||||
// evaluates to true
|
||||
result = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);
|
||||
Assert.assertTrue(result);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOtherOperators() throws Exception {
|
||||
// evaluates to false
|
||||
boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
assertFalse(falseValue);
|
||||
|
||||
// evaluates to true
|
||||
boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
assertTrue(trueValue);
|
||||
|
||||
//evaluates to false
|
||||
falseValue = parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
assertFalse(falseValue);
|
||||
}
|
||||
|
||||
// 7.5.4.2
|
||||
@@ -282,7 +285,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// evaluates to false
|
||||
boolean falseValue = parser.parseExpression("true and false").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
assertFalse(falseValue);
|
||||
// evaluates to true
|
||||
String expression = "isMember('Nikola Tesla') and isMember('Mihajlo Pupin')";
|
||||
boolean trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
@@ -291,24 +294,24 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// evaluates to true
|
||||
trueValue = parser.parseExpression("true or false").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
assertTrue(trueValue);
|
||||
|
||||
// evaluates to true
|
||||
expression = "isMember('Nikola Tesla') or isMember('Albert Einstien')";
|
||||
trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
assertTrue(trueValue);
|
||||
|
||||
// -- NOT --
|
||||
|
||||
// evaluates to false
|
||||
falseValue = parser.parseExpression("!true").getValue(Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
assertFalse(falseValue);
|
||||
|
||||
|
||||
// -- AND and NOT --
|
||||
expression = "isMember('Nikola Tesla') and !isMember('Mihajlo Pupin')";
|
||||
falseValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
|
||||
Assert.assertFalse(falseValue);
|
||||
assertFalse(falseValue);
|
||||
}
|
||||
|
||||
// 7.5.4.3
|
||||
@@ -317,42 +320,42 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
public void testNumericalOperators() throws Exception {
|
||||
// Addition
|
||||
int two = parser.parseExpression("1 + 1").getValue(Integer.class); // 2
|
||||
Assert.assertEquals(2,two);
|
||||
assertEquals(2,two);
|
||||
|
||||
String testString = parser.parseExpression("'test' + ' ' + 'string'").getValue(String.class); // 'test string'
|
||||
Assert.assertEquals("test string",testString);
|
||||
assertEquals("test string",testString);
|
||||
|
||||
// Subtraction
|
||||
int four = parser.parseExpression("1 - -3").getValue(Integer.class); // 4
|
||||
Assert.assertEquals(4,four);
|
||||
assertEquals(4,four);
|
||||
|
||||
double d = parser.parseExpression("1000.00 - 1e4").getValue(Double.class); // -9000
|
||||
Assert.assertEquals(-9000.0d,d);
|
||||
assertEquals(-9000.0d, d, 0);
|
||||
|
||||
// Multiplication
|
||||
int six = parser.parseExpression("-2 * -3").getValue(Integer.class); // 6
|
||||
Assert.assertEquals(6,six);
|
||||
assertEquals(6,six);
|
||||
|
||||
double twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Double.class); // 24.0
|
||||
Assert.assertEquals(24.0d,twentyFour);
|
||||
assertEquals(24.0d, twentyFour, 0);
|
||||
|
||||
// Division
|
||||
int minusTwo = parser.parseExpression("6 / -3").getValue(Integer.class); // -2
|
||||
Assert.assertEquals(-2,minusTwo);
|
||||
assertEquals(-2,minusTwo);
|
||||
|
||||
double one = parser.parseExpression("8.0 / 4e0 / 2").getValue(Double.class); // 1.0
|
||||
Assert.assertEquals(1.0d,one);
|
||||
assertEquals(1.0d, one, 0);
|
||||
|
||||
// Modulus
|
||||
int three = parser.parseExpression("7 % 4").getValue(Integer.class); // 3
|
||||
Assert.assertEquals(3,three);
|
||||
assertEquals(3,three);
|
||||
|
||||
int oneInt = parser.parseExpression("8 / 5 % 2").getValue(Integer.class); // 1
|
||||
Assert.assertEquals(1,oneInt);
|
||||
assertEquals(1,oneInt);
|
||||
|
||||
// Operator precedence
|
||||
int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); // -21
|
||||
Assert.assertEquals(-21,minusTwentyOne);
|
||||
assertEquals(-21,minusTwentyOne);
|
||||
}
|
||||
|
||||
// 7.5.5
|
||||
@@ -365,12 +368,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
parser.parseExpression("foo").setValue(inventorContext, "Alexander Seovic2");
|
||||
|
||||
Assert.assertEquals("Alexander Seovic2",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
assertEquals("Alexander Seovic2",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
// alternatively
|
||||
|
||||
String aleks = parser.parseExpression("foo = 'Alexandar Seovic'").getValue(inventorContext, String.class);
|
||||
Assert.assertEquals("Alexandar Seovic",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
Assert.assertEquals("Alexandar Seovic",aleks);
|
||||
assertEquals("Alexandar Seovic",parser.parseExpression("foo").getValue(inventorContext,String.class));
|
||||
assertEquals("Alexandar Seovic",aleks);
|
||||
}
|
||||
|
||||
// 7.5.6
|
||||
@@ -378,9 +381,9 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testTypes() throws Exception {
|
||||
Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);
|
||||
Assert.assertEquals(Date.class,dateClass);
|
||||
assertEquals(Date.class,dateClass);
|
||||
boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);
|
||||
Assert.assertTrue(trueValue);
|
||||
assertTrue(trueValue);
|
||||
}
|
||||
|
||||
// 7.5.7
|
||||
@@ -391,7 +394,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
societyContext.setRootObject(new IEEE());
|
||||
Inventor einstein =
|
||||
parser.parseExpression("new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')").getValue(Inventor.class);
|
||||
Assert.assertEquals("Albert Einstein", einstein.getName());
|
||||
assertEquals("Albert Einstein", einstein.getName());
|
||||
//create new inventor instance within add method of List
|
||||
parser.parseExpression("Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))").getValue(societyContext);
|
||||
}
|
||||
@@ -408,7 +411,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
parser.parseExpression("foo = #newName").getValue(context);
|
||||
|
||||
Assert.assertEquals("Mike Tesla",tesla.getFoo());
|
||||
assertEquals("Mike Tesla",tesla.getFoo());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -425,7 +428,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
|
||||
// all prime numbers > 10 from the list (using selection ?{...})
|
||||
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
|
||||
Assert.assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
|
||||
assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
|
||||
}
|
||||
|
||||
// 7.5.9
|
||||
@@ -439,7 +442,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
"reverseString", new Class[] { String.class }));
|
||||
|
||||
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
|
||||
Assert.assertEquals("dlrow olleh",helloWorldReversed);
|
||||
assertEquals("dlrow olleh",helloWorldReversed);
|
||||
}
|
||||
|
||||
// 7.5.10
|
||||
@@ -447,7 +450,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
@Test
|
||||
public void testTernary() throws Exception {
|
||||
String falseString = parser.parseExpression("false ? 'trueExp' : 'falseExp'").getValue(String.class);
|
||||
Assert.assertEquals("falseExp",falseString);
|
||||
assertEquals("falseExp",falseString);
|
||||
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
@@ -460,7 +463,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
+ "+ Name + ' Society' : #queryName + ' is not a member of the ' + Name + ' Society'";
|
||||
|
||||
String queryResultString = parser.parseExpression(expression).getValue(societyContext, String.class);
|
||||
Assert.assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
|
||||
assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
|
||||
// queryResultString = "Nikola Tesla is a member of the IEEE Society"
|
||||
}
|
||||
|
||||
@@ -472,8 +475,8 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
StandardEvaluationContext societyContext = new StandardEvaluationContext();
|
||||
societyContext.setRootObject(new IEEE());
|
||||
List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
|
||||
Assert.assertEquals(1,list.size());
|
||||
Assert.assertEquals("Nikola Tesla",list.get(0).getName());
|
||||
assertEquals(1,list.size());
|
||||
assertEquals("Nikola Tesla",list.get(0).getName());
|
||||
}
|
||||
|
||||
// 7.5.12
|
||||
@@ -482,7 +485,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
|
||||
public void testTemplating() throws Exception {
|
||||
String randomPhrase =
|
||||
parser.parseExpression("random number is ${T(java.lang.Math).random()}", new TemplatedParserContext()).getValue(String.class);
|
||||
Assert.assertTrue(randomPhrase.startsWith("random number"));
|
||||
assertTrue(randomPhrase.startsWith("random number"));
|
||||
}
|
||||
|
||||
static class TemplatedParserContext implements ParserContext {
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
@@ -33,28 +36,27 @@ public class StandardTypeLocatorTests {
|
||||
@Test
|
||||
public void testImports() throws EvaluationException {
|
||||
StandardTypeLocator locator = new StandardTypeLocator();
|
||||
Assert.assertEquals(Integer.class,locator.findType("java.lang.Integer"));
|
||||
Assert.assertEquals(String.class,locator.findType("java.lang.String"));
|
||||
assertEquals(Integer.class,locator.findType("java.lang.Integer"));
|
||||
assertEquals(String.class,locator.findType("java.lang.String"));
|
||||
|
||||
List<String> prefixes = locator.getImportPrefixes();
|
||||
Assert.assertEquals(1,prefixes.size());
|
||||
Assert.assertTrue(prefixes.contains("java.lang"));
|
||||
Assert.assertFalse(prefixes.contains("java.util"));
|
||||
assertEquals(1,prefixes.size());
|
||||
assertTrue(prefixes.contains("java.lang"));
|
||||
assertFalse(prefixes.contains("java.util"));
|
||||
|
||||
Assert.assertEquals(Boolean.class,locator.findType("Boolean"));
|
||||
assertEquals(Boolean.class,locator.findType("Boolean"));
|
||||
// currently does not know about java.util by default
|
||||
// assertEquals(java.util.List.class,locator.findType("List"));
|
||||
|
||||
try {
|
||||
locator.findType("URL");
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (EvaluationException ee) {
|
||||
SpelEvaluationException sEx = (SpelEvaluationException)ee;
|
||||
Assert.assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
|
||||
assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
|
||||
}
|
||||
locator.registerImport("java.net");
|
||||
Assert.assertEquals(java.net.URL.class,locator.findType("URL"));
|
||||
|
||||
assertEquals(java.net.URL.class,locator.findType("URL"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
@@ -71,7 +74,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("hello ${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals("hello world", o.toString());
|
||||
assertEquals("hello world", o.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +82,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("hello ${'to'} you", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals("hello to you", o.toString());
|
||||
assertEquals("hello to you", o.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +91,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
Expression expr = parser.parseExpression("The quick ${'brown'} fox jumped over the ${'lazy'} dog",
|
||||
DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals("The quick brown fox jumped over the lazy dog", o.toString());
|
||||
assertEquals("The quick brown fox jumped over the lazy dog", o.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,19 +99,19 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Object o = expr.getValue();
|
||||
Assert.assertEquals("hello world", o.toString());
|
||||
assertEquals("hello world", o.toString());
|
||||
|
||||
expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue();
|
||||
Assert.assertEquals("", o.toString());
|
||||
assertEquals("", o.toString());
|
||||
|
||||
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue();
|
||||
Assert.assertEquals("abc", o.toString());
|
||||
assertEquals("abc", o.toString());
|
||||
|
||||
expr = parser.parseExpression("abc", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
o = expr.getValue((Object)null);
|
||||
Assert.assertEquals("abc", o.toString());
|
||||
assertEquals("abc", o.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,35 +131,35 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
checkString("hello world", ex.getValue(ctx, new Rooty()));
|
||||
checkString("hello world", ex.getValue(ctx, new Rooty(), String.class));
|
||||
checkString("hello world", ex.getValue(ctx, new Rooty(), String.class));
|
||||
Assert.assertEquals("hello ${'world'}", ex.getExpressionString());
|
||||
Assert.assertFalse(ex.isWritable(new StandardEvaluationContext()));
|
||||
Assert.assertFalse(ex.isWritable(new Rooty()));
|
||||
Assert.assertFalse(ex.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
assertEquals("hello ${'world'}", ex.getExpressionString());
|
||||
assertFalse(ex.isWritable(new StandardEvaluationContext()));
|
||||
assertFalse(ex.isWritable(new Rooty()));
|
||||
assertFalse(ex.isWritable(new StandardEvaluationContext(), new Rooty()));
|
||||
|
||||
Assert.assertEquals(String.class,ex.getValueType());
|
||||
Assert.assertEquals(String.class,ex.getValueType(ctx));
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor().getType());
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(ctx).getType());
|
||||
Assert.assertEquals(String.class,ex.getValueType(new Rooty()));
|
||||
Assert.assertEquals(String.class,ex.getValueType(ctx, new Rooty()));
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType());
|
||||
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
|
||||
assertEquals(String.class,ex.getValueType());
|
||||
assertEquals(String.class,ex.getValueType(ctx));
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor().getType());
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(ctx).getType());
|
||||
assertEquals(String.class,ex.getValueType(new Rooty()));
|
||||
assertEquals(String.class,ex.getValueType(ctx, new Rooty()));
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType());
|
||||
assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
|
||||
|
||||
try {
|
||||
ex.setValue(ctx, null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (EvaluationException ee) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
ex.setValue((Object)null, null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (EvaluationException ee) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
ex.setValue(ctx, null, null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (EvaluationException ee) {
|
||||
// success
|
||||
}
|
||||
@@ -170,34 +173,34 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
// treat the nested ${..} as a part of the expression
|
||||
Expression ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 4 world",s);
|
||||
assertEquals("hello 4 world",s);
|
||||
|
||||
// not a useful expression but tests nested expression syntax that clashes with template prefix/suffix
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.assertEquals(CompositeStringExpression.class,ex.getClass());
|
||||
assertEquals(CompositeStringExpression.class,ex.getClass());
|
||||
CompositeStringExpression cse = (CompositeStringExpression)ex;
|
||||
Expression[] exprs = cse.getExpressions();
|
||||
Assert.assertEquals(3,exprs.length);
|
||||
Assert.assertEquals("listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]",exprs[1].getExpressionString());
|
||||
assertEquals(3,exprs.length);
|
||||
assertEquals("listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]",exprs[1].getExpressionString());
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello world",s);
|
||||
assertEquals("hello world",s);
|
||||
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 4 10 world",s);
|
||||
assertEquals("hello 4 10 world",s);
|
||||
|
||||
try {
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world",pe.getMessage());
|
||||
assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world",pe.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30",pe.getMessage());
|
||||
assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30",pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,74 +210,74 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
||||
// Just wanting to use the prefix or suffix within the template:
|
||||
Expression ex = parser.parseExpression("hello ${3+4} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
String s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 7 world",s);
|
||||
assertEquals("hello 7 world",s);
|
||||
|
||||
ex = parser.parseExpression("hello ${3+4} wo${'${'}rld",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 7 wo${rld",s);
|
||||
assertEquals("hello 7 wo${rld",s);
|
||||
|
||||
ex = parser.parseExpression("hello ${3+4} wo}rld",DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
|
||||
Assert.assertEquals("hello 7 wo}rld",s);
|
||||
assertEquals("hello 7 wo}rld",s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
|
||||
Expression expr = parser.parseExpression("1+2+3");
|
||||
Assert.assertEquals(6,expr.getValue());
|
||||
assertEquals(6,expr.getValue());
|
||||
expr = parser.parseExpression("1+2+3",null);
|
||||
Assert.assertEquals(6,expr.getValue());
|
||||
assertEquals(6,expr.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorCases() throws Exception {
|
||||
try {
|
||||
parser.parseExpression("hello ${'world'", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No ending suffix '}' for expression starting at character 6: ${'world'",pe.getMessage());
|
||||
Assert.assertEquals("hello ${'world'",pe.getExpressionString());
|
||||
assertEquals("No ending suffix '}' for expression starting at character 6: ${'world'",pe.getMessage());
|
||||
assertEquals("hello ${'world'",pe.getExpressionString());
|
||||
}
|
||||
try {
|
||||
parser.parseExpression("hello ${'wibble'${'world'}", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No ending suffix '}' for expression starting at character 6: ${'wibble'${'world'}",pe.getMessage());
|
||||
assertEquals("No ending suffix '}' for expression starting at character 6: ${'wibble'${'world'}",pe.getMessage());
|
||||
}
|
||||
try {
|
||||
parser.parseExpression("hello ${} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
|
||||
Assert.fail("Should have failed");
|
||||
fail("Should have failed");
|
||||
} catch (ParseException pe) {
|
||||
Assert.assertEquals("No expression defined within delimiter '${}' at character 6",pe.getMessage());
|
||||
assertEquals("No expression defined within delimiter '${}' at character 6",pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateParserContext() {
|
||||
TemplateParserContext tpc = new TemplateParserContext("abc","def");
|
||||
Assert.assertEquals("abc", tpc.getExpressionPrefix());
|
||||
Assert.assertEquals("def", tpc.getExpressionSuffix());
|
||||
Assert.assertTrue(tpc.isTemplate());
|
||||
assertEquals("abc", tpc.getExpressionPrefix());
|
||||
assertEquals("def", tpc.getExpressionSuffix());
|
||||
assertTrue(tpc.isTemplate());
|
||||
|
||||
tpc = new TemplateParserContext();
|
||||
Assert.assertEquals("#{", tpc.getExpressionPrefix());
|
||||
Assert.assertEquals("}", tpc.getExpressionSuffix());
|
||||
Assert.assertTrue(tpc.isTemplate());
|
||||
assertEquals("#{", tpc.getExpressionPrefix());
|
||||
assertEquals("}", tpc.getExpressionSuffix());
|
||||
assertTrue(tpc.isTemplate());
|
||||
|
||||
ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
|
||||
Assert.assertEquals("#{", pc.getExpressionPrefix());
|
||||
Assert.assertEquals("}", pc.getExpressionSuffix());
|
||||
Assert.assertTrue(pc.isTemplate());
|
||||
assertEquals("#{", pc.getExpressionPrefix());
|
||||
assertEquals("}", pc.getExpressionSuffix());
|
||||
assertTrue(pc.isTemplate());
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
private void checkString(String expectedString, Object value) {
|
||||
if (!(value instanceof String)) {
|
||||
Assert.fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");
|
||||
fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");
|
||||
}
|
||||
if (!value.equals(expectedString)) {
|
||||
Assert.fail("Did not get expected result. Should have been '" + expectedString + "' but was '" + value + "'");
|
||||
fail("Did not get expected result. Should have been '" + expectedString + "' but was '" + value + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -77,11 +77,11 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
Object v = parser.parseRaw("#notStatic()").getValue(ctx);
|
||||
Assert.fail("Should have failed with exception - cannot call non static method that way");
|
||||
fail("Should have failed with exception - cannot call non static method that way");
|
||||
} catch (SpelEvaluationException se) {
|
||||
if (se.getMessageCode() != SpelMessage.FUNCTION_MUST_BE_STATIC) {
|
||||
se.printStackTrace();
|
||||
Assert.fail("Should have failed a message about the function needing to be static, not: "
|
||||
fail("Should have failed a message about the function needing to be static, not: "
|
||||
+ se.getMessageCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,20 @@
|
||||
|
||||
package org.springframework.expression.spel.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.ParseException;
|
||||
@@ -47,19 +52,19 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
|
||||
@Test
|
||||
public void testFormatHelperForClassName() {
|
||||
Assert.assertEquals("java.lang.String",FormatHelper.formatClassNameForMessage(String.class));
|
||||
Assert.assertEquals("java.lang.String[]",FormatHelper.formatClassNameForMessage(new String[1].getClass()));
|
||||
Assert.assertEquals("int[]",FormatHelper.formatClassNameForMessage(new int[1].getClass()));
|
||||
Assert.assertEquals("int[][]",FormatHelper.formatClassNameForMessage(new int[1][2].getClass()));
|
||||
Assert.assertEquals("null",FormatHelper.formatClassNameForMessage(null));
|
||||
assertEquals("java.lang.String",FormatHelper.formatClassNameForMessage(String.class));
|
||||
assertEquals("java.lang.String[]",FormatHelper.formatClassNameForMessage(new String[1].getClass()));
|
||||
assertEquals("int[]",FormatHelper.formatClassNameForMessage(new int[1].getClass()));
|
||||
assertEquals("int[][]",FormatHelper.formatClassNameForMessage(new int[1][2].getClass()));
|
||||
assertEquals("null",FormatHelper.formatClassNameForMessage(null));
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testFormatHelperForMethod() {
|
||||
Assert.assertEquals("foo(java.lang.String)",FormatHelper.formatMethodForMessage("foo", String.class));
|
||||
Assert.assertEquals("goo(java.lang.String,int[])",FormatHelper.formatMethodForMessage("goo", String.class,new int[1].getClass()));
|
||||
Assert.assertEquals("boo()",FormatHelper.formatMethodForMessage("boo"));
|
||||
assertEquals("foo(java.lang.String)",FormatHelper.formatMethodForMessage("foo", String.class));
|
||||
assertEquals("goo(java.lang.String,int[])",FormatHelper.formatMethodForMessage("goo", String.class,new int[1].getClass()));
|
||||
assertEquals("boo()",FormatHelper.formatMethodForMessage("boo"));
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -90,15 +95,15 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
// CompoundExpression value:2
|
||||
// IntLiteral value:2
|
||||
// ===> Expression '3+4+5+6+7-2' - AST end
|
||||
Assert.assertTrue(s.indexOf("===> Expression '3+4+5+6+7-2' - AST start")!=-1);
|
||||
Assert.assertTrue(s.indexOf(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
|
||||
assertTrue(s.indexOf("===> Expression '3+4+5+6+7-2' - AST start")!=-1);
|
||||
assertTrue(s.indexOf(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedValue() {
|
||||
TypedValue tValue = new TypedValue("hello");
|
||||
Assert.assertEquals(String.class,tValue.getTypeDescriptor().getType());
|
||||
Assert.assertEquals("TypedValue: 'hello' of [java.lang.String]",tValue.toString());
|
||||
assertEquals(String.class,tValue.getTypeDescriptor().getType());
|
||||
assertEquals("TypedValue: 'hello' of [java.lang.String]",tValue.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,10 +261,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
args = new Object[]{3,false,3.0f};
|
||||
try {
|
||||
ReflectionHelper.convertAllArguments(null, args, twoArg);
|
||||
Assert.fail("Should have failed because no converter supplied");
|
||||
fail("Should have failed because no converter supplied");
|
||||
}
|
||||
catch (SpelEvaluationException se) {
|
||||
Assert.assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,se.getMessageCode());
|
||||
assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,se.getMessageCode());
|
||||
}
|
||||
|
||||
// null value
|
||||
@@ -272,14 +277,14 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
public void testSetupArguments() {
|
||||
Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(new Class[]{new String[0].getClass()},"a","b","c");
|
||||
|
||||
Assert.assertEquals(1,newArray.length);
|
||||
assertEquals(1,newArray.length);
|
||||
Object firstParam = newArray[0];
|
||||
Assert.assertEquals(String.class,firstParam.getClass().getComponentType());
|
||||
assertEquals(String.class,firstParam.getClass().getComponentType());
|
||||
Object[] firstParamArray = (Object[])firstParam;
|
||||
Assert.assertEquals(3,firstParamArray.length);
|
||||
Assert.assertEquals("a",firstParamArray[0]);
|
||||
Assert.assertEquals("b",firstParamArray[1]);
|
||||
Assert.assertEquals("c",firstParamArray[2]);
|
||||
assertEquals(3,firstParamArray.length);
|
||||
assertEquals("a",firstParamArray[0]);
|
||||
assertEquals("b",firstParamArray[1]);
|
||||
assertEquals("c",firstParamArray[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,19 +293,19 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Tester t = new Tester();
|
||||
t.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(t);
|
||||
Assert.assertTrue(rpr.canRead(ctx, t, "property"));
|
||||
Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue());
|
||||
Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
assertTrue(rpr.canRead(ctx, t, "property"));
|
||||
assertEquals("hello",rpr.read(ctx, t, "property").getValue());
|
||||
assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
|
||||
Assert.assertTrue(rpr.canRead(ctx, t, "field"));
|
||||
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue());
|
||||
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
assertTrue(rpr.canRead(ctx, t, "field"));
|
||||
assertEquals(3,rpr.read(ctx, t, "field").getValue());
|
||||
assertEquals(3,rpr.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
|
||||
Assert.assertTrue(rpr.canWrite(ctx, t, "property"));
|
||||
assertTrue(rpr.canWrite(ctx, t, "property"));
|
||||
rpr.write(ctx, t, "property","goodbye");
|
||||
rpr.write(ctx, t, "property","goodbye"); // cached accessor used
|
||||
|
||||
Assert.assertTrue(rpr.canWrite(ctx, t, "field"));
|
||||
assertTrue(rpr.canWrite(ctx, t, "field"));
|
||||
rpr.write(ctx, t, "field",12);
|
||||
rpr.write(ctx, t, "field",12);
|
||||
|
||||
@@ -308,27 +313,31 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
// of populating type descriptor cache
|
||||
rpr.write(ctx,t,"field2",3);
|
||||
rpr.write(ctx, t, "property2","doodoo");
|
||||
Assert.assertEquals(3,rpr.read(ctx,t,"field2").getValue());
|
||||
assertEquals(3,rpr.read(ctx,t,"field2").getValue());
|
||||
|
||||
// Attempted read as first activity on this field and property (no canRead before them)
|
||||
Assert.assertEquals(0,rpr.read(ctx,t,"field3").getValue());
|
||||
Assert.assertEquals("doodoo",rpr.read(ctx,t,"property3").getValue());
|
||||
assertEquals(0,rpr.read(ctx,t,"field3").getValue());
|
||||
assertEquals("doodoo",rpr.read(ctx,t,"property3").getValue());
|
||||
|
||||
// Access through is method
|
||||
// Assert.assertEquals(0,rpr.read(ctx,t,"field3").getValue());
|
||||
Assert.assertEquals(false,rpr.read(ctx,t,"property4").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"property4"));
|
||||
// assertEquals(0,rpr.read(ctx,t,"field3").getValue());
|
||||
assertEquals(false,rpr.read(ctx,t,"property4").getValue());
|
||||
assertTrue(rpr.canRead(ctx,t,"property4"));
|
||||
|
||||
// repro SPR-9123, ReflectivePropertyAccessor JavaBean property names compliance tests
|
||||
Assert.assertEquals("iD",rpr.read(ctx,t,"iD").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"iD"));
|
||||
Assert.assertEquals("id",rpr.read(ctx,t,"id").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"id"));
|
||||
Assert.assertEquals("ID",rpr.read(ctx,t,"ID").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"ID"));
|
||||
assertEquals("iD",rpr.read(ctx,t,"iD").getValue());
|
||||
assertTrue(rpr.canRead(ctx,t,"iD"));
|
||||
assertEquals("id",rpr.read(ctx,t,"id").getValue());
|
||||
assertTrue(rpr.canRead(ctx,t,"id"));
|
||||
assertEquals("ID",rpr.read(ctx,t,"ID").getValue());
|
||||
assertTrue(rpr.canRead(ctx,t,"ID"));
|
||||
// note: "Id" is not a valid JavaBean name, nevertheless it is treated as "id"
|
||||
Assert.assertEquals("id",rpr.read(ctx,t,"Id").getValue());
|
||||
Assert.assertTrue(rpr.canRead(ctx,t,"Id"));
|
||||
assertEquals("id",rpr.read(ctx,t,"Id").getValue());
|
||||
assertTrue(rpr.canRead(ctx,t,"Id"));
|
||||
|
||||
// SPR-10122, ReflectivePropertyAccessor JavaBean property names compliance tests - setters
|
||||
rpr.write(ctx, t, "pEBS","Test String");
|
||||
assertEquals("Test String",rpr.read(ctx,t,"pEBS").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -337,68 +346,68 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
Tester t = new Tester();
|
||||
t.setProperty("hello");
|
||||
EvaluationContext ctx = new StandardEvaluationContext(t);
|
||||
// Assert.assertTrue(rpr.canRead(ctx, t, "property"));
|
||||
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue());
|
||||
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
// assertTrue(rpr.canRead(ctx, t, "property"));
|
||||
// assertEquals("hello",rpr.read(ctx, t, "property").getValue());
|
||||
// assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
|
||||
PropertyAccessor optA = rpr.createOptimalAccessor(ctx, t, "property");
|
||||
Assert.assertTrue(optA.canRead(ctx, t, "property"));
|
||||
Assert.assertFalse(optA.canRead(ctx, t, "property2"));
|
||||
assertTrue(optA.canRead(ctx, t, "property"));
|
||||
assertFalse(optA.canRead(ctx, t, "property2"));
|
||||
try {
|
||||
optA.canWrite(ctx, t, "property");
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
optA.canWrite(ctx, t, "property2");
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
Assert.assertEquals("hello",optA.read(ctx, t, "property").getValue());
|
||||
Assert.assertEquals("hello",optA.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
assertEquals("hello",optA.read(ctx, t, "property").getValue());
|
||||
assertEquals("hello",optA.read(ctx, t, "property").getValue()); // cached accessor used
|
||||
|
||||
try {
|
||||
optA.getSpecificTargetClasses();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
optA.write(ctx,t,"property",null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
|
||||
optA = rpr.createOptimalAccessor(ctx, t, "field");
|
||||
Assert.assertTrue(optA.canRead(ctx, t, "field"));
|
||||
Assert.assertFalse(optA.canRead(ctx, t, "field2"));
|
||||
assertTrue(optA.canRead(ctx, t, "field"));
|
||||
assertFalse(optA.canRead(ctx, t, "field2"));
|
||||
try {
|
||||
optA.canWrite(ctx, t, "field");
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
optA.canWrite(ctx, t, "field2");
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
Assert.assertEquals(3,optA.read(ctx, t, "field").getValue());
|
||||
Assert.assertEquals(3,optA.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
assertEquals(3,optA.read(ctx, t, "field").getValue());
|
||||
assertEquals(3,optA.read(ctx, t, "field").getValue()); // cached accessor used
|
||||
|
||||
try {
|
||||
optA.getSpecificTargetClasses();
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
try {
|
||||
optA.write(ctx,t,"field",null);
|
||||
Assert.fail();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
// success
|
||||
}
|
||||
@@ -419,6 +428,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
String iD = "iD";
|
||||
String id = "id";
|
||||
String ID = "ID";
|
||||
String pEBS = "pEBS";
|
||||
|
||||
public String getProperty() { return property; }
|
||||
public void setProperty(String value) { property = value; }
|
||||
@@ -434,6 +444,14 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
public String getId() { return id; }
|
||||
|
||||
public String getID() { return ID; }
|
||||
|
||||
public String getpEBS() {
|
||||
return pEBS;
|
||||
}
|
||||
|
||||
public void setpEBS(String pEBS) {
|
||||
this.pEBS = pEBS;
|
||||
}
|
||||
}
|
||||
|
||||
static class Super {
|
||||
@@ -452,25 +470,25 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
private void checkMatch(Class[] inputTypes, Class[] expectedTypes, StandardTypeConverter typeConverter,ArgsMatchKind expectedMatchKind,int... argsForConversion) {
|
||||
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArguments(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
|
||||
if (expectedMatchKind==null) {
|
||||
Assert.assertNull("Did not expect them to match in any way", matchInfo);
|
||||
assertNull("Did not expect them to match in any way", matchInfo);
|
||||
} else {
|
||||
Assert.assertNotNull("Should not be a null match", matchInfo);
|
||||
assertNotNull("Should not be a null match", matchInfo);
|
||||
}
|
||||
|
||||
if (expectedMatchKind==ArgsMatchKind.EXACT) {
|
||||
Assert.assertTrue(matchInfo.isExactMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
assertTrue(matchInfo.isExactMatch());
|
||||
assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
|
||||
Assert.assertTrue(matchInfo.isCloseMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
assertTrue(matchInfo.isCloseMatch());
|
||||
assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
|
||||
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
if (argsForConversion==null) {
|
||||
Assert.fail("there are arguments that need conversion");
|
||||
fail("there are arguments that need conversion");
|
||||
}
|
||||
Assert.assertEquals("The array of args that need conversion is different length to that expected",argsForConversion.length, matchInfo.argsRequiringConversion.length);
|
||||
assertEquals("The array of args that need conversion is different length to that expected",argsForConversion.length, matchInfo.argsRequiringConversion.length);
|
||||
for (int a=0;a<argsForConversion.length;a++) {
|
||||
Assert.assertEquals(argsForConversion[a],matchInfo.argsRequiringConversion[a]);
|
||||
assertEquals(argsForConversion[a],matchInfo.argsRequiringConversion[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,38 +499,38 @@ public class ReflectionHelperTests extends ExpressionTestCase {
|
||||
private void checkMatch2(Class[] inputTypes, Class[] expectedTypes, StandardTypeConverter typeConverter,ArgsMatchKind expectedMatchKind,int... argsForConversion) {
|
||||
ReflectionHelper.ArgumentsMatchInfo matchInfo = ReflectionHelper.compareArgumentsVarargs(getTypeDescriptors(expectedTypes), getTypeDescriptors(inputTypes), typeConverter);
|
||||
if (expectedMatchKind==null) {
|
||||
Assert.assertNull("Did not expect them to match in any way: "+matchInfo, matchInfo);
|
||||
assertNull("Did not expect them to match in any way: "+matchInfo, matchInfo);
|
||||
} else {
|
||||
Assert.assertNotNull("Should not be a null match", matchInfo);
|
||||
assertNotNull("Should not be a null match", matchInfo);
|
||||
}
|
||||
|
||||
if (expectedMatchKind==ArgsMatchKind.EXACT) {
|
||||
Assert.assertTrue(matchInfo.isExactMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
assertTrue(matchInfo.isExactMatch());
|
||||
assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
|
||||
Assert.assertTrue(matchInfo.isCloseMatch());
|
||||
Assert.assertNull(matchInfo.argsRequiringConversion);
|
||||
assertTrue(matchInfo.isCloseMatch());
|
||||
assertNull(matchInfo.argsRequiringConversion);
|
||||
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
|
||||
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
|
||||
if (argsForConversion==null) {
|
||||
Assert.fail("there are arguments that need conversion");
|
||||
fail("there are arguments that need conversion");
|
||||
}
|
||||
Assert.assertEquals("The array of args that need conversion is different length to that expected",argsForConversion.length, matchInfo.argsRequiringConversion.length);
|
||||
assertEquals("The array of args that need conversion is different length to that expected",argsForConversion.length, matchInfo.argsRequiringConversion.length);
|
||||
for (int a=0;a<argsForConversion.length;a++) {
|
||||
Assert.assertEquals(argsForConversion[a],matchInfo.argsRequiringConversion[a]);
|
||||
assertEquals(argsForConversion[a],matchInfo.argsRequiringConversion[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkArguments(Object[] args, Object... expected) {
|
||||
Assert.assertEquals(expected.length,args.length);
|
||||
assertEquals(expected.length,args.length);
|
||||
for (int i=0;i<expected.length;i++) {
|
||||
checkArgument(expected[i],args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkArgument(Object expected, Object actual) {
|
||||
Assert.assertEquals(expected,actual);
|
||||
assertEquals(expected,actual);
|
||||
}
|
||||
|
||||
private List<TypeDescriptor> getTypeDescriptors(Class... types) {
|
||||
|
||||
Reference in New Issue
Block a user