polish
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.el.BeanELResolver;
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.FunctionMapper;
|
||||
import javax.el.VariableMapper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
import org.springframework.binding.expression.el.DelegatingELContext;
|
||||
import org.springframework.binding.expression.el.ELContextFactory;
|
||||
import org.springframework.binding.expression.el.JBossELExpressionParser;
|
||||
import org.springframework.binding.expression.support.TestBean;
|
||||
|
||||
/**
|
||||
* Tests to verify the delegation behavior of ELContextImpl.
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
*
|
||||
*/
|
||||
public class ELContextDelegationTests extends TestCase {
|
||||
|
||||
private ELContext mockContext = new MockELContext();
|
||||
private ExpressionParser expressionParser = new DelegatingELExpressionParser();
|
||||
private TestBean bean;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
bean = new TestBean();
|
||||
bean.setFlag(true);
|
||||
}
|
||||
|
||||
public final void testGetValueByContextDelegation() {
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression("#{bean.flag}").evaluate(bean, null));
|
||||
assertEquals(Boolean.TRUE, expressionParser.parseExpression("#{bean.flag}").evaluate(null, null));
|
||||
}
|
||||
|
||||
private class DelegatingELExpressionParser extends JBossELExpressionParser {
|
||||
|
||||
protected ELContextFactory getELContextFactory() {
|
||||
ELContextFactory stubFactory = new ELContextFactory() {
|
||||
|
||||
public ELContext getELContext(Object target) {
|
||||
DelegatingELContext ctx = new DelegatingELContext();
|
||||
ctx.addDelegate(mockContext);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
};
|
||||
return stubFactory;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockELContext extends ELContext {
|
||||
|
||||
ELResolver resolver = new MockELResolver();
|
||||
|
||||
public ELResolver getELResolver() {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
public FunctionMapper getFunctionMapper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public VariableMapper getVariableMapper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MockELResolver extends ELResolver {
|
||||
|
||||
public Class getCommonPropertyType(ELContext context, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getFeatureDescriptors(ELContext context, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) {
|
||||
if (base != null)
|
||||
return base.getClass();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context, Object base, Object property) {
|
||||
if (base == null && "bean".equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return bean;
|
||||
}
|
||||
if (base == bean) {
|
||||
return new BeanELResolver().getValue(context, base, property);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext context, Object base, Object property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setValue(ELContext context, Object base, Object property, Object value) {
|
||||
if (base == null && "bean".equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
} else if (base == bean) {
|
||||
new BeanELResolver().setValue(context, base, property, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.binding.expression.el.JBossELExpressionParser;
|
||||
import org.springframework.binding.expression.support.TestBean;
|
||||
import org.springframework.binding.expression.support.TestMethods;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests to exercise the extended method invoking expression extensions of JBoss-el.
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
*
|
||||
*/
|
||||
public class ELMethodExpressionTests extends TestCase {
|
||||
|
||||
JBossELExpressionParser parser = new JBossELExpressionParser();
|
||||
|
||||
Map context;
|
||||
|
||||
Map container;
|
||||
|
||||
TestMethods target;
|
||||
MockControl targetMockControl;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
context = new HashMap();
|
||||
container = new HashMap();
|
||||
targetMockControl = MockControl.createControl(TestMethods.class);
|
||||
target = (TestMethods) targetMockControl.getMock();
|
||||
context.put("container", container);
|
||||
container.put("myObject", target);
|
||||
}
|
||||
|
||||
public void testWithIntParam() {
|
||||
String expression = "#{container.myObject.doSomethingWithInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
target.doSomethingWithInt(param);
|
||||
targetMockControl.replay();
|
||||
|
||||
parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
|
||||
}
|
||||
|
||||
public void testReturnWithIntParam() {
|
||||
String expected = "sucess";
|
||||
String expression = "#{container.myObject.returnStringFromInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
targetMockControl.expectAndReturn(target.returnStringFromInt(param), expected);
|
||||
targetMockControl.replay();
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
public void testReturnWithIntAndObject() {
|
||||
String expected = "success";
|
||||
String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}";
|
||||
int param1 = 5;
|
||||
container.put("param1", new Integer(param1));
|
||||
TestBean param2 = new TestBean();
|
||||
container.put("param2", param2);
|
||||
targetMockControl.expectAndReturn(target.returnStringFromIntAndObject(param1, param2), expected);
|
||||
targetMockControl.replay();
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.el.JBossELExpressionParser;
|
||||
|
||||
public class ELMethodParsingTests extends TestCase {
|
||||
|
||||
JBossELExpressionParser parser;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
parser = new JBossELExpressionParser();
|
||||
}
|
||||
|
||||
public void testEmptyMethod() {
|
||||
|
||||
String expStr1 = "#{foo.bar()}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar()";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
public void testMethodWithParams() {
|
||||
|
||||
String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar(moe.curly, groucho.harpo)";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
import org.springframework.binding.expression.support.TestBean;
|
||||
import org.springframework.binding.expression.support.TestMethods;
|
||||
|
||||
/**
|
||||
* Tests to exercise the extended method invoking expression extensions of JBoss-el.
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class JBossELExpressionParserTests extends TestCase {
|
||||
|
||||
JBossELExpressionParser parser = new JBossELExpressionParser();
|
||||
|
||||
Map context;
|
||||
|
||||
Map container;
|
||||
|
||||
TestMethods target;
|
||||
MockControl targetMockControl;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
context = new HashMap();
|
||||
container = new HashMap();
|
||||
targetMockControl = MockControl.createControl(TestMethods.class);
|
||||
target = (TestMethods) targetMockControl.getMock();
|
||||
context.put("container", container);
|
||||
container.put("myObject", target);
|
||||
}
|
||||
|
||||
public void testWithIntParam() {
|
||||
String expression = "#{container.myObject.doSomethingWithInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
target.doSomethingWithInt(param);
|
||||
targetMockControl.replay();
|
||||
|
||||
parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
|
||||
}
|
||||
|
||||
public void testReturnWithIntParam() {
|
||||
String expected = "sucess";
|
||||
String expression = "#{container.myObject.returnStringFromInt(container.param1)}";
|
||||
int param = 5;
|
||||
container.put("param1", new Integer(param));
|
||||
targetMockControl.expectAndReturn(target.returnStringFromInt(param), expected);
|
||||
targetMockControl.replay();
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
public void testReturnWithIntAndObject() {
|
||||
String expected = "success";
|
||||
String expression = "#{container.myObject.returnStringFromIntAndObject(container.param1, container.param2)}";
|
||||
int param1 = 5;
|
||||
container.put("param1", new Integer(param1));
|
||||
TestBean param2 = new TestBean();
|
||||
container.put("param2", param2);
|
||||
targetMockControl.expectAndReturn(target.returnStringFromIntAndObject(param1, param2), expected);
|
||||
targetMockControl.replay();
|
||||
|
||||
String result = (String) parser.parseExpression(expression).evaluate(context, null);
|
||||
targetMockControl.verify();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
public void testEmptyMethod() {
|
||||
|
||||
String expStr1 = "#{foo.bar()}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar()";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
public void testMethodWithParams() {
|
||||
|
||||
String expStr1 = "#{foo.bar(moe.curly, groucho.harpo)}";
|
||||
Expression result1 = parser.parseExpression(expStr1);
|
||||
assertNotNull(result1);
|
||||
assertEquals(expStr1, result1.toString());
|
||||
|
||||
String expStr2 = "foo.bar(moe.curly, groucho.harpo)";
|
||||
Expression result2 = parser.parseExpression(expStr2);
|
||||
assertNotNull(result2);
|
||||
assertEquals(expStr1, result2.toString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user