init
This commit is contained in:
264
test/org/apache/el/TestELEvaluation.java
Normal file
264
test/org/apache/el/TestELEvaluation.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.el.ELException;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.el.lang.ELSupport;
|
||||
import org.apache.jasper.el.ELContextImpl;
|
||||
|
||||
/**
|
||||
* Tests the EL engine directly. Similar tests may be found in
|
||||
* {@link org.apache.jasper.compiler.TestAttributeParser} and
|
||||
* {@link TestELInJsp}.
|
||||
*/
|
||||
public class TestELEvaluation {
|
||||
|
||||
/**
|
||||
* Test use of spaces in ternary expressions. This was primarily an EL
|
||||
* parser bug.
|
||||
*/
|
||||
@Test
|
||||
public void testBug42565() {
|
||||
Assert.assertEquals("false", evaluateExpression("${false?true:false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false?true: false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false?true :false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false?true : false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false? true:false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false? true: false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false? true :false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false? true : false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ?true:false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ?true: false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ?true :false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ?true : false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ? true:false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ? true: false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ? true :false}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${false ? true : false}"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test use nested ternary expressions. This was primarily an EL parser bug.
|
||||
*/
|
||||
@Test
|
||||
public void testBug44994() {
|
||||
Assert.assertEquals("none", evaluateExpression(
|
||||
"${0 lt 0 ? 1 lt 0 ? 'many': 'one': 'none'}"));
|
||||
Assert.assertEquals("one", evaluateExpression(
|
||||
"${0 lt 1 ? 1 lt 1 ? 'many': 'one': 'none'}"));
|
||||
Assert.assertEquals("many", evaluateExpression(
|
||||
"${0 lt 2 ? 1 lt 2 ? 'many': 'one': 'none'}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParserBug45511() {
|
||||
// Test cases provided by OP
|
||||
Assert.assertEquals("true", evaluateExpression("${empty ('')}"));
|
||||
Assert.assertEquals("true", evaluateExpression("${empty('')}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${(true) and (false)}"));
|
||||
Assert.assertEquals("false", evaluateExpression("${(true)and(false)}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug48112() {
|
||||
// bug 48112
|
||||
Assert.assertEquals("{world}", evaluateExpression("${fn:trim('{world}')}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParserLiteralExpression() {
|
||||
// Inspired by work on bug 45451, comments from kkolinko on the dev
|
||||
// list and looking at the spec to find some edge cases
|
||||
|
||||
// '\' is only an escape character inside a StringLiteral
|
||||
Assert.assertEquals("\\\\", evaluateExpression("\\\\"));
|
||||
|
||||
/*
|
||||
* LiteralExpressions can only contain ${ or #{ if escaped with \
|
||||
* \ is not an escape character in any other circumstances including \\
|
||||
*/
|
||||
Assert.assertEquals("\\", evaluateExpression("\\"));
|
||||
Assert.assertEquals("$", evaluateExpression("$"));
|
||||
Assert.assertEquals("#", evaluateExpression("#"));
|
||||
Assert.assertEquals("\\$", evaluateExpression("\\$"));
|
||||
Assert.assertEquals("\\#", evaluateExpression("\\#"));
|
||||
Assert.assertEquals("\\\\$", evaluateExpression("\\\\$"));
|
||||
Assert.assertEquals("\\\\#", evaluateExpression("\\\\#"));
|
||||
Assert.assertEquals("${", evaluateExpression("\\${"));
|
||||
Assert.assertEquals("#{", evaluateExpression("\\#{"));
|
||||
Assert.assertEquals("\\${", evaluateExpression("\\\\${"));
|
||||
Assert.assertEquals("\\#{", evaluateExpression("\\\\#{"));
|
||||
|
||||
// '\' is only an escape for '${' and '#{'.
|
||||
Assert.assertEquals("\\$", evaluateExpression("\\$"));
|
||||
Assert.assertEquals("${", evaluateExpression("\\${"));
|
||||
Assert.assertEquals("\\$a", evaluateExpression("\\$a"));
|
||||
Assert.assertEquals("\\a", evaluateExpression("\\a"));
|
||||
Assert.assertEquals("\\\\", evaluateExpression("\\\\"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParserStringLiteral() {
|
||||
// Inspired by work on bug 45451, comments from kkolinko on the dev
|
||||
// list and looking at the spec to find some edge cases
|
||||
|
||||
// The only characters that can be escaped inside a String literal
|
||||
// are \ " and '. # and $ are not escaped inside a String literal.
|
||||
Assert.assertEquals("\\", evaluateExpression("${'\\\\'}"));
|
||||
Assert.assertEquals("\\", evaluateExpression("${\"\\\\\"}"));
|
||||
Assert.assertEquals("\\\"'$#", evaluateExpression("${'\\\\\\\"\\'$#'}"));
|
||||
Assert.assertEquals("\\\"'$#", evaluateExpression("${\"\\\\\\\"\\'$#\"}"));
|
||||
|
||||
// Trying to quote # or $ should throw an error
|
||||
Exception e = null;
|
||||
try {
|
||||
evaluateExpression("${'\\$'}");
|
||||
} catch (ELException el) {
|
||||
e = el;
|
||||
}
|
||||
Assert.assertNotNull(e);
|
||||
|
||||
Assert.assertEquals("\\$", evaluateExpression("${'\\\\$'}"));
|
||||
Assert.assertEquals("\\\\$", evaluateExpression("${'\\\\\\\\$'}"));
|
||||
|
||||
|
||||
// Can use ''' inside '"' when quoting with '"' and vice versa without
|
||||
// escaping
|
||||
Assert.assertEquals("\\\"", evaluateExpression("${'\\\\\"'}"));
|
||||
Assert.assertEquals("\"\\", evaluateExpression("${'\"\\\\'}"));
|
||||
Assert.assertEquals("\\'", evaluateExpression("${'\\\\\\''}"));
|
||||
Assert.assertEquals("'\\", evaluateExpression("${'\\'\\\\'}"));
|
||||
Assert.assertEquals("\\'", evaluateExpression("${\"\\\\'\"}"));
|
||||
Assert.assertEquals("'\\", evaluateExpression("${\"'\\\\\"}"));
|
||||
Assert.assertEquals("\\\"", evaluateExpression("${\"\\\\\\\"\"}"));
|
||||
Assert.assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleEscaping() throws Exception {
|
||||
Assert.assertEquals("''", evaluateExpression("${\"\'\'\"}"));
|
||||
}
|
||||
|
||||
private void compareBoth(String msg, int expected, Object o1, Object o2){
|
||||
int i1 = ELSupport.compare(null, o1, o2);
|
||||
int i2 = ELSupport.compare(null, o2, o1);
|
||||
Assert.assertEquals(msg,expected, i1);
|
||||
Assert.assertEquals(msg,expected, -i2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testElSupportCompare(){
|
||||
compareBoth("Nulls should compare equal", 0, null, null);
|
||||
compareBoth("Null should compare equal to \"\"", 0, "", null);
|
||||
compareBoth("Null should be less than File()",-1, null, new File(""));
|
||||
compareBoth("Null should be less than Date()",-1, null, new Date());
|
||||
compareBoth("Date(0) should be less than Date(1)",-1, new Date(0), new Date(1));
|
||||
try {
|
||||
compareBoth("Should not compare",0, new Date(), new File(""));
|
||||
Assert.fail("Expecting ClassCastException");
|
||||
} catch (ClassCastException expected) {
|
||||
// Expected
|
||||
}
|
||||
Assert.assertTrue(null == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test mixing ${...} and #{...} in the same expression.
|
||||
*/
|
||||
@Test
|
||||
public void testMixedTypes() {
|
||||
// Mixing types should throw an error
|
||||
Exception e = null;
|
||||
try {
|
||||
evaluateExpression("${1+1}#{1+1}");
|
||||
} catch (ELException el) {
|
||||
e = el;
|
||||
}
|
||||
Assert.assertNotNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscape01() {
|
||||
Assert.assertEquals("$${", evaluateExpression("$\\${"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49081a() {
|
||||
Assert.assertEquals("$2", evaluateExpression("$${1+1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49081b() {
|
||||
Assert.assertEquals("#2", evaluateExpression("##{1+1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49081c() {
|
||||
Assert.assertEquals("#2", evaluateExpression("#${1+1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49081d() {
|
||||
Assert.assertEquals("$2", evaluateExpression("$#{1+1}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug60431a() {
|
||||
Assert.assertEquals("OK", evaluateExpression("${fn:concat('O','K')}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug60431b() {
|
||||
Assert.assertEquals("OK", evaluateExpression("${fn:concat(fn:toArray('O','K'))}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug60431c() {
|
||||
Assert.assertEquals("", evaluateExpression("${fn:concat()}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug60431d() {
|
||||
Assert.assertEquals("OK", evaluateExpression("${fn:concat2('OK')}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug60431e() {
|
||||
Assert.assertEquals("RUOK", evaluateExpression("${fn:concat2('RU', fn:toArray('O','K'))}"));
|
||||
}
|
||||
|
||||
// ************************************************************************
|
||||
|
||||
private String evaluateExpression(String expression) {
|
||||
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
|
||||
ELContextImpl ctx = new ELContextImpl(exprFactory);
|
||||
ctx.setFunctionMapper(new TesterFunctions.FMapper());
|
||||
ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
|
||||
String.class);
|
||||
return (String) ve.getValue(ctx);
|
||||
}
|
||||
}
|
||||
528
test/org/apache/el/TestELInJsp.java
Normal file
528
test/org/apache/el/TestELInJsp.java
Normal file
File diff suppressed because it is too large
Load Diff
539
test/org/apache/el/TestMethodExpressionImpl.java
Normal file
539
test/org/apache/el/TestMethodExpressionImpl.java
Normal file
File diff suppressed because it is too large
Load Diff
267
test/org/apache/el/TestValueExpressionImpl.java
Normal file
267
test/org/apache/el/TestValueExpressionImpl.java
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.el.ValueReference;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.jasper.el.ELContextImpl;
|
||||
|
||||
public class TestValueExpressionImpl {
|
||||
|
||||
@Test
|
||||
public void testGetValueReference() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanB beanB = new TesterBeanB();
|
||||
beanB.setName("Tomcat");
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanB, TesterBeanB.class);
|
||||
context.getVariableMapper().setVariable("beanB", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${beanB.name}", String.class);
|
||||
|
||||
// First check the basics work
|
||||
String result = (String) ve.getValue(context);
|
||||
Assert.assertEquals("Tomcat", result);
|
||||
|
||||
// Now check the value reference
|
||||
ValueReference vr = ve.getValueReference(context);
|
||||
Assert.assertNotNull(vr);
|
||||
|
||||
Assert.assertEquals(beanB, vr.getBase());
|
||||
Assert.assertEquals("name", vr.getProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValueReferenceVariable() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanB beanB = new TesterBeanB();
|
||||
beanB.setName("Tomcat");
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanB, TesterBeanB.class);
|
||||
context.getVariableMapper().setVariable("beanB", var);
|
||||
|
||||
ValueExpression var2 = factory.createValueExpression(
|
||||
context, "${beanB.name}", String.class);
|
||||
|
||||
context.getVariableMapper().setVariable("foo", var2);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${foo}", ValueExpression.class);
|
||||
|
||||
|
||||
// Now check the value reference
|
||||
ValueReference vr = ve.getValueReference(context);
|
||||
Assert.assertNotNull(vr);
|
||||
|
||||
Assert.assertEquals(beanB, vr.getBase());
|
||||
Assert.assertEquals("name", vr.getProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug49345() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanA beanA = new TesterBeanA();
|
||||
TesterBeanB beanB = new TesterBeanB();
|
||||
beanB.setName("Tomcat");
|
||||
beanA.setBean(beanB);
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanA, TesterBeanA.class);
|
||||
context.getVariableMapper().setVariable("beanA", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${beanA.bean.name}", String.class);
|
||||
|
||||
// First check the basics work
|
||||
String result = (String) ve.getValue(context);
|
||||
Assert.assertEquals("Tomcat", result);
|
||||
|
||||
// Now check the value reference
|
||||
ValueReference vr = ve.getValueReference(context);
|
||||
Assert.assertNotNull(vr);
|
||||
|
||||
Assert.assertEquals(beanB, vr.getBase());
|
||||
Assert.assertEquals("name", vr.getProperty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug50105() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterEnum testEnum = TesterEnum.APPLE;
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(testEnum, TesterEnum.class);
|
||||
context.getVariableMapper().setVariable("testEnum", var);
|
||||
|
||||
// When coercing an Enum to a String, name() should always be used.
|
||||
ValueExpression ve1 = factory.createValueExpression(
|
||||
context, "${testEnum}", String.class);
|
||||
String result1 = (String) ve1.getValue(context);
|
||||
Assert.assertEquals("APPLE", result1);
|
||||
|
||||
ValueExpression ve2 = factory.createValueExpression(
|
||||
context, "foo${testEnum}bar", String.class);
|
||||
String result2 = (String) ve2.getValue(context);
|
||||
Assert.assertEquals("fooAPPLEbar", result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug51177ObjectMap() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
Object o1 = "String value";
|
||||
Object o2 = Integer.valueOf(32);
|
||||
|
||||
Map<Object,Object> map = new HashMap<>();
|
||||
map.put("key1", o1);
|
||||
map.put("key2", o2);
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(map, Map.class);
|
||||
context.getVariableMapper().setVariable("map", var);
|
||||
|
||||
ValueExpression ve1 = factory.createValueExpression(
|
||||
context, "${map.key1}", Object.class);
|
||||
ve1.setValue(context, o2);
|
||||
Assert.assertEquals(o2, ve1.getValue(context));
|
||||
|
||||
ValueExpression ve2 = factory.createValueExpression(
|
||||
context, "${map.key2}", Object.class);
|
||||
ve2.setValue(context, o1);
|
||||
Assert.assertEquals(o1, ve2.getValue(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug51177ObjectList() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
Object o1 = "String value";
|
||||
Object o2 = Integer.valueOf(32);
|
||||
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(0, o1);
|
||||
list.add(1, o2);
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(list, List.class);
|
||||
context.getVariableMapper().setVariable("list", var);
|
||||
|
||||
ValueExpression ve1 = factory.createValueExpression(
|
||||
context, "${list[0]}", Object.class);
|
||||
ve1.setValue(context, o2);
|
||||
Assert.assertEquals(o2, ve1.getValue(context));
|
||||
|
||||
ValueExpression ve2 = factory.createValueExpression(
|
||||
context, "${list[1]}", Object.class);
|
||||
ve2.setValue(context, o1);
|
||||
Assert.assertEquals(o1, ve2.getValue(context));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test returning an empty list as a bean property.
|
||||
*/
|
||||
@Test
|
||||
public void testBug51544Bean() throws Exception {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanA beanA = new TesterBeanA();
|
||||
beanA.setValList(Collections.emptyList());
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanA, TesterBeanA.class);
|
||||
context.getVariableMapper().setVariable("beanA", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${beanA.valList.size()}", Integer.class);
|
||||
|
||||
Integer result = (Integer) ve.getValue(context);
|
||||
Assert.assertEquals(Integer.valueOf(0), result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Test using list directly as variable.
|
||||
*/
|
||||
@Test
|
||||
public void testBug51544Direct() throws Exception {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
List<?> list = Collections.emptyList();
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(list, List.class);
|
||||
context.getVariableMapper().setVariable("list", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${list.size()}", Integer.class);
|
||||
|
||||
Integer result = (Integer) ve.getValue(context);
|
||||
Assert.assertEquals(Integer.valueOf(0), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBug56522SetNullValue() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanB beanB = new TesterBeanB();
|
||||
beanB.setName("Tomcat");
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanB, TesterBeanB.class);
|
||||
context.getVariableMapper().setVariable("beanB", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${beanB.name}", String.class);
|
||||
|
||||
// First check the basics work
|
||||
String result = (String) ve.getValue(context);
|
||||
Assert.assertEquals("Tomcat", result);
|
||||
|
||||
// Now set the value to null
|
||||
ve.setValue(context, null);
|
||||
|
||||
Assert.assertEquals("", beanB.getName());
|
||||
}
|
||||
}
|
||||
67
test/org/apache/el/TesterBeanA.java
Normal file
67
test/org/apache/el/TesterBeanA.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TesterBeanA {
|
||||
private TesterBeanB bean;
|
||||
private String name;
|
||||
private long valLong;
|
||||
private List<?> valList;
|
||||
|
||||
public TesterBeanB getBean() {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void setBean(TesterBeanB bean) {
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getValLong() {
|
||||
return valLong;
|
||||
}
|
||||
|
||||
public void setValLong(long valLong) {
|
||||
this.valLong = valLong;
|
||||
}
|
||||
|
||||
public List<?> getValList() {
|
||||
return valList;
|
||||
}
|
||||
|
||||
public void setValList(List<?> valList) {
|
||||
this.valList = valList;
|
||||
}
|
||||
|
||||
public CharSequence echo1(CharSequence cs) {
|
||||
return "A1" + cs;
|
||||
}
|
||||
|
||||
public CharSequence echo2(String s) {
|
||||
return "A2" + s;
|
||||
}
|
||||
}
|
||||
31
test/org/apache/el/TesterBeanAA.java
Normal file
31
test/org/apache/el/TesterBeanAA.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanAA extends TesterBeanA {
|
||||
|
||||
@Override
|
||||
public String echo1(CharSequence cs) {
|
||||
return "AA1" + cs.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String echo2(String s) {
|
||||
return "AA2" + s;
|
||||
}
|
||||
}
|
||||
23
test/org/apache/el/TesterBeanAAA.java
Normal file
23
test/org/apache/el/TesterBeanAAA.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanAAA extends TesterBeanAA {
|
||||
// No additional implementation - just need a class that extends AA for
|
||||
// testing EL methods calls
|
||||
}
|
||||
53
test/org/apache/el/TesterBeanB.java
Normal file
53
test/org/apache/el/TesterBeanB.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanB {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String sayHello() {
|
||||
return "Hello from " + name;
|
||||
}
|
||||
|
||||
public String sayHello(String to) {
|
||||
return "Hello " + to + " from " + name;
|
||||
}
|
||||
|
||||
public String echo(String...strings) {
|
||||
if (strings == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(strings[i]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
31
test/org/apache/el/TesterBeanBB.java
Normal file
31
test/org/apache/el/TesterBeanBB.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanBB extends TesterBeanB {
|
||||
|
||||
private String extra;
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
}
|
||||
23
test/org/apache/el/TesterBeanBBB.java
Normal file
23
test/org/apache/el/TesterBeanBBB.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanBBB extends TesterBeanBB {
|
||||
// No additional implementation - just need a class that extends BB for
|
||||
// testing EL methods calls
|
||||
}
|
||||
41
test/org/apache/el/TesterBeanC.java
Normal file
41
test/org/apache/el/TesterBeanC.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanC {
|
||||
public String sayHello(TesterBeanA a, TesterBeanB b) {
|
||||
return "AB: Hello " + a.getName() + " from " + b.getName();
|
||||
}
|
||||
public String sayHello(TesterBeanAA a, TesterBeanB b) {
|
||||
return "AAB: Hello " + a.getName() + " from " + b.getName();
|
||||
}
|
||||
public String sayHello(TesterBeanA a, TesterBeanBB b) {
|
||||
return "ABB: Hello " + a.getName() + " from " + b.getName();
|
||||
}
|
||||
public String sayHello(TesterBeanA a, TesterBeanBB... b) {
|
||||
StringBuilder result =
|
||||
new StringBuilder("ABB[]: Hello " + a.getName() + " from ");
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
if (i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(b[i].getName());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
40
test/org/apache/el/TesterBeanD.java
Normal file
40
test/org/apache/el/TesterBeanD.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class used to test the calling of overloaded methods.
|
||||
*/
|
||||
public class TesterBeanD {
|
||||
|
||||
private List<Object> things = new ArrayList<>();
|
||||
|
||||
public void addThing(String thing) {
|
||||
things.add(thing);
|
||||
}
|
||||
|
||||
public void addThing(Class<?> clazz) {
|
||||
things.add(clazz);
|
||||
}
|
||||
|
||||
public List<Object> getThings() {
|
||||
return things;
|
||||
}
|
||||
}
|
||||
30
test/org/apache/el/TesterBeanEnum.java
Normal file
30
test/org/apache/el/TesterBeanEnum.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public class TesterBeanEnum {
|
||||
|
||||
private volatile TesterEnum lastSubmitted = null;
|
||||
|
||||
public void submit(TesterEnum testerEnum) {
|
||||
this.lastSubmitted = testerEnum;
|
||||
}
|
||||
|
||||
public TesterEnum getLastSubmitted() {
|
||||
return lastSubmitted;
|
||||
}
|
||||
}
|
||||
26
test/org/apache/el/TesterEnum.java
Normal file
26
test/org/apache/el/TesterEnum.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
public enum TesterEnum {
|
||||
APPLE, ORANGE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "This is a " + this.name();
|
||||
}
|
||||
}
|
||||
110
test/org/apache/el/TesterFunctions.java
Normal file
110
test/org/apache/el/TesterFunctions.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.el.FunctionMapper;
|
||||
|
||||
public class TesterFunctions {
|
||||
public static String trim(String input) {
|
||||
return input.trim();
|
||||
}
|
||||
|
||||
public static String concat(String... inputs) {
|
||||
if (inputs == null || inputs.length == 0) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String input : inputs) {
|
||||
result.append(input);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String concat2(String prefix, String... inputs) {
|
||||
StringBuilder result = new StringBuilder(prefix);
|
||||
for (String input : inputs) {
|
||||
result.append(input);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String[] toArray(String a, String b) {
|
||||
return new String[] { a, b };
|
||||
}
|
||||
|
||||
|
||||
public static class Inner$Class {
|
||||
|
||||
public static final String RETVAL = "Return from bug49555";
|
||||
public static String bug49555() {
|
||||
return RETVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class FMapper extends FunctionMapper {
|
||||
|
||||
@Override
|
||||
public Method resolveFunction(String prefix, String localName) {
|
||||
if ("trim".equals(localName)) {
|
||||
Method m;
|
||||
try {
|
||||
m = TesterFunctions.class.getMethod("trim", String.class);
|
||||
return m;
|
||||
} catch (SecurityException e) {
|
||||
// Ignore
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("concat".equals(localName)) {
|
||||
Method m;
|
||||
try {
|
||||
m = TesterFunctions.class.getMethod("concat", String[].class);
|
||||
return m;
|
||||
} catch (SecurityException e) {
|
||||
// Ignore
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("concat2".equals(localName)) {
|
||||
Method m;
|
||||
try {
|
||||
m = TesterFunctions.class.getMethod("concat2", String.class, String[].class);
|
||||
return m;
|
||||
} catch (SecurityException e) {
|
||||
// Ignore
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("toArray".equals(localName)) {
|
||||
Method m;
|
||||
try {
|
||||
m = TesterFunctions.class.getMethod("toArray", String.class, String.class);
|
||||
return m;
|
||||
} catch (SecurityException e) {
|
||||
// Ignore
|
||||
} catch (NoSuchMethodException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
140
test/org/apache/el/lang/TestELArithmetic.java
Normal file
140
test/org/apache/el/lang/TestELArithmetic.java
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestELArithmetic {
|
||||
private static final String a = "1.1";
|
||||
private static final BigInteger b =
|
||||
new BigInteger("1000000000000000000000");
|
||||
|
||||
@Test
|
||||
public void testAdd01() throws Exception {
|
||||
Assert.assertEquals("1000000000000000000001.1",
|
||||
String.valueOf(ELArithmetic.add(a, b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null + null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtract01() throws Exception {
|
||||
Assert.assertEquals("-999999999999999999998.9",
|
||||
String.valueOf(ELArithmetic.subtract(a, b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubtract02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null - null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiply01() throws Exception {
|
||||
Assert.assertEquals("1100000000000000000000.0",
|
||||
String.valueOf(ELArithmetic.multiply(a, b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiply02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null * null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivide01() throws Exception {
|
||||
Assert.assertEquals("0.0",
|
||||
String.valueOf(ELArithmetic.divide(a, b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivide02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null / null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMod01() throws Exception {
|
||||
Assert.assertEquals("1.1",
|
||||
String.valueOf(ELArithmetic.mod(a, b)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMod02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null % null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnaryMinus01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("-null");
|
||||
Assert.assertEquals(Long.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371bigDecimal() throws Exception {
|
||||
Assert.assertEquals(BigDecimal.valueOf(1),
|
||||
ELArithmetic.add("", BigDecimal.valueOf(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371double() throws Exception {
|
||||
Assert.assertEquals(Double.valueOf(7), ELArithmetic.add("", Double.valueOf(7)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371doubleString() throws Exception {
|
||||
Assert.assertEquals(Double.valueOf(2), ELArithmetic.add("", "2."));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371bigInteger() throws Exception {
|
||||
Assert.assertEquals(BigInteger.valueOf(0),
|
||||
ELArithmetic.multiply("", BigInteger.valueOf(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371long() throws Exception {
|
||||
Assert.assertEquals(Long.valueOf(1), ELArithmetic.add("", Integer.valueOf(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371long2() throws Exception {
|
||||
Assert.assertEquals(Long.valueOf(-3), ELArithmetic.subtract("1", "4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug47371doubleString2() throws Exception {
|
||||
Assert.assertEquals(Double.valueOf(2), ELArithmetic.add("1.", "1"));
|
||||
}
|
||||
}
|
||||
283
test/org/apache/el/lang/TestELSupport.java
Normal file
283
test/org/apache/el/lang/TestELSupport.java
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
import java.beans.PropertyEditorManager;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELManager;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestELSupport {
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Assert.assertTrue(ELSupport.equals(null, "01", Long.valueOf(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigDecimal() {
|
||||
testIsSame(new BigDecimal(
|
||||
"0.123456789012345678901234567890123456789012345678901234567890123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigInteger() {
|
||||
testIsSame(new BigInteger(
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() {
|
||||
testIsSame(Long.valueOf(0x0102030405060708L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInteger() {
|
||||
testIsSame(Integer.valueOf(0x01020304));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShort() {
|
||||
testIsSame(Short.valueOf((short) 0x0102));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByte() {
|
||||
testIsSame(Byte.valueOf((byte) 0xEF));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDouble() {
|
||||
testIsSame(Double.valueOf(0.123456789012345678901234));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloat() {
|
||||
testIsSame(Float.valueOf(0.123456F));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceIntegerToNumber() {
|
||||
Integer input = Integer.valueOf(4390241);
|
||||
Object output = ELSupport.coerceToType(null, input, Number.class);
|
||||
Assert.assertEquals(input, output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceNullToNumber() {
|
||||
Object output = ELSupport.coerceToType(null, null, Number.class);
|
||||
Assert.assertNull(output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceEnumAToEnumA() {
|
||||
Object output = null;
|
||||
try {
|
||||
output = ELSupport.coerceToEnum(null, TestEnumA.VALA1, TestEnumA.class);
|
||||
} finally {
|
||||
Assert.assertEquals(TestEnumA.VALA1, output);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceEnumAToEnumB() {
|
||||
Object output = null;
|
||||
try {
|
||||
output = ELSupport.coerceToEnum(null, TestEnumA.VALA1, TestEnumB.class);
|
||||
} catch (ELException ele) {
|
||||
// Ignore
|
||||
}
|
||||
Assert.assertNull(output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceEnumAToEnumC() {
|
||||
Object output = null;
|
||||
try {
|
||||
output = ELSupport.coerceToEnum(null, TestEnumA.VALA1, TestEnumC.class);
|
||||
} catch (ELException ele) {
|
||||
// Ignore
|
||||
}
|
||||
Assert.assertNull(output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType01() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, Integer.class);
|
||||
Assert.assertNull("Result: " + result, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType02() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, int.class);
|
||||
Assert.assertEquals(Integer.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType03() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, boolean.class);
|
||||
Assert.assertEquals(Boolean.valueOf(null), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType04() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, String.class);
|
||||
Assert.assertEquals("", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType05() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, Character.class);
|
||||
Assert.assertNull("Result: " + result, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType06() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", Character.class);
|
||||
Assert.assertEquals(Character.valueOf((char) 0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType07() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, char.class);
|
||||
Assert.assertEquals(Character.valueOf((char) 0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType08() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", char.class);
|
||||
Assert.assertEquals(Character.valueOf((char) 0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType09() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, Boolean.class);
|
||||
Assert.assertNull("Result: " + result, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType10() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", Boolean.class);
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType11() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
null, boolean.class);
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType12() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", boolean.class);
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType13() {
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", TesterType.class);
|
||||
Assert.assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType14() {
|
||||
PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorNoError.class);
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"Foo", TesterType.class);
|
||||
Assert.assertTrue(result instanceof TesterType);
|
||||
Assert.assertEquals("Foo", ((TesterType) result).getValue());
|
||||
}
|
||||
|
||||
@Test(expected=ELException.class)
|
||||
public void testCoerceToType15() {
|
||||
PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"Foo", TesterType.class);
|
||||
Assert.assertTrue(result instanceof TesterType);
|
||||
Assert.assertEquals("Foo", ((TesterType) result).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToType16() {
|
||||
PropertyEditorManager.registerEditor(TesterType.class, TesterTypeEditorError.class);
|
||||
Object result = ELManager.getExpressionFactory().coerceToType(
|
||||
"", TesterType.class);
|
||||
Assert.assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToNumber01() {
|
||||
Object result = ELSupport.coerceToNumber(
|
||||
null, (Object) null, Integer.class);
|
||||
Assert.assertNull("Result: " + result, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToNumber02() {
|
||||
Object result = ELSupport.coerceToNumber(
|
||||
null, (Object) null, int.class);
|
||||
Assert.assertEquals(Integer.valueOf(0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToBoolean01() {
|
||||
Object result = ELSupport.coerceToBoolean(null, null, true);
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoerceToBoolean02() {
|
||||
Object result = ELSupport.coerceToBoolean(null, null, false);
|
||||
Assert.assertNull("Result: " + result, result);
|
||||
}
|
||||
|
||||
private static void testIsSame(Object value) {
|
||||
Assert.assertEquals(value, ELSupport.coerceToNumber(null, value, value.getClass()));
|
||||
}
|
||||
|
||||
private static enum TestEnumA {
|
||||
VALA1,
|
||||
VALA2
|
||||
}
|
||||
private static enum TestEnumB {
|
||||
VALB1,
|
||||
VALB2
|
||||
}
|
||||
private static enum TestEnumC {
|
||||
VALA1,
|
||||
VALA2,
|
||||
VALB1,
|
||||
VALB2
|
||||
}
|
||||
}
|
||||
21
test/org/apache/el/lang/TesterBean.java
Normal file
21
test/org/apache/el/lang/TesterBean.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
public class TesterBean {
|
||||
|
||||
}
|
||||
30
test/org/apache/el/lang/TesterType.java
Normal file
30
test/org/apache/el/lang/TesterType.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
public class TesterType {
|
||||
|
||||
private final String value;
|
||||
|
||||
public TesterType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
79
test/org/apache/el/lang/TesterTypeEditorBase.java
Normal file
79
test/org/apache/el/lang/TesterTypeEditorBase.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyEditor;
|
||||
|
||||
public abstract class TesterTypeEditorBase implements PropertyEditor {
|
||||
|
||||
protected TesterType type = null;
|
||||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaintable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJavaInitializationString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getCustomEditor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomEditor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
}
|
||||
25
test/org/apache/el/lang/TesterTypeEditorError.java
Normal file
25
test/org/apache/el/lang/TesterTypeEditorError.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
public class TesterTypeEditorError extends TesterTypeEditorBase {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
25
test/org/apache/el/lang/TesterTypeEditorNoError.java
Normal file
25
test/org/apache/el/lang/TesterTypeEditorNoError.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
public class TesterTypeEditorNoError extends TesterTypeEditorBase {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
type = new TesterType(text);
|
||||
}
|
||||
}
|
||||
55
test/org/apache/el/lang/TesterVariableMapperImpl.java
Normal file
55
test/org/apache/el/lang/TesterVariableMapperImpl.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.lang;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.TesterELContext;
|
||||
import javax.el.ValueExpression;
|
||||
import javax.el.VariableMapper;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TesterVariableMapperImpl {
|
||||
|
||||
@Test
|
||||
public void testSetVariable01() {
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
ELContext context = new TesterELContext();
|
||||
ValueExpression ve1 =
|
||||
factory.createValueExpression(context, "${1}", int.class);
|
||||
ValueExpression ve2 =
|
||||
factory.createValueExpression(context, "${2}", int.class);
|
||||
ValueExpression ve3 =
|
||||
factory.createValueExpression(context, "${3}", int.class);
|
||||
|
||||
VariableMapper mapper = new VariableMapperImpl();
|
||||
|
||||
mapper.setVariable("var1", ve1);
|
||||
mapper.setVariable("var2", ve2);
|
||||
mapper.setVariable("var3", ve3);
|
||||
|
||||
|
||||
mapper.setVariable("var2", null);
|
||||
|
||||
Assert.assertEquals(ve1, mapper.resolveVariable("var1"));
|
||||
Assert.assertNull(mapper.resolveVariable("var2"));
|
||||
Assert.assertEquals(ve3, mapper.resolveVariable("var3"));
|
||||
}
|
||||
}
|
||||
53
test/org/apache/el/parser/TestAstAnd.java
Normal file
53
test/org/apache/el/parser/TestAstAnd.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstAnd {
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("true && true");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("true && null");
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null && true");
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null && null");
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
}
|
||||
83
test/org/apache/el/parser/TestAstAssign.java
Normal file
83
test/org/apache/el/parser/TestAstAssign.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstAssign {
|
||||
|
||||
@Test
|
||||
public void testGetValue01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
processor.defineBean("bean01", new TesterBeanB());
|
||||
|
||||
Object result = processor.getValue(
|
||||
"bean01.text = 'hello'", String.class);
|
||||
|
||||
Assert.assertEquals("hello", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetValue02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
processor.defineBean("bean01", new TesterBeanB());
|
||||
|
||||
Object result = processor.getValue(
|
||||
"bean01.text = 'hello'; bean01.text", String.class);
|
||||
|
||||
Assert.assertEquals("hello", result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
processor.defineBean("bean01", new TesterBeanB());
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${bean01.text = 'hello'}", String.class);
|
||||
|
||||
Assert.assertEquals(String.class, ve.getType(context));
|
||||
Assert.assertEquals("hello", ve.getValue(context));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
processor.defineBean("bean01", new TesterBeanB());
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${bean01.text = 'hello'; bean01.text}", String.class);
|
||||
|
||||
Assert.assertEquals(String.class, ve.getType(context));
|
||||
Assert.assertEquals("hello", ve.getValue(context));
|
||||
}
|
||||
}
|
||||
32
test/org/apache/el/parser/TestAstChoice.java
Normal file
32
test/org/apache/el/parser/TestAstChoice.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstChoice {
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null?1:2");
|
||||
Assert.assertEquals(Long.valueOf(2), result);
|
||||
}
|
||||
}
|
||||
122
test/org/apache/el/parser/TestAstConcatenation.java
Normal file
122
test/org/apache/el/parser/TestAstConcatenation.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstConcatenation {
|
||||
|
||||
/**
|
||||
* Test string concatenation.
|
||||
*/
|
||||
@Test
|
||||
public void testConcatenation01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("'a' += 'b'", String.class);
|
||||
Assert.assertEquals("ab", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test coercion to string then concatenation.
|
||||
*/
|
||||
@Test
|
||||
public void testConcatenation02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1 += 2", String.class);
|
||||
Assert.assertEquals("12", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string concatenation with whitespace.
|
||||
*/
|
||||
@Test
|
||||
public void testConcatenation03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("' a' += ' b '", String.class);
|
||||
Assert.assertEquals(" a b ", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string concatenation with mixed types.
|
||||
*/
|
||||
@Test
|
||||
public void testConcatenation04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("'a' += 3", String.class);
|
||||
Assert.assertEquals("a3", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test operator precedence (+ before +=).
|
||||
*/
|
||||
@Test
|
||||
public void testPrecedence01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1 + 2 += 3", String.class);
|
||||
Assert.assertEquals("33", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test operator precedence (+ before +=).
|
||||
*/
|
||||
@Test
|
||||
public void testPrecedence02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1 += 2 + 3", String.class);
|
||||
Assert.assertEquals("15", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test operator precedence (+= before >).
|
||||
*/
|
||||
@Test
|
||||
public void testPrecedence03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("10 > 2 += 3", String.class);
|
||||
Assert.assertEquals("false", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test operator precedence (+= before >).
|
||||
*/
|
||||
@Test
|
||||
public void testPrecedence04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1 += 2 > 3", String.class);
|
||||
Assert.assertEquals("true", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${'a' += 3}", String.class);
|
||||
|
||||
Assert.assertEquals(String.class, ve.getType(context));
|
||||
Assert.assertEquals("a3", ve.getValue(context));
|
||||
}
|
||||
}
|
||||
41
test/org/apache/el/parser/TestAstFunction.java
Normal file
41
test/org/apache/el/parser/TestAstFunction.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstFunction {
|
||||
|
||||
@Test
|
||||
public void testImport01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("Integer(1000)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1000), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImport02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
processor.getELManager().getELContext().getImportHandler()
|
||||
.importStatic("java.lang.Integer.valueOf");
|
||||
Object result = processor.getValue("valueOf(1000)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1000), result);
|
||||
}
|
||||
}
|
||||
46
test/org/apache/el/parser/TestAstIdentifier.java
Normal file
46
test/org/apache/el/parser/TestAstIdentifier.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstIdentifier {
|
||||
|
||||
@Test
|
||||
public void testImport01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("Integer.MAX_VALUE",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(Integer.MAX_VALUE), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testImport02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
processor.getELManager().getELContext().getImportHandler().importStatic(
|
||||
"java.lang.Integer.MAX_VALUE");
|
||||
Object result =
|
||||
processor.getValue("MAX_VALUE",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(Integer.MAX_VALUE), result);
|
||||
}
|
||||
}
|
||||
236
test/org/apache/el/parser/TestAstLambdaExpression.java
Normal file
236
test/org/apache/el/parser/TestAstLambdaExpression.java
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstLambdaExpression {
|
||||
|
||||
@Test
|
||||
public void testSpec01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("(x->x+1)(1)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(2), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpec02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("((x,y)->x+y)(1,2)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(3), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpec03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("(()->64)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(64), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpec04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (x,y)->x+y; v(3,4)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(7), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpec05() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("fact = n -> n==0? 1: n*fact(n-1); fact(5)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(120), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpec06() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(x->y->x-y)(2)(1)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvocation01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->2)()",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(2), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->y->2-y)()(1)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->y->()->2-y)()(1)()",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=ELException.class)
|
||||
public void testNested03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
// More method parameters than there are nested lambda expressions
|
||||
processor.getValue("(()->y->()->2-y)()(1)()()",
|
||||
Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->y->()->x->x-y)()(1)()(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested05() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->y->()->()->x->x-y)()(1)()()(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested06() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("(()->y->()->()->x->x-y)()(1)()(3)(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested07() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("()->()->()->42",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(42), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (x->y->x-y); v(2)(1)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (()->y->2-y); v()(1)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (()->y->()->2-y); v()(1)()",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=ELException.class)
|
||||
public void testLambdaAsFunction04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
// More method parameters than there are nested lambda expressions
|
||||
processor.getValue("v = (()->y->()->2-y); v()(1)()()",
|
||||
Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction05() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (()->y->()->x->x-y); v()(1)()(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction06() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (()->y->()->()->x->x-y); v()(1)()()(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLambdaAsFunction07() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("v = (()->y->()->()->x->x-y); v()(1)()(3)(2)",
|
||||
Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=javax.el.ELException.class)
|
||||
public void testLambdaAsFunction08() {
|
||||
// Using a name space for the function is not allowed
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result =
|
||||
processor.getValue("foo:v = (x)->x+1; foo:v(0)", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(1), result);
|
||||
}
|
||||
}
|
||||
87
test/org/apache/el/parser/TestAstListData.java
Normal file
87
test/org/apache/el/parser/TestAstListData.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstListData {
|
||||
|
||||
private static final List<String> simpleList = new ArrayList<>();
|
||||
private static final List<Object> nestedList = new ArrayList<>();
|
||||
|
||||
static {
|
||||
simpleList.add("a");
|
||||
simpleList.add("b");
|
||||
simpleList.add("c");
|
||||
simpleList.add("b");
|
||||
simpleList.add("c");
|
||||
nestedList.add(simpleList);
|
||||
nestedList.add(Collections.EMPTY_LIST);
|
||||
nestedList.add("d");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue(
|
||||
"['a','b','c', 'b', 'c']", List.class);
|
||||
Assert.assertEquals(simpleList, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("[]", List.class);
|
||||
Assert.assertEquals(Collections.EMPTY_LIST, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue(
|
||||
"[['a','b','c','b','c'],[],'d']", List.class);
|
||||
Assert.assertEquals(nestedList, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${['a','b','c','b','c']}", List.class);
|
||||
|
||||
Assert.assertEquals(List.class, ve.getType(context));
|
||||
Assert.assertEquals(simpleList, ve.getValue(context));
|
||||
}
|
||||
}
|
||||
90
test/org/apache/el/parser/TestAstMapData.java
Normal file
90
test/org/apache/el/parser/TestAstMapData.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstMapData {
|
||||
|
||||
private static final Map<String,String> simpleMap = new HashMap<>();
|
||||
private static final Map<Object,Object> nestedMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
simpleMap.put("a", "1");
|
||||
simpleMap.put("b", "2");
|
||||
simpleMap.put("c", "3");
|
||||
|
||||
nestedMap.put("simple", simpleMap);
|
||||
// {} will get parsed as an empty Set as there is nothing to hint to the
|
||||
// parser that Map is expected here.
|
||||
nestedMap.put("empty", Collections.EMPTY_SET);
|
||||
nestedMap.put("d", "4");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue(
|
||||
"{'a':'1','b':'2','c':'3'}", Map.class);
|
||||
Assert.assertEquals(simpleMap, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("{}", Map.class);
|
||||
Assert.assertEquals(Collections.EMPTY_MAP, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue(
|
||||
"{'simple':{'a':'1','b':'2','c':'3'}," +
|
||||
"'empty':{}," +
|
||||
"'d':'4'}", Map.class);
|
||||
Assert.assertEquals(nestedMap, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${{'a':'1','b':'2','c':'3'}}", Map.class);
|
||||
|
||||
Assert.assertEquals(Map.class, ve.getType(context));
|
||||
Assert.assertEquals(simpleMap, ve.getValue(context));
|
||||
}
|
||||
}
|
||||
46
test/org/apache/el/parser/TestAstNot.java
Normal file
46
test/org/apache/el/parser/TestAstNot.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstNot {
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("!null");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("!true");
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("!false");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
}
|
||||
53
test/org/apache/el/parser/TestAstOr.java
Normal file
53
test/org/apache/el/parser/TestAstOr.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELProcessor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstOr {
|
||||
|
||||
@Test
|
||||
public void test01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("true || true");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("true || null");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null || true");
|
||||
Assert.assertEquals(Boolean.TRUE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test04() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.eval("null || null");
|
||||
Assert.assertEquals(Boolean.FALSE, result);
|
||||
}
|
||||
}
|
||||
66
test/org/apache/el/parser/TestAstSemicolon.java
Normal file
66
test/org/apache/el/parser/TestAstSemicolon.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstSemicolon {
|
||||
|
||||
@Test
|
||||
public void testGetValue01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1;2", String.class);
|
||||
Assert.assertEquals("2", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetValue02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1;2", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(2), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetValue03() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("1;2 + 3", Integer.class);
|
||||
Assert.assertEquals(Integer.valueOf(5), result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${1+1;2+2}", Integer.class);
|
||||
|
||||
Assert.assertEquals(Number.class, ve.getType(context));
|
||||
Assert.assertEquals(Integer.valueOf(4), ve.getValue(context));
|
||||
}
|
||||
}
|
||||
84
test/org/apache/el/parser/TestAstSetData.java
Normal file
84
test/org/apache/el/parser/TestAstSetData.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELManager;
|
||||
import javax.el.ELProcessor;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestAstSetData {
|
||||
|
||||
private static final Set<String> simpleSet = new HashSet<>();
|
||||
private static final Set<Object> nestedSet = new HashSet<>();
|
||||
|
||||
static {
|
||||
simpleSet.add("a");
|
||||
simpleSet.add("b");
|
||||
simpleSet.add("c");
|
||||
|
||||
nestedSet.add(simpleSet);
|
||||
nestedSet.add(Collections.EMPTY_SET);
|
||||
nestedSet.add("d");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("{'a','b','c'}", Set.class);
|
||||
Assert.assertEquals(simpleSet, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple02() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("{}", Set.class);
|
||||
Assert.assertEquals(Collections.EMPTY_SET, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNested01() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
Object result = processor.getValue("{{'a','b','c'},{},'d'}", Set.class);
|
||||
Assert.assertEquals(nestedSet, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
ELProcessor processor = new ELProcessor();
|
||||
ELContext context = processor.getELManager().getELContext();
|
||||
ExpressionFactory factory = ELManager.getExpressionFactory();
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, "${{'a','b','c'}}", Set.class);
|
||||
|
||||
Assert.assertEquals(Set.class, ve.getType(context));
|
||||
Assert.assertEquals(simpleSet, ve.getValue(context));
|
||||
}
|
||||
}
|
||||
291
test/org/apache/el/parser/TestELParser.java
Normal file
291
test/org/apache/el/parser/TestELParser.java
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.apache.jasper.el.ELContextImpl;
|
||||
import org.apache.tomcat.util.collections.SynchronizedStack;
|
||||
|
||||
public class TestELParser {
|
||||
|
||||
@Test
|
||||
public void testBug49081() {
|
||||
// OP's report
|
||||
testExpression("#${1+1}", "#2");
|
||||
|
||||
// Variations on a theme
|
||||
testExpression("#", "#");
|
||||
testExpression("##", "##");
|
||||
testExpression("###", "###");
|
||||
testExpression("$", "$");
|
||||
testExpression("$$", "$$");
|
||||
testExpression("$$$", "$$$");
|
||||
testExpression("#$", "#$");
|
||||
testExpression("#$#", "#$#");
|
||||
testExpression("$#", "$#");
|
||||
testExpression("$#$", "$#$");
|
||||
|
||||
testExpression("#{1+1}", "2");
|
||||
testExpression("##{1+1}", "#2");
|
||||
testExpression("###{1+1}", "##2");
|
||||
testExpression("${1+1}", "2");
|
||||
testExpression("$${1+1}", "$2");
|
||||
testExpression("$$${1+1}", "$$2");
|
||||
testExpression("#${1+1}", "#2");
|
||||
testExpression("#$#{1+1}", "#$2");
|
||||
testExpression("$#{1+1}", "$2");
|
||||
testExpression("$#${1+1}", "$#2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaKeyWordSuffix() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanA beanA = new TesterBeanA();
|
||||
beanA.setInt("five");
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanA, TesterBeanA.class);
|
||||
context.getVariableMapper().setVariable("beanA", var);
|
||||
|
||||
// Should fail
|
||||
Exception e = null;
|
||||
try {
|
||||
factory.createValueExpression(context, "${beanA.int}",
|
||||
String.class);
|
||||
} catch (ELException ele) {
|
||||
e = ele;
|
||||
}
|
||||
Assert.assertNotNull(e);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaKeyWordIdentifier() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanA beanA = new TesterBeanA();
|
||||
beanA.setInt("five");
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanA, TesterBeanA.class);
|
||||
context.getVariableMapper().setVariable("this", var);
|
||||
|
||||
// Should fail
|
||||
Exception e = null;
|
||||
try {
|
||||
factory.createValueExpression(context, "${this}", String.class);
|
||||
} catch (ELException ele) {
|
||||
e = ele;
|
||||
}
|
||||
Assert.assertNotNull(e);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void bug56179a() {
|
||||
doTestBug56179(0, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179b() {
|
||||
doTestBug56179(1, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179c() {
|
||||
doTestBug56179(2, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179d() {
|
||||
doTestBug56179(3, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179e() {
|
||||
doTestBug56179(4, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179f() {
|
||||
doTestBug56179(5, "test == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179g() {
|
||||
doTestBug56179(0, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179h() {
|
||||
doTestBug56179(1, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179i() {
|
||||
doTestBug56179(2, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179j() {
|
||||
doTestBug56179(3, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179k() {
|
||||
doTestBug56179(4, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179l() {
|
||||
doTestBug56179(5, "(test) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179m() {
|
||||
doTestBug56179(5, "((test)) == true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56179n() {
|
||||
doTestBug56179(5, "(((test))) == true");
|
||||
}
|
||||
|
||||
private void doTestBug56179(int parenthesesCount, String innerExpr) {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(Boolean.TRUE, Boolean.class);
|
||||
context.getVariableMapper().setVariable("test", var);
|
||||
|
||||
StringBuilder expr = new StringBuilder();
|
||||
expr.append("${");
|
||||
for (int i = 0; i < parenthesesCount; i++) {
|
||||
expr.append("(");
|
||||
}
|
||||
expr.append(innerExpr);
|
||||
for (int i = 0; i < parenthesesCount; i++) {
|
||||
expr.append(")");
|
||||
}
|
||||
expr.append("}");
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, expr.toString(), String.class);
|
||||
|
||||
String result = (String) ve.getValue(context);
|
||||
Assert.assertEquals("true", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug56185() {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
TesterBeanC beanC = new TesterBeanC();
|
||||
ValueExpression var =
|
||||
factory.createValueExpression(beanC, TesterBeanC.class);
|
||||
context.getVariableMapper().setVariable("myBean", var);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(context,
|
||||
"${(myBean.int1 > 1 and myBean.myBool) or "+
|
||||
"((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}",
|
||||
Boolean.class);
|
||||
Assert.assertEquals(Boolean.FALSE, ve.getValue(context));
|
||||
beanC.setInt1(2);
|
||||
beanC.setMyBool1(true);
|
||||
Assert.assertEquals(Boolean.TRUE, ve.getValue(context));
|
||||
}
|
||||
|
||||
private void testExpression(String expression, String expected) {
|
||||
ExpressionFactory factory = ExpressionFactory.newInstance();
|
||||
ELContext context = new ELContextImpl(factory);
|
||||
|
||||
ValueExpression ve = factory.createValueExpression(
|
||||
context, expression, String.class);
|
||||
|
||||
String result = (String) ve.getValue(context);
|
||||
Assert.assertEquals(expected, result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test to explore if re-using Parser instances is faster.
|
||||
*
|
||||
* Tests on my laptop show:
|
||||
* - overhead by introducing the stack is in the noise for parsing even the
|
||||
* simplest expression
|
||||
* - efficiency from re-using the ELParser is measurable for even a single
|
||||
* reuse of the parser
|
||||
* - with large numbers of parses (~10k) performance for a trivial parse is
|
||||
* three times faster
|
||||
* - around the 100 iterations mark GC overhead adds significant noise to
|
||||
* the results - for consistent results you either need fewer parses to
|
||||
* avoid triggering GC or more parses so the GC effects are evenly
|
||||
* distributed between the runs
|
||||
*
|
||||
* Note that the test is single threaded.
|
||||
*/
|
||||
@Ignore
|
||||
@Test
|
||||
public void testParserPerformance() throws ParseException {
|
||||
final int runs = 20;
|
||||
final int parseIterations = 10000;
|
||||
|
||||
|
||||
for (int j = 0; j < runs; j ++) {
|
||||
long start = System.nanoTime();
|
||||
SynchronizedStack<ELParser> stack = new SynchronizedStack<>();
|
||||
|
||||
for (int i = 0; i < parseIterations; i ++) {
|
||||
ELParser parser = stack.pop();
|
||||
if (parser == null) {
|
||||
parser = new ELParser(new StringReader("${'foo'}"));
|
||||
} else {
|
||||
parser.ReInit(new StringReader("${'foo'}"));
|
||||
}
|
||||
parser.CompositeExpression();
|
||||
stack.push(parser);
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
|
||||
System.out.println(parseIterations +
|
||||
" iterations using ELParser.ReInit(...) took " + (end - start) + "ns");
|
||||
}
|
||||
|
||||
for (int j = 0; j < runs; j ++) {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < parseIterations; i ++) {
|
||||
ELParser parser = new ELParser(new StringReader("${'foo'}"));
|
||||
parser.CompositeExpression();
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
|
||||
System.out.println(parseIterations +
|
||||
" iterations using new ELParser(...) took " + (end - start) + "ns");
|
||||
}
|
||||
}
|
||||
}
|
||||
30
test/org/apache/el/parser/TesterBeanA.java
Normal file
30
test/org/apache/el/parser/TesterBeanA.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
public class TesterBeanA {
|
||||
private String keywordInt;
|
||||
|
||||
public String getInt() {
|
||||
return keywordInt;
|
||||
}
|
||||
|
||||
public void setInt(String keywordInt) {
|
||||
this.keywordInt = keywordInt;
|
||||
}
|
||||
}
|
||||
30
test/org/apache/el/parser/TesterBeanB.java
Normal file
30
test/org/apache/el/parser/TesterBeanB.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
public class TesterBeanB {
|
||||
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
49
test/org/apache/el/parser/TesterBeanC.java
Normal file
49
test/org/apache/el/parser/TesterBeanC.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.parser;
|
||||
|
||||
public class TesterBeanC {
|
||||
|
||||
private int int1;
|
||||
private boolean myBool;
|
||||
private boolean myBool1;
|
||||
|
||||
public int getInt1() {
|
||||
return int1;
|
||||
}
|
||||
|
||||
public void setInt1(int int1) {
|
||||
this.int1 = int1;
|
||||
}
|
||||
|
||||
public boolean isMyBool() {
|
||||
return myBool;
|
||||
}
|
||||
|
||||
public void setMyBool(boolean myBool) {
|
||||
this.myBool = myBool;
|
||||
}
|
||||
|
||||
public boolean isMyBool1() {
|
||||
return myBool1;
|
||||
}
|
||||
|
||||
public void setMyBool1(boolean myBool1) {
|
||||
this.myBool1 = myBool1;
|
||||
}
|
||||
|
||||
}
|
||||
779
test/org/apache/el/stream/TestCollectionOperations.java
Normal file
779
test/org/apache/el/stream/TestCollectionOperations.java
Normal file
File diff suppressed because it is too large
Load Diff
63
test/org/apache/el/util/TestReflectionUtil.java
Normal file
63
test/org/apache/el/util/TestReflectionUtil.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.util;
|
||||
|
||||
import javax.el.MethodNotFoundException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestReflectionUtil {
|
||||
|
||||
private static final Tester BASE = new Tester();
|
||||
|
||||
/*
|
||||
* Expect failure as it is not possible to identify which method named
|
||||
* "testA()" is intended.
|
||||
*/
|
||||
@Test(expected=MethodNotFoundException.class)
|
||||
public void testBug54370a() {
|
||||
ReflectionUtil.getMethod(null, BASE, "testA",
|
||||
new Class[] {null, String.class},
|
||||
new Object[] {null, ""});
|
||||
}
|
||||
|
||||
/*
|
||||
* Expect failure as it is not possible to identify which method named
|
||||
* "testB()" is intended. Note: In EL null can always be coerced to a valid
|
||||
* value for a primitive.
|
||||
*/
|
||||
@Test(expected=MethodNotFoundException.class)
|
||||
public void testBug54370b() {
|
||||
ReflectionUtil.getMethod(null, BASE, "testB",
|
||||
new Class[] {null, String.class},
|
||||
new Object[] {null, ""});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug54370c() {
|
||||
ReflectionUtil.getMethod(null, BASE, "testC",
|
||||
new Class[] {null},
|
||||
new Object[] {null});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug54370d() {
|
||||
ReflectionUtil.getMethod(null, BASE, "testD",
|
||||
new Class[] {null},
|
||||
new Object[] {null});
|
||||
}
|
||||
}
|
||||
52
test/org/apache/el/util/Tester.java
Normal file
52
test/org/apache/el/util/Tester.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.apache.el.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Tester {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testA(InputStream param1, String param2) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testA(Long param1, String param2) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testB(InputStream param1, String param2) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testB(long param1, String param2) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testC(long param1) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testD(String param1) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user