set value tests
This commit is contained in:
parent
c178888efd
commit
8d63a34652
|
|
@ -45,6 +45,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
|||
public void testRelOperatorGE02() {
|
||||
evaluate("3 >= 3", "true", Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
// public void testRelOperatorsIn01() {
|
||||
// evaluate("3 in {1,2,3,4,5}", "true", Boolean.class);
|
||||
|
|
@ -137,7 +138,7 @@ public class EvaluationTests extends ExpressionTestCase {
|
|||
public void testPropertiesNested02() {
|
||||
evaluate("placeOfBirth.doubleIt(12)", "24", Integer.class);
|
||||
}
|
||||
|
||||
|
||||
// methods
|
||||
public void testMethods01() {
|
||||
evaluate("echo(12)", "12", String.class);
|
||||
|
|
@ -454,4 +455,5 @@ public class EvaluationTests extends ExpressionTestCase {
|
|||
evaluateAndAskForReturnType("3*4+5", "17", String.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ public abstract class ExpressionTestCase extends TestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce a nice string representation of the input object.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ParseException;
|
||||
|
||||
/**
|
||||
* Tests set value expressions.
|
||||
*
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class SetValueTests extends ExpressionTestCase {
|
||||
|
||||
private final static boolean DEBUG = false;
|
||||
|
||||
public void testSetProperty() {
|
||||
setValue("wonNobelPrize", true);
|
||||
}
|
||||
|
||||
public void testSetNestedProperty() {
|
||||
setValue("placeOfBirth.city", "Wien");
|
||||
}
|
||||
|
||||
//public void testSetPropertyTypeCoersion() {
|
||||
// setValue("wonNobelPrize", "true");
|
||||
//}
|
||||
|
||||
//public void testSetArrayElementValue() {
|
||||
// setValue("inventions[0]", "Just the telephone");
|
||||
//}
|
||||
|
||||
public void testSetArrayElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
}
|
||||
|
||||
//public void testSetListElementValue() {
|
||||
// setValue("placesLivedList[0]", new PlaceOfBirth("Wien"));
|
||||
//}
|
||||
|
||||
//public void testSetGenericListElementValueTypeCoersion() {
|
||||
// setValue("placesLivedList[0]", "Wien");
|
||||
//}
|
||||
|
||||
public void testSetListElementNestedValue() {
|
||||
setValue("placesLived[0].city", "Wien");
|
||||
}
|
||||
|
||||
protected void setValue(String expression, Object value) {
|
||||
try {
|
||||
Expression e = parser.parseExpression(expression);
|
||||
if (e == null) {
|
||||
fail("Parser returned null for expression");
|
||||
}
|
||||
if (DEBUG) {
|
||||
SpelUtilities.printAbstractSyntaxTree(System.out, e);
|
||||
}
|
||||
assertTrue("Expression is not writeable but should be", e.isWritable(eContext));
|
||||
e.setValue(eContext, value);
|
||||
assertEquals("Retrieved value was not equal to set value", value, e.getValue(eContext));
|
||||
} catch (EvaluationException ee) {
|
||||
ee.printStackTrace();
|
||||
fail("Unexpected Exception: " + ee.getMessage());
|
||||
} catch (ParseException pe) {
|
||||
pe.printStackTrace();
|
||||
fail("Unexpected Exception: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package org.springframework.expression.spel.testresources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
@ -14,7 +16,10 @@ public class Inventor {
|
|||
private String[] inventions;
|
||||
public String randomField;
|
||||
public Map testMap;
|
||||
|
||||
private boolean wonNobelPrize;
|
||||
private PlaceOfBirth[] placesLived;
|
||||
private List<PlaceOfBirth> placesLivedList = new ArrayList<PlaceOfBirth>();
|
||||
|
||||
public Inventor(String name, Date birthdate, String nationality) {
|
||||
this.name = name;
|
||||
this.birthdate = birthdate;
|
||||
|
|
@ -31,8 +36,14 @@ public class Inventor {
|
|||
|
||||
public void setPlaceOfBirth(PlaceOfBirth placeOfBirth2) {
|
||||
placeOfBirth = placeOfBirth2;
|
||||
this.placesLived = new PlaceOfBirth[] { placeOfBirth2 };
|
||||
this.placesLivedList.add(placeOfBirth2);
|
||||
}
|
||||
|
||||
public String[] getInventions() {
|
||||
return inventions;
|
||||
}
|
||||
|
||||
public void setInventions(String[] inventions) {
|
||||
this.inventions = inventions;
|
||||
}
|
||||
|
|
@ -44,6 +55,30 @@ public class Inventor {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean getWonNobelPrize() {
|
||||
return wonNobelPrize;
|
||||
}
|
||||
|
||||
public void setWonNobelPrize(boolean wonNobelPrize) {
|
||||
this.wonNobelPrize = wonNobelPrize;
|
||||
}
|
||||
|
||||
public PlaceOfBirth[] getPlacesLived() {
|
||||
return placesLived;
|
||||
}
|
||||
|
||||
public void setPlacesLived(PlaceOfBirth[] placesLived) {
|
||||
this.placesLived = placesLived;
|
||||
}
|
||||
|
||||
public List<PlaceOfBirth> getPlacesLivedList() {
|
||||
return placesLivedList;
|
||||
}
|
||||
|
||||
public void setPlacesLivedList(List<PlaceOfBirth> placesLivedList) {
|
||||
this.placesLivedList = placesLivedList;
|
||||
}
|
||||
|
||||
public String echo(Object o) {
|
||||
return o.toString();
|
||||
|
|
|
|||
Loading…
Reference in New Issue