import javax.el.FunctionMapper;
import javax.el.ValueExpression;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import org.apache.el.lang.ELSupport;
import org.apache.jasper.el.ELContextImpl;
* {@link org.apache.jasper.compiler.TestAttributeParser} and
* {@link TestELInJsp}.
*/
-public class TestELEvaluation extends TestCase {
+public class TestELEvaluation {
/**
* Test use of spaces in ternary expressions. This was primarily an EL
* parser bug.
*/
+ @Test
public void testBug42565() {
assertEquals("false", evaluateExpression("${false?true:false}"));
assertEquals("false", evaluateExpression("${false?true: false}"));
/**
* Test use nested ternary expressions. This was primarily an EL parser bug.
*/
+ @Test
public void testBug44994() {
assertEquals("none", evaluateExpression(
"${0 lt 0 ? 1 lt 0 ? 'many': 'one': 'none'}"));
assertEquals("many", evaluateExpression(
"${0 lt 2 ? 1 lt 2 ? 'many': 'one': 'none'}"));
}
-
-
+
+ @Test
public void testParserBug45511() {
// Test cases provided by OP
assertEquals("true", evaluateExpression("${empty ('')}"));
assertEquals("false", evaluateExpression("${(true)and(false)}"));
}
+ @Test
public void testBug48112() {
// bug 48112
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
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
assertEquals(msg,expected, -i2);
}
+ @Test
public void testElSupportCompare(){
compareBoth("Nulls should compare equal", 0, null, null);
compareBoth("Null should compare equal to \"\"", 0, "", null);
/**
* Test mixing ${...} and #{...} in the same expression.
*/
+ @Test
public void testMixedTypes() {
// Mixing types should throw an error
Exception e = null;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
import org.apache.jasper.el.ELContextImpl;
-public class TestMethodExpressionImpl extends TestCase {
+public class TestMethodExpressionImpl {
private ExpressionFactory factory;
private ELContext context;
-
- @Override
+
+ @Before
public void setUp() {
factory = ExpressionFactory.newInstance();
context = new ELContextImpl();
context.getVariableMapper().setVariable("beanC",
factory.createValueExpression(beanC, TesterBeanC.class));
}
-
+
+ @Test
public void testIsParametersProvided() {
TesterBeanB beanB = new TesterBeanB();
beanB.setName("Tomcat");
assertTrue(me2.isParmetersProvided());
}
+ @Test
public void testInvoke() {
TesterBeanB beanB = new TesterBeanB();
beanB.setName("B");
me3.invoke(context, new Object[] { null }));
}
+ @Test
public void testInvokeWithSuper() {
MethodExpression me = factory.createMethodExpression(context,
"${beanA.setBean(beanBB)}", null ,
Object r = ve.getValue(context);
assertEquals("BB", r);
}
-
+
+ @Test
public void testInvokeWithSuperABNoReturnTypeNoParamTypes() {
MethodExpression me2 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanB)}", null , null);
Object r2 = me2.invoke(context, null);
assertEquals("AB: Hello A from B", r2.toString());
}
-
+
+ @Test
public void testInvokeWithSuperABReturnTypeNoParamTypes() {
MethodExpression me3 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanB)}", String.class , null);
Object r3 = me3.invoke(context, null);
assertEquals("AB: Hello A from B", r3.toString());
}
-
+
+ @Test
public void testInvokeWithSuperABNoReturnTypeParamTypes() {
MethodExpression me4 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanB)}", null ,
Object r4 = me4.invoke(context, null);
assertEquals("AB: Hello A from B", r4.toString());
}
-
+
+ @Test
public void testInvokeWithSuperABReturnTypeParamTypes() {
MethodExpression me5 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanB)}", String.class ,
Object r5 = me5.invoke(context, null);
assertEquals("AB: Hello A from B", r5.toString());
}
-
+
+ @Test
public void testInvokeWithSuperABB() {
MethodExpression me6 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanBB)}", null , null);
Object r6 = me6.invoke(context, null);
assertEquals("ABB: Hello A from BB", r6.toString());
}
-
+
+ @Test
public void testInvokeWithSuperABBB() {
MethodExpression me7 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanBBB)}", null , null);
Object r7 = me7.invoke(context, null);
assertEquals("ABB: Hello A from BBB", r7.toString());
}
-
+
+ @Test
public void testInvokeWithSuperAAB() {
MethodExpression me8 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAA,beanB)}", null , null);
Object r8 = me8.invoke(context, null);
assertEquals("AAB: Hello AA from B", r8.toString());
}
-
+
+ @Test
public void testInvokeWithSuperAABB() {
MethodExpression me9 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAA,beanBB)}", null , null);
// Expected to fail
assertNotNull(e);
}
-
+
+ @Test
public void testInvokeWithSuperAABBB() {
// The Java compiler reports this as ambiguous. Using the parameter that
// matches exactly seems reasonable to limit the scope of the method
Object r10 = me10.invoke(context, null);
assertEquals("AAB: Hello AA from BBB", r10.toString());
}
-
+
+ @Test
public void testInvokeWithSuperAAAB() {
MethodExpression me11 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAAA,beanB)}", null , null);
Object r11 = me11.invoke(context, null);
assertEquals("AAB: Hello AAA from B", r11.toString());
}
-
+
+ @Test
public void testInvokeWithSuperAAABB() {
// The Java compiler reports this as ambiguous. Using the parameter that
// matches exactly seems reasonable to limit the scope of the method
Object r12 = me12.invoke(context, null);
assertEquals("ABB: Hello AAA from BB", r12.toString());
}
-
+
+ @Test
public void testInvokeWithSuperAAABBB() {
MethodExpression me13 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAAA,beanBBB)}", null , null);
// Expected to fail
assertNotNull(e);
}
-
+
+ @Test
public void testInvokeWithVarArgsAB() throws Exception {
MethodExpression me1 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanB,beanB)}", null , null);
// Expected to fail
assertNotNull(e);
}
-
+
+ @Test
public void testInvokeWithVarArgsABB() throws Exception {
MethodExpression me2 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanBB,beanBB)}", null , null);
Object r2 = me2.invoke(context, null);
assertEquals("ABB[]: Hello A from BB, BB", r2.toString());
}
-
+
+ @Test
public void testInvokeWithVarArgsABBB() throws Exception {
MethodExpression me3 = factory.createMethodExpression(context,
"${beanC.sayHello(beanA,beanBBB,beanBBB)}", null , null);
Object r3 = me3.invoke(context, null);
assertEquals("ABB[]: Hello A from BBB, BBB", r3.toString());
}
-
+
+ @Test
public void testInvokeWithVarArgsAAB() throws Exception {
MethodExpression me4 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAA,beanB,beanB)}", null , null);
// Expected to fail
assertNotNull(e);
}
-
+
+ @Test
public void testInvokeWithVarArgsAABB() throws Exception {
MethodExpression me5 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAA,beanBB,beanBB)}", null , null);
Object r5 = me5.invoke(context, null);
assertEquals("ABB[]: Hello AA from BB, BB", r5.toString());
}
-
+
+ @Test
public void testInvokeWithVarArgsAABBB() throws Exception {
MethodExpression me6 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAA,beanBBB,beanBBB)}", null , null);
Object r6 = me6.invoke(context, null);
assertEquals("ABB[]: Hello AA from BBB, BBB", r6.toString());
}
-
+
+ @Test
public void testInvokeWithVarArgsAAAB() throws Exception {
MethodExpression me7 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAAA,beanB,beanB)}", null , null);
// Expected to fail
assertNotNull(e);
}
-
+
+ @Test
public void testInvokeWithVarArgsAAABB() throws Exception {
MethodExpression me8 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAAA,beanBB,beanBB)}", null , null);
Object r8 = me8.invoke(context, null);
assertEquals("ABB[]: Hello AAA from BB, BB", r8.toString());
}
-
+
+ @Test
public void testInvokeWithVarArgsAAABBB() throws Exception {
MethodExpression me9 = factory.createMethodExpression(context,
"${beanC.sayHello(beanAAA,beanBBB,beanBBB)}", null , null);
Object r9 = me9.invoke(context, null);
assertEquals("ABB[]: Hello AAA from BBB, BBB", r9.toString());
}
-
+
/*
* This is also tested implicitly in numerous places elsewhere in this
* class.
*/
+ @Test
public void testBug49655() throws Exception {
// This is the call the failed
MethodExpression me = factory.createMethodExpression(context,
"#{beanA.name}", java.lang.String.class);
assertEquals("New value", ve.getValue(context));
}
-
+
+ @Test
public void testBugPrimitives() throws Exception {
MethodExpression me = factory.createMethodExpression(context,
"${beanA.setValLong(5)}", null, null);
"#{beanA.valLong}", java.lang.String.class);
assertEquals("5", ve.getValue(context));
}
-
+
+ @Test
public void testBug50449a() throws Exception {
MethodExpression me1 = factory.createMethodExpression(context,
"${beanB.sayHello()}", null, null);
assertEquals("Hello from B", actual);
}
+ @Test
public void testBug50449b() throws Exception {
MethodExpression me1 = factory.createMethodExpression(context,
"${beanB.sayHello('Tomcat')}", null, null);
String actual = (String) me1.invoke(context, null);
assertEquals("Hello Tomcat from B", actual);
}
-
+
+ @Test
public void testBug50790a() throws Exception {
ValueExpression ve = factory.createValueExpression(context,
"#{beanAA.name.contains(beanA.name)}", java.lang.Boolean.class);
assertEquals(Boolean.TRUE, actual);
}
+ @Test
public void testBug50790b() throws Exception {
ValueExpression ve = factory.createValueExpression(context,
"#{beanA.name.contains(beanAA.name)}", java.lang.Boolean.class);
import javax.el.ValueExpression;
import javax.el.ValueReference;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
import org.apache.jasper.el.ELContextImpl;
-public class TestValueExpressionImpl extends TestCase {
+public class TestValueExpressionImpl {
+ @Test
public void testGetValueReference() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
assertEquals("name", vr.getProperty());
}
-
+ @Test
public void testBug49345() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
assertEquals("name", vr.getProperty());
}
-
+ @Test
public void testBug50105() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
assertEquals("fooAPPLEbar", result2);
}
+ @Test
public void testBug51177ObjectMap() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
ve2.setValue(context, o1);
assertEquals(o1, ve2.getValue(context));
}
-
+
+ @Test
public void testBug51177ObjectList() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
/**
* Test returning an empty list as a bean property.
*/
+ @Test
public void testBug51544Bean() throws Exception {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
/**
* Test using list directly as variable.
*/
+ @Test
public void testBug51544Direct() throws Exception {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
import java.math.BigDecimal;
import java.math.BigInteger;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class TestELArithmetic extends TestCase {
+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 testAdd() throws Exception {
assertEquals("1000000000000000000001.1",
String.valueOf(ELArithmetic.add(a, b)));
}
+ @Test
public void testSubtract() throws Exception {
assertEquals("-999999999999999999998.9",
String.valueOf(ELArithmetic.subtract(a, b)));
}
+ @Test
public void testMultiply() throws Exception {
assertEquals("1100000000000000000000.0",
String.valueOf(ELArithmetic.multiply(a, b)));
}
+ @Test
public void testDivide() throws Exception {
assertEquals("0.0",
String.valueOf(ELArithmetic.divide(a, b)));
}
+ @Test
public void testMod() throws Exception {
assertEquals("1.1",
String.valueOf(ELArithmetic.mod(a, b)));
}
+ @Test
public void testBug47371bigDecimal() throws Exception {
assertEquals(BigDecimal.valueOf(1),
ELArithmetic.add("", BigDecimal.valueOf(1)));
}
+ @Test
public void testBug47371double() throws Exception {
assertEquals(Double.valueOf(7), ELArithmetic.add("", Double.valueOf(7)));
}
+ @Test
public void testBug47371doubleString() throws Exception {
assertEquals(Double.valueOf(2), ELArithmetic.add("", "2."));
}
+ @Test
public void testBug47371bigInteger() throws Exception {
assertEquals(BigInteger.valueOf(0),
ELArithmetic.multiply("", BigInteger.valueOf(1)));
}
+ @Test
public void testBug47371long() throws Exception {
assertEquals(Long.valueOf(1), ELArithmetic.add("", Integer.valueOf(1)));
}
+ @Test
public void testBug47371long2() throws Exception {
assertEquals(Long.valueOf(-3), ELArithmetic.subtract("1", "4"));
}
+ @Test
public void testBug47371doubleString2() throws Exception {
assertEquals(Double.valueOf(2), ELArithmetic.add("1.", "1"));
}
import javax.el.ELException;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
-public class TestELSupport extends TestCase {
+import org.junit.Test;
+
+public class TestELSupport {
+ @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(input, Number.class);
assertEquals(input, output);
}
+ @Test
public void testCoerceNullToNumber() {
Object output = ELSupport.coerceToType(null, Number.class);
assertEquals(Long.valueOf(0), output);
}
-
+
+ @Test
public void testCoerceEnumAToEnumA() {
Object output = null;
try {
assertEquals(TestEnumA.VALA1, output);
}
}
-
+
+ @Test
public void testCoerceEnumAToEnumB() {
Object output = null;
try {
assertNull(output);
}
+ @Test
public void testCoerceEnumAToEnumC() {
Object output = null;
try {
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
import org.apache.jasper.el.ELContextImpl;
-public class TestELParser extends TestCase {
+public class TestELParser {
+ @Test
public void testBug49081() {
// OP's report
testExpression("#${1+1}", "#2");
testExpression("$#{1+1}", "$2");
testExpression("$#${1+1}", "$#2");
}
-
+
+ @Test
public void testJavaKeyWordSuffix() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
assertNotNull(e);
}
+ @Test
public void testJavaKeyWordIdentifier() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
import javax.el.FunctionMapper;
import javax.el.ValueExpression;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
import org.apache.el.ExpressionFactoryImpl;
import org.apache.el.TesterFunctions;
* Test the EL processing from JSP attributes. Similar tests may be found in
* {@link org.apache.el.TestELEvaluation} and {@link org.apache.el.TestELInJsp}.
*/
-public class TestAttributeParser extends TestCase {
+public class TestAttributeParser {
/**
* Test use of spaces in ternary expressions. This was primarily an EL
* parser bug.
*/
+ @Test
public void testBug42565() {
assertEquals("false", evalAttr("${false?true:false}", '\"'));
assertEquals("false", evalAttr("${false?true: false}", '\"'));
* {@link org.apache.el.TestELEvaluation}. This is just a smoke test to
* ensure JSP attribute processing doesn't cause any additional issues.
*/
+ @Test
public void testBug44994() {
assertEquals("none",
evalAttr("${0 lt 0 ? 1 lt 0 ? 'many': 'one': 'none'}", '\"'));
* EL. See {@link #testBug45451()} for a test that combines JSP attribute
* quoting and EL quoting.
*/
+ @Test
public void testBug45015() {
// Warning: Java String quoting vs. JSP attribute quoting
assertEquals("hello 'world'", evalAttr("hello 'world'", '\"'));
assertEquals("hello world\"", evalAttr("hello world\\\"", '\''));
}
-
+ @Test
public void testBug45451() {
assertEquals("2", evalAttr("${1+1}", '\"'));
assertEquals("${1+1}", evalAttr("\\${1+1}", '\"'));
assertEquals("\\2", evalAttr("\\\\${1+1}", '\"'));
}
-
+
+ @Test
public void testBug49081() {
assertEquals("#2", evalAttr("#${1+1}", '\"'));
}
+ @Test
public void testLiteral() {
// Inspired by work on bug 45451, comments from kkolinko on the dev
// list and looking at the spec to find some edge cases
assertEquals("foo\\bar\\baz", evalAttr("${\"foo\"}\\\\${\\\'bar\\\'}\\\\${\"baz\"}", '\''));
}
+ @Test
public void testScriptExpressionLiterals() {
assertEquals(" \"hello world\" ", parseScriptExpression(
" \"hello world\" ", (char) 0));