init
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user