Polish test classes
- Consistent importing of org.junit.Assert.*; - Proper declaration of expected exceptions via @Test(expected). - Renamed SpEL ExpressionTestCase to AbstractExpressionTests. - Formatting and test method naming conventions.
This commit is contained in:
parent
f717b55035
commit
1f778530b5
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -15,15 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.aop.aspectj.annotation;
|
package org.springframework.aop.aspectj.annotation;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotSame;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
@ -46,7 +37,9 @@ import org.aspectj.lang.annotation.DeclareParents;
|
||||||
import org.aspectj.lang.annotation.DeclarePrecedence;
|
import org.aspectj.lang.annotation.DeclarePrecedence;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
|
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
|
|
@ -66,6 +59,9 @@ import test.aop.Lockable;
|
||||||
import test.aop.PerTargetAspect;
|
import test.aop.PerTargetAspect;
|
||||||
import test.aop.TwoAdviceAspect;
|
import test.aop.TwoAdviceAspect;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract tests for AspectJAdvisorFactory.
|
* Abstract tests for AspectJAdvisorFactory.
|
||||||
* See subclasses for tests of concrete factories.
|
* See subclasses for tests of concrete factories.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
@ -27,6 +23,8 @@ import org.junit.Test;
|
||||||
import org.springframework.tests.sample.beans.TestBean;
|
import org.springframework.tests.sample.beans.TestBean;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Dmitriy Kopylenko
|
* @author Dmitriy Kopylenko
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,14 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.aop.framework;
|
package org.springframework.aop.framework;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotSame;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
@ -41,9 +33,11 @@ import junit.framework.TestCase;
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
import org.springframework.aop.AfterReturningAdvice;
|
import org.springframework.aop.AfterReturningAdvice;
|
||||||
import org.springframework.aop.DynamicIntroductionAdvice;
|
import org.springframework.aop.DynamicIntroductionAdvice;
|
||||||
|
|
@ -85,6 +79,8 @@ import test.mixin.LockMixinAdvisor;
|
||||||
import test.mixin.Lockable;
|
import test.mixin.Lockable;
|
||||||
import test.mixin.LockedException;
|
import test.mixin.LockedException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -29,12 +26,14 @@ import org.springframework.expression.ParseException;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common superclass for expression tests.
|
* Common superclass for expression tests.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public abstract class ExpressionTestCase {
|
public abstract class AbstractExpressionTests {
|
||||||
|
|
||||||
private final static boolean DEBUG = false;
|
private final static boolean DEBUG = false;
|
||||||
|
|
||||||
|
|
@ -44,6 +43,7 @@ public abstract class ExpressionTestCase {
|
||||||
protected final ExpressionParser parser = new SpelExpressionParser();
|
protected final ExpressionParser parser = new SpelExpressionParser();
|
||||||
protected final StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
protected final StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate an expression and check that the actual result matches the expectedValue and the class of the result
|
* Evaluate an expression and check that the actual result matches the expectedValue and the class of the result
|
||||||
* matches the expectedClassOfResult.
|
* matches the expectedClassOfResult.
|
||||||
|
|
@ -51,7 +51,7 @@ public abstract class ExpressionTestCase {
|
||||||
* @param expectedValue the expected result for evaluating the expression
|
* @param expectedValue the expected result for evaluating the expression
|
||||||
* @param expectedResultType the expected class of the evaluation result
|
* @param expectedResultType the expected class of the evaluation result
|
||||||
*/
|
*/
|
||||||
public void evaluate(String expression, Object expectedValue, Class<?> expectedResultType) {
|
protected void evaluate(String expression, Object expectedValue, Class<?> expectedResultType) {
|
||||||
try {
|
try {
|
||||||
Expression expr = parser.parseExpression(expression);
|
Expression expr = parser.parseExpression(expression);
|
||||||
if (expr == null) {
|
if (expr == null) {
|
||||||
|
|
@ -61,9 +61,9 @@ public abstract class ExpressionTestCase {
|
||||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||||
}
|
}
|
||||||
// Class<?> expressionType = expr.getValueType();
|
// Class<?> expressionType = expr.getValueType();
|
||||||
// assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
// assertEquals("Type of the expression is not as expected. Should be '" +
|
||||||
// '"+expressionType+"'",
|
// expectedResultType + "' but is '"
|
||||||
// expectedResultType,expressionType);
|
// + expressionType + "'", expectedResultType, expressionType);
|
||||||
|
|
||||||
Object value = expr.getValue(eContext);
|
Object value = expr.getValue(eContext);
|
||||||
|
|
||||||
|
|
@ -86,20 +86,23 @@ public abstract class ExpressionTestCase {
|
||||||
|
|
||||||
if (expectedValue instanceof String) {
|
if (expectedValue instanceof String) {
|
||||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||||
ExpressionTestCase.stringValueOf(value));
|
AbstractExpressionTests.stringValueOf(value));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||||
}
|
}
|
||||||
} catch (EvaluationException ee) {
|
}
|
||||||
|
catch (EvaluationException ee) {
|
||||||
ee.printStackTrace();
|
ee.printStackTrace();
|
||||||
fail("Unexpected Exception: " + ee.getMessage());
|
fail("Unexpected Exception: " + ee.getMessage());
|
||||||
} catch (ParseException pe) {
|
}
|
||||||
|
catch (ParseException pe) {
|
||||||
pe.printStackTrace();
|
pe.printStackTrace();
|
||||||
fail("Unexpected Exception: " + pe.getMessage());
|
fail("Unexpected Exception: " + pe.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evaluateAndAskForReturnType(String expression, Object expectedValue, Class<?> expectedResultType) {
|
protected void evaluateAndAskForReturnType(String expression, Object expectedValue, Class<?> expectedResultType) {
|
||||||
try {
|
try {
|
||||||
Expression expr = parser.parseExpression(expression);
|
Expression expr = parser.parseExpression(expression);
|
||||||
if (expr == null) {
|
if (expr == null) {
|
||||||
|
|
@ -109,9 +112,9 @@ public abstract class ExpressionTestCase {
|
||||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||||
}
|
}
|
||||||
// Class<?> expressionType = expr.getValueType();
|
// Class<?> expressionType = expr.getValueType();
|
||||||
// assertEquals("Type of the expression is not as expected. Should be '"+expectedResultType+"' but is
|
// assertEquals("Type of the expression is not as expected. Should be '" +
|
||||||
// '"+expressionType+"'",
|
// expectedResultType + "' but is '"
|
||||||
// expectedResultType,expressionType);
|
// + expressionType + "'", expectedResultType, expressionType);
|
||||||
|
|
||||||
Object value = expr.getValue(eContext, expectedResultType);
|
Object value = expr.getValue(eContext, expectedResultType);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
@ -128,11 +131,13 @@ public abstract class ExpressionTestCase {
|
||||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||||
// isAssignableFrom would allow some room for compatibility
|
// isAssignableFrom would allow some room for compatibility
|
||||||
// in the above expression...
|
// in the above expression...
|
||||||
} catch (EvaluationException ee) {
|
}
|
||||||
|
catch (EvaluationException ee) {
|
||||||
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
fail("Unexpected EvaluationException: " + ex.getMessage());
|
fail("Unexpected EvaluationException: " + ex.getMessage());
|
||||||
} catch (ParseException pe) {
|
}
|
||||||
|
catch (ParseException pe) {
|
||||||
fail("Unexpected ParseException: " + pe.getMessage());
|
fail("Unexpected ParseException: " + pe.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +152,7 @@ public abstract class ExpressionTestCase {
|
||||||
* @param expectedClassOfResult the expected class of the evaluation result
|
* @param expectedClassOfResult the expected class of the evaluation result
|
||||||
* @param shouldBeWritable should the parsed expression be writable?
|
* @param shouldBeWritable should the parsed expression be writable?
|
||||||
*/
|
*/
|
||||||
public void evaluate(String expression, Object expectedValue, Class<?> expectedClassOfResult,
|
protected void evaluate(String expression, Object expectedValue, Class<?> expectedClassOfResult,
|
||||||
boolean shouldBeWritable) {
|
boolean shouldBeWritable) {
|
||||||
try {
|
try {
|
||||||
Expression e = parser.parseExpression(expression);
|
Expression e = parser.parseExpression(expression);
|
||||||
|
|
@ -168,15 +173,16 @@ public abstract class ExpressionTestCase {
|
||||||
Class<? extends Object> resultType = value.getClass();
|
Class<? extends Object> resultType = value.getClass();
|
||||||
if (expectedValue instanceof String) {
|
if (expectedValue instanceof String) {
|
||||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
||||||
ExpressionTestCase.stringValueOf(value));
|
AbstractExpressionTests.stringValueOf(value));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
|
||||||
}
|
}
|
||||||
// assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue,
|
// assertEquals("Did not get expected value for expression '" + expression +
|
||||||
// ExpressionTestCase.stringValueOf(value));
|
// "'.", expectedValue, stringValueOf(value));
|
||||||
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult
|
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult
|
||||||
+ "' but result was of type '" + resultType + "'", expectedClassOfResult
|
+ "' but result was of type '" + resultType + "'",
|
||||||
.equals/* isAssignableFrom */(resultType), true);
|
expectedClassOfResult.equals/* isAssignableFrom */(resultType), true);
|
||||||
// TODO isAssignableFrom would allow some room for compatibility
|
// TODO isAssignableFrom would allow some room for compatibility
|
||||||
// in the above expression...
|
// in the above expression...
|
||||||
|
|
||||||
|
|
@ -187,10 +193,12 @@ public abstract class ExpressionTestCase {
|
||||||
else
|
else
|
||||||
fail("Expected the expression to be readonly but it is not");
|
fail("Expected the expression to be readonly but it is not");
|
||||||
}
|
}
|
||||||
} catch (EvaluationException ee) {
|
}
|
||||||
|
catch (EvaluationException ee) {
|
||||||
ee.printStackTrace();
|
ee.printStackTrace();
|
||||||
fail("Unexpected Exception: " + ee.getMessage());
|
fail("Unexpected Exception: " + ee.getMessage());
|
||||||
} catch (ParseException pe) {
|
}
|
||||||
|
catch (ParseException pe) {
|
||||||
pe.printStackTrace();
|
pe.printStackTrace();
|
||||||
fail("Unexpected Exception: " + pe.getMessage());
|
fail("Unexpected Exception: " + pe.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -228,15 +236,16 @@ public abstract class ExpressionTestCase {
|
||||||
if (expectedReturnType != null) {
|
if (expectedReturnType != null) {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Object value = expr.getValue(eContext, expectedReturnType);
|
Object value = expr.getValue(eContext, expectedReturnType);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Object value = expr.getValue(eContext);
|
Object value = expr.getValue(eContext);
|
||||||
}
|
}
|
||||||
fail("Should have failed with message " + expectedMessage);
|
fail("Should have failed with message " + expectedMessage);
|
||||||
} catch (EvaluationException ee) {
|
}
|
||||||
|
catch (EvaluationException ee) {
|
||||||
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
SpelEvaluationException ex = (SpelEvaluationException) ee;
|
||||||
if (ex.getMessageCode() != expectedMessage) {
|
if (ex.getMessageCode() != expectedMessage) {
|
||||||
// System.out.println(ex.getMessage());
|
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||||
}
|
}
|
||||||
|
|
@ -262,13 +271,15 @@ public abstract class ExpressionTestCase {
|
||||||
fail("Insert does not match, expected 'null' but insert value was '" + inserts[i - 1]
|
fail("Insert does not match, expected 'null' but insert value was '" + inserts[i - 1]
|
||||||
+ "'");
|
+ "'");
|
||||||
}
|
}
|
||||||
} else if (inserts[i - 1] == null) {
|
}
|
||||||
|
else if (inserts[i - 1] == null) {
|
||||||
if (otherProperties[i] != null) {
|
if (otherProperties[i] != null) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
fail("Insert does not match, expected '" + otherProperties[i]
|
fail("Insert does not match, expected '" + otherProperties[i]
|
||||||
+ "' but insert value was 'null'");
|
+ "' but insert value was 'null'");
|
||||||
}
|
}
|
||||||
} else if (!inserts[i - 1].equals(otherProperties[i])) {
|
}
|
||||||
|
else if (!inserts[i - 1].equals(otherProperties[i])) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
|
||||||
+ inserts[i - 1] + "'");
|
+ inserts[i - 1] + "'");
|
||||||
|
|
@ -276,7 +287,8 @@ public abstract class ExpressionTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ParseException pe) {
|
}
|
||||||
|
catch (ParseException pe) {
|
||||||
pe.printStackTrace();
|
pe.printStackTrace();
|
||||||
fail("Unexpected Exception: " + pe.getMessage());
|
fail("Unexpected Exception: " + pe.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -295,21 +307,22 @@ public abstract class ExpressionTestCase {
|
||||||
Expression expr = parser.parseExpression(expression);
|
Expression expr = parser.parseExpression(expression);
|
||||||
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
|
||||||
fail("Parsing should have failed!");
|
fail("Parsing should have failed!");
|
||||||
} catch (ParseException pe) {
|
}
|
||||||
// pe.printStackTrace();
|
catch (ParseException pe) {
|
||||||
// Throwable t = pe.getCause();
|
// pe.printStackTrace();
|
||||||
// if (t == null) {
|
// Throwable t = pe.getCause();
|
||||||
// fail("ParseException caught with no defined cause");
|
// if (t == null) {
|
||||||
// }
|
// fail("ParseException caught with no defined cause");
|
||||||
// if (!(t instanceof SpelEvaluationException)) {
|
// }
|
||||||
// t.printStackTrace();
|
// if (!(t instanceof SpelEvaluationException)) {
|
||||||
// fail("Cause of parse exception is not a SpelException");
|
// t.printStackTrace();
|
||||||
// }
|
// fail("Cause of parse exception is not a SpelException");
|
||||||
// SpelEvaluationException ex = (SpelEvaluationException) t;
|
// }
|
||||||
// pe.printStackTrace();
|
// SpelEvaluationException ex = (SpelEvaluationException) t;
|
||||||
SpelParseException ex = (SpelParseException)pe;
|
// pe.printStackTrace();
|
||||||
|
SpelParseException ex = (SpelParseException) pe;
|
||||||
if (ex.getMessageCode() != expectedMessage) {
|
if (ex.getMessageCode() != expectedMessage) {
|
||||||
// System.out.println(ex.getMessage());
|
// System.out.println(ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
assertEquals("Failed to get expected message", expectedMessage, ex.getMessageCode());
|
||||||
}
|
}
|
||||||
|
|
@ -340,16 +353,17 @@ public abstract class ExpressionTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stringValueOf(Object value) {
|
protected static String stringValueOf(Object value) {
|
||||||
return stringValueOf(value, false);
|
return stringValueOf(value, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a nice string representation of the input object.
|
* Produce a nice string representation of the input object.
|
||||||
*
|
*
|
||||||
* @param value object to be formatted
|
* @param value object to be formatted
|
||||||
* @return a nice string
|
* @return a nice string
|
||||||
*/
|
*/
|
||||||
public static String stringValueOf(Object value, boolean isNested) {
|
protected static String stringValueOf(Object value, boolean isNested) {
|
||||||
// do something nice for arrays
|
// do something nice for arrays
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return "null";
|
return "null";
|
||||||
|
|
@ -368,7 +382,8 @@ public abstract class ExpressionTestCase {
|
||||||
sb.append(stringValueOf(l[j]));
|
sb.append(stringValueOf(l[j]));
|
||||||
}
|
}
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
} else if (primitiveType == Long.TYPE) {
|
}
|
||||||
|
else if (primitiveType == Long.TYPE) {
|
||||||
long[] l = (long[]) value;
|
long[] l = (long[]) value;
|
||||||
sb.append("long[").append(l.length).append("]{");
|
sb.append("long[").append(l.length).append("]{");
|
||||||
for (int j = 0; j < l.length; j++) {
|
for (int j = 0; j < l.length; j++) {
|
||||||
|
|
@ -378,11 +393,13 @@ public abstract class ExpressionTestCase {
|
||||||
sb.append(stringValueOf(l[j]));
|
sb.append(stringValueOf(l[j]));
|
||||||
}
|
}
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new RuntimeException("Please implement support for type " + primitiveType.getName()
|
throw new RuntimeException("Please implement support for type " + primitiveType.getName()
|
||||||
+ " in ExpressionTestCase.stringValueOf()");
|
+ " in ExpressionTestCase.stringValueOf()");
|
||||||
}
|
}
|
||||||
} else if (value.getClass().getComponentType().isArray()) {
|
}
|
||||||
|
else if (value.getClass().getComponentType().isArray()) {
|
||||||
List<Object> l = Arrays.asList((Object[]) value);
|
List<Object> l = Arrays.asList((Object[]) value);
|
||||||
if (!isNested) {
|
if (!isNested) {
|
||||||
sb.append(value.getClass().getComponentType().getName());
|
sb.append(value.getClass().getComponentType().getName());
|
||||||
|
|
@ -397,7 +414,8 @@ public abstract class ExpressionTestCase {
|
||||||
sb.append(stringValueOf(object, true));
|
sb.append(stringValueOf(object, true));
|
||||||
}
|
}
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
List<Object> l = Arrays.asList((Object[]) value);
|
List<Object> l = Arrays.asList((Object[]) value);
|
||||||
if (!isNested) {
|
if (!isNested) {
|
||||||
sb.append(value.getClass().getComponentType().getName());
|
sb.append(value.getClass().getComponentType().getName());
|
||||||
|
|
@ -414,7 +432,8 @@ public abstract class ExpressionTestCase {
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,35 +13,37 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test construction of arrays.
|
* Test construction of arrays.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ArrayConstructorTests extends ExpressionTestCase {
|
public class ArrayConstructorTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleArrayWithInitializer() {
|
public void simpleArrayWithInitializer() {
|
||||||
evaluateArrayBuildingExpression("new int[]{1,2,3}", "[1,2,3]");
|
evaluateArrayBuildingExpression("new int[]{1,2,3}", "[1,2,3]");
|
||||||
evaluateArrayBuildingExpression("new int[]{}", "[]");
|
evaluateArrayBuildingExpression("new int[]{}", "[]");
|
||||||
evaluate("new int[]{}.length", "0", Integer.class);
|
evaluate("new int[]{}.length", "0", Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConversion() {
|
public void conversion() {
|
||||||
evaluate("new String[]{1,2,3}[0]", "1", String.class);
|
evaluate("new String[]{1,2,3}[0]", "1", String.class);
|
||||||
evaluate("new int[]{'123'}[0]", 123, Integer.class);
|
evaluate("new int[]{'123'}[0]", 123, Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultidimensionalArrays() {
|
public void multidimensionalArrays() {
|
||||||
evaluateAndCheckError("new int[][]{{1,2},{3,4}}", SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED);
|
evaluateAndCheckError("new int[][]{{1,2},{3,4}}", SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED);
|
||||||
evaluateAndCheckError("new int[3][]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
evaluateAndCheckError("new int[3][]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
||||||
evaluateAndCheckError("new int[]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
evaluateAndCheckError("new int[]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
||||||
|
|
@ -50,7 +52,7 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitiveTypeArrayConstructors() {
|
public void primitiveTypeArrayConstructors() {
|
||||||
evaluateArrayBuildingExpression("new int[]{1,2,3,4}", "[1,2,3,4]");
|
evaluateArrayBuildingExpression("new int[]{1,2,3,4}", "[1,2,3,4]");
|
||||||
evaluateArrayBuildingExpression("new boolean[]{true,false,true}", "[true,false,true]");
|
evaluateArrayBuildingExpression("new boolean[]{true,false,true}", "[true,false,true]");
|
||||||
evaluateArrayBuildingExpression("new char[]{'a','b','c'}", "[a,b,c]");
|
evaluateArrayBuildingExpression("new char[]{'a','b','c'}", "[a,b,c]");
|
||||||
|
|
@ -62,7 +64,7 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitiveTypeArrayConstructorsElements() {
|
public void primitiveTypeArrayConstructorsElements() {
|
||||||
evaluate("new int[]{1,2,3,4}[0]", 1, Integer.class);
|
evaluate("new int[]{1,2,3,4}[0]", 1, Integer.class);
|
||||||
evaluate("new boolean[]{true,false,true}[0]", true, Boolean.class);
|
evaluate("new boolean[]{true,false,true}[0]", true, Boolean.class);
|
||||||
evaluate("new char[]{'a','b','c'}[0]", 'a', Character.class);
|
evaluate("new char[]{'a','b','c'}[0]", 'a', Character.class);
|
||||||
|
|
@ -75,7 +77,7 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorCases() {
|
public void errorCases() {
|
||||||
evaluateAndCheckError("new char[7]{'a','c','d','e'}", SpelMessage.INITIALIZER_LENGTH_INCORRECT);
|
evaluateAndCheckError("new char[7]{'a','c','d','e'}", SpelMessage.INITIALIZER_LENGTH_INCORRECT);
|
||||||
evaluateAndCheckError("new char[3]{'a','c','d','e'}", SpelMessage.INITIALIZER_LENGTH_INCORRECT);
|
evaluateAndCheckError("new char[3]{'a','c','d','e'}", SpelMessage.INITIALIZER_LENGTH_INCORRECT);
|
||||||
evaluateAndCheckError("new char[2]{'hello','world'}", SpelMessage.TYPE_CONVERSION_ERROR);
|
evaluateAndCheckError("new char[2]{'hello','world'}", SpelMessage.TYPE_CONVERSION_ERROR);
|
||||||
|
|
@ -83,7 +85,7 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTypeArrayConstructors() {
|
public void typeArrayConstructors() {
|
||||||
evaluate("new String[]{'a','b','c','d'}[1]", "b", String.class);
|
evaluate("new String[]{'a','b','c','d'}[1]", "b", String.class);
|
||||||
evaluateAndCheckError("new String[]{'a','b','c','d'}.size()", SpelMessage.METHOD_NOT_FOUND, 30, "size()",
|
evaluateAndCheckError("new String[]{'a','b','c','d'}.size()", SpelMessage.METHOD_NOT_FOUND, 30, "size()",
|
||||||
"java.lang.String[]");
|
"java.lang.String[]");
|
||||||
|
|
@ -91,12 +93,12 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicArray() {
|
public void basicArray() {
|
||||||
evaluate("new String[3]", "java.lang.String[3]{null,null,null}", String[].class);
|
evaluate("new String[3]", "java.lang.String[3]{null,null,null}", String[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiDimensionalArray() {
|
public void multiDimensionalArray() {
|
||||||
evaluate("new String[2][2]", "[Ljava.lang.String;[2]{[2]{null,null},[2]{null,null}}", String[][].class);
|
evaluate("new String[2][2]", "[Ljava.lang.String;[2]{[2]{null,null},[2]{null,null}}", String[][].class);
|
||||||
evaluate("new String[3][2][1]",
|
evaluate("new String[3][2][1]",
|
||||||
"[[Ljava.lang.String;[3]{[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}}}",
|
"[[Ljava.lang.String;[3]{[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}},[2]{[1]{null},[1]{null}}}",
|
||||||
|
|
@ -104,11 +106,11 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorInvocation03() {
|
public void constructorInvocation03() {
|
||||||
evaluateAndCheckError("new String[]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
evaluateAndCheckError("new String[]", SpelMessage.MISSING_ARRAY_DIMENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorInvocation04() {
|
public void constructorInvocation04() {
|
||||||
evaluateAndCheckError("new Integer[3]{'3','ghi','5'}", SpelMessage.INCORRECT_ELEMENT_TYPE_FOR_ARRAY, 4);
|
evaluateAndCheckError("new Integer[3]{'3','ghi','5'}", SpelMessage.INCORRECT_ELEMENT_TYPE_FOR_ARRAY, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,8 +118,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
SpelExpressionParser parser = new SpelExpressionParser();
|
SpelExpressionParser parser = new SpelExpressionParser();
|
||||||
Expression e = parser.parseExpression(expression);
|
Expression e = parser.parseExpression(expression);
|
||||||
Object o = e.getValue();
|
Object o = e.getValue();
|
||||||
Assert.assertNotNull(o);
|
assertNotNull(o);
|
||||||
Assert.assertTrue(o.getClass().isArray());
|
assertTrue(o.getClass().isArray());
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
s.append('[');
|
s.append('[');
|
||||||
if (o instanceof int[]) {
|
if (o instanceof int[]) {
|
||||||
|
|
@ -128,7 +130,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof boolean[]) {
|
}
|
||||||
|
else if (o instanceof boolean[]) {
|
||||||
boolean[] array = (boolean[]) o;
|
boolean[] array = (boolean[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -136,7 +139,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof char[]) {
|
}
|
||||||
|
else if (o instanceof char[]) {
|
||||||
char[] array = (char[]) o;
|
char[] array = (char[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -144,7 +148,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof long[]) {
|
}
|
||||||
|
else if (o instanceof long[]) {
|
||||||
long[] array = (long[]) o;
|
long[] array = (long[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -152,7 +157,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof short[]) {
|
}
|
||||||
|
else if (o instanceof short[]) {
|
||||||
short[] array = (short[]) o;
|
short[] array = (short[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -160,7 +166,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof double[]) {
|
}
|
||||||
|
else if (o instanceof double[]) {
|
||||||
double[] array = (double[]) o;
|
double[] array = (double[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -168,7 +175,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof float[]) {
|
}
|
||||||
|
else if (o instanceof float[]) {
|
||||||
float[] array = (float[]) o;
|
float[] array = (float[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -176,7 +184,8 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else if (o instanceof byte[]) {
|
}
|
||||||
|
else if (o instanceof byte[]) {
|
||||||
byte[] array = (byte[]) o;
|
byte[] array = (byte[]) o;
|
||||||
for (int i = 0; i < array.length; i++) {
|
for (int i = 0; i < array.length; i++) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
|
@ -184,11 +193,12 @@ public class ArrayConstructorTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
s.append(array[i]);
|
s.append(array[i]);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Assert.fail("Not supported " + o.getClass());
|
else {
|
||||||
|
fail("Not supported " + o.getClass());
|
||||||
}
|
}
|
||||||
s.append(']');
|
s.append(']');
|
||||||
Assert.assertEquals(expectedToString, s.toString());
|
assertEquals(expectedToString, s.toString());
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Oliver Becker
|
* @author Oliver Becker
|
||||||
*/
|
*/
|
||||||
public class BooleanExpressionTests extends ExpressionTestCase {
|
public class BooleanExpressionTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBooleanTrue() {
|
public void testBooleanTrue() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,9 +19,9 @@ package org.springframework.expression.spel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.expression.AccessException;
|
import org.springframework.expression.AccessException;
|
||||||
import org.springframework.expression.ConstructorExecutor;
|
import org.springframework.expression.ConstructorExecutor;
|
||||||
|
|
@ -32,12 +32,14 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests invocation of constructors.
|
* Tests invocation of constructors.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ConstructorInvocationTests extends ExpressionTestCase {
|
public class ConstructorInvocationTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTypeConstructors() {
|
public void testTypeConstructors() {
|
||||||
|
|
@ -46,29 +48,33 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonExistentType() {
|
public void testNonExistentType() {
|
||||||
evaluateAndCheckError("new FooBar()",SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
|
evaluateAndCheckError("new FooBar()", SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
static class TestException extends Exception {
|
static class TestException extends Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Tester {
|
static class Tester {
|
||||||
|
|
||||||
public static int counter;
|
public static int counter;
|
||||||
public int i;
|
public int i;
|
||||||
|
|
||||||
public Tester() {}
|
|
||||||
|
public Tester() {
|
||||||
|
}
|
||||||
|
|
||||||
public Tester(int i) throws Exception {
|
public Tester(int i) throws Exception {
|
||||||
counter++;
|
counter++;
|
||||||
if (i==1) {
|
if (i == 1) {
|
||||||
throw new IllegalArgumentException("IllegalArgumentException for 1");
|
throw new IllegalArgumentException("IllegalArgumentException for 1");
|
||||||
}
|
}
|
||||||
if (i==2) {
|
if (i == 2) {
|
||||||
throw new RuntimeException("RuntimeException for 2");
|
throw new RuntimeException("RuntimeException for 2");
|
||||||
}
|
}
|
||||||
if (i==4) {
|
if (i == 4) {
|
||||||
throw new TestException();
|
throw new TestException();
|
||||||
}
|
}
|
||||||
this.i = i;
|
this.i = i;
|
||||||
|
|
@ -79,6 +85,8 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorThrowingException_SPR6760() {
|
public void testConstructorThrowingException_SPR6760() {
|
||||||
// Test ctor on inventor:
|
// Test ctor on inventor:
|
||||||
|
|
@ -93,60 +101,65 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||||
// Normal exit
|
// Normal exit
|
||||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||||
eContext.setRootObject(new Tester());
|
eContext.setRootObject(new Tester());
|
||||||
eContext.setVariable("bar",3);
|
eContext.setVariable("bar", 3);
|
||||||
Object o = expr.getValue(eContext);
|
Object o = expr.getValue(eContext);
|
||||||
Assert.assertEquals(o,3);
|
assertEquals(o, 3);
|
||||||
Assert.assertEquals(1,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(1, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
// Now the expression has cached that throwException(int) is the right thing to call
|
// Now the expression has cached that throwException(int) is the right thing to
|
||||||
// Let's change 'bar' to be a PlaceOfBirth which indicates the cached reference is
|
// call. Let's change 'bar' to be a PlaceOfBirth which indicates the cached
|
||||||
// out of date.
|
// reference is out of date.
|
||||||
eContext.setVariable("bar",new PlaceOfBirth("London"));
|
eContext.setVariable("bar", new PlaceOfBirth("London"));
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.assertEquals(0, o);
|
assertEquals(0, o);
|
||||||
// That confirms the logic to mark the cached reference stale and retry is working
|
// That confirms the logic to mark the cached reference stale and retry is working
|
||||||
|
|
||||||
|
|
||||||
// Now let's cause the method to exit via exception and ensure it doesn't cause
|
// Now let's cause the method to exit via exception and ensure it doesn't cause
|
||||||
// a retry.
|
// a retry.
|
||||||
|
|
||||||
// First, switch back to throwException(int)
|
// First, switch back to throwException(int)
|
||||||
eContext.setVariable("bar",3);
|
eContext.setVariable("bar", 3);
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.assertEquals(3, o);
|
assertEquals(3, o);
|
||||||
Assert.assertEquals(2,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(2, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
// 4 will make it throw a checked exception - this will be wrapped by spel on the way out
|
// 4 will make it throw a checked exception - this will be wrapped by spel on the
|
||||||
eContext.setVariable("bar",4);
|
// way out
|
||||||
|
eContext.setVariable("bar", 4);
|
||||||
try {
|
try {
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.fail("Should have failed");
|
fail("Should have failed");
|
||||||
} catch (Exception e) {
|
}
|
||||||
// A problem occurred whilst attempting to construct an object of type 'org.springframework.expression.spel.ConstructorInvocationTests$Tester' using arguments '(java.lang.Integer)'
|
catch (Exception e) {
|
||||||
|
// A problem occurred whilst attempting to construct an object of type
|
||||||
|
// 'org.springframework.expression.spel.ConstructorInvocationTests$Tester'
|
||||||
|
// using arguments '(java.lang.Integer)'
|
||||||
int idx = e.getMessage().indexOf("Tester");
|
int idx = e.getMessage().indexOf("Tester");
|
||||||
if (idx==-1) {
|
if (idx == -1) {
|
||||||
Assert.fail("Expected reference to Tester in :"+e.getMessage());
|
fail("Expected reference to Tester in :" + e.getMessage());
|
||||||
}
|
}
|
||||||
// normal
|
// normal
|
||||||
}
|
}
|
||||||
// If counter is 4 then the method got called twice!
|
// If counter is 4 then the method got called twice!
|
||||||
Assert.assertEquals(3,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(3, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
|
|
||||||
// 1 will make it throw a RuntimeException - SpEL will let this through
|
// 1 will make it throw a RuntimeException - SpEL will let this through
|
||||||
eContext.setVariable("bar",1);
|
eContext.setVariable("bar", 1);
|
||||||
try {
|
try {
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.fail("Should have failed");
|
fail("Should have failed");
|
||||||
} catch (Exception e) {
|
}
|
||||||
// A problem occurred whilst attempting to construct an object of type 'org.springframework.expression.spel.ConstructorInvocationTests$Tester' using arguments '(java.lang.Integer)'
|
catch (Exception e) {
|
||||||
|
// A problem occurred whilst attempting to construct an object of type
|
||||||
|
// 'org.springframework.expression.spel.ConstructorInvocationTests$Tester'
|
||||||
|
// using arguments '(java.lang.Integer)'
|
||||||
if (e instanceof SpelEvaluationException) {
|
if (e instanceof SpelEvaluationException) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.fail("Should not have been wrapped");
|
fail("Should not have been wrapped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If counter is 5 then the method got called twice!
|
// If counter is 5 then the method got called twice!
|
||||||
Assert.assertEquals(4,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(4, parser.parseExpression("counter").getValue(eContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -155,58 +168,69 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||||
|
|
||||||
// reflective constructor accessor is the only one by default
|
// reflective constructor accessor is the only one by default
|
||||||
List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
|
List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
|
||||||
Assert.assertEquals(1,constructorResolvers.size());
|
assertEquals(1, constructorResolvers.size());
|
||||||
|
|
||||||
ConstructorResolver dummy = new DummyConstructorResolver();
|
ConstructorResolver dummy = new DummyConstructorResolver();
|
||||||
ctx.addConstructorResolver(dummy);
|
ctx.addConstructorResolver(dummy);
|
||||||
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
|
assertEquals(2, ctx.getConstructorResolvers().size());
|
||||||
|
|
||||||
List<ConstructorResolver> copy = new ArrayList<ConstructorResolver>();
|
List<ConstructorResolver> copy = new ArrayList<ConstructorResolver>();
|
||||||
copy.addAll(ctx.getConstructorResolvers());
|
copy.addAll(ctx.getConstructorResolvers());
|
||||||
Assert.assertTrue(ctx.removeConstructorResolver(dummy));
|
assertTrue(ctx.removeConstructorResolver(dummy));
|
||||||
Assert.assertFalse(ctx.removeConstructorResolver(dummy));
|
assertFalse(ctx.removeConstructorResolver(dummy));
|
||||||
Assert.assertEquals(1,ctx.getConstructorResolvers().size());
|
assertEquals(1, ctx.getConstructorResolvers().size());
|
||||||
|
|
||||||
ctx.setConstructorResolvers(copy);
|
ctx.setConstructorResolvers(copy);
|
||||||
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
|
assertEquals(2, ctx.getConstructorResolvers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class DummyConstructorResolver implements ConstructorResolver {
|
static class DummyConstructorResolver implements ConstructorResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstructorExecutor resolve(EvaluationContext context, String typeName, List<TypeDescriptor> argumentTypes)
|
public ConstructorExecutor resolve(EvaluationContext context, String typeName,
|
||||||
throws AccessException {
|
List<TypeDescriptor> argumentTypes) throws AccessException {
|
||||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVarargsInvocation01() {
|
public void testVarargsInvocation01() {
|
||||||
// Calling 'Fruit(String... strings)'
|
// Calling 'Fruit(String... strings)'
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit('a','b','c').stringscount()", 3, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit('a','b','c').stringscount()", 3,
|
||||||
|
Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit('a').stringscount()", 1, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit('a').stringscount()", 1, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit().stringscount()", 0, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit().stringscount()", 0, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(1,2,3).stringscount()", 3, Integer.class); // all need converting to strings
|
// all need converting to strings
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(1).stringscount()", 1, Integer.class); // needs string conversion
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(1,2,3).stringscount()", 3, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(1,'a',3.0d).stringscount()", 3, Integer.class); // first and last need conversion
|
// needs string conversion
|
||||||
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(1).stringscount()", 1, Integer.class);
|
||||||
|
// first and last need conversion
|
||||||
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(1,'a',3.0d).stringscount()", 3,
|
||||||
|
Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVarargsInvocation02() {
|
public void testVarargsInvocation02() {
|
||||||
// Calling 'Fruit(int i, String... strings)' - returns int+length_of_strings
|
// Calling 'Fruit(int i, String... strings)' - returns int+length_of_strings
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(5,'a','b','c').stringscount()", 8, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(5,'a','b','c').stringscount()", 8,
|
||||||
|
Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a').stringscount()", 3, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a').stringscount()", 3, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(4).stringscount()", 4, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(4).stringscount()", 4, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(8,2,3).stringscount()", 10, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(8,2,3).stringscount()", 10, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(9).stringscount()", 9, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(9).stringscount()", 9, Integer.class);
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a',3.0d).stringscount()", 4, Integer.class);
|
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a',3.0d).stringscount()", 4,
|
||||||
evaluate("new org.springframework.expression.spel.testresources.Fruit(8,stringArrayOfThreeItems).stringscount()", 11, Integer.class);
|
Integer.class);
|
||||||
|
evaluate(
|
||||||
|
"new org.springframework.expression.spel.testresources.Fruit(8,stringArrayOfThreeItems).stringscount()",
|
||||||
|
11, Integer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These tests are attempting to call constructors where we need to widen or convert the argument in order to
|
* These tests are attempting to call constructors where we need to widen or convert
|
||||||
* satisfy a suitable constructor.
|
* the argument in order to satisfy a suitable constructor.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWidening01() {
|
public void testWidening01() {
|
||||||
|
|
@ -220,7 +244,8 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testArgumentConversion01() {
|
public void testArgumentConversion01() {
|
||||||
// Closest ctor will be new String(String) and converter supports Double>String
|
// Closest ctor will be new String(String) and converter supports Double>String
|
||||||
// TODO currently failing as with new ObjectToArray converter closest constructor matched becomes String(byte[]) which fails...
|
// TODO currently failing as with new ObjectToArray converter closest constructor
|
||||||
|
// matched becomes String(byte[]) which fails...
|
||||||
evaluate("new String(3.0d)", "3.0", String.class);
|
evaluate("new String(3.0d)", "3.0", String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ import org.springframework.expression.spel.testresources.TestPerson;
|
||||||
* @author Giovanni Dall'Oglio Risso
|
* @author Giovanni Dall'Oglio Risso
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class EvaluationTests extends ExpressionTestCase {
|
public class EvaluationTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
|
public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
|
public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scenario: using the standard infrastructure and running simple expression evaluation.
|
* Scenario: using the standard infrastructure and running simple expression evaluation.
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import org.springframework.expression.spel.testresources.Inventor;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ExpressionStateTests extends ExpressionTestCase {
|
public class ExpressionStateTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstruction() {
|
public void testConstruction() {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class ExpressionWithConversionTests extends ExpressionTestCase {
|
public class ExpressionWithConversionTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
private static List<String> listOfString = new ArrayList<String>();
|
private static List<String> listOfString = new ArrayList<String>();
|
||||||
private static TypeDescriptor typeDescriptorForListOfString = null;
|
private static TypeDescriptor typeDescriptorForListOfString = null;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class InProgressTests extends ExpressionTestCase {
|
public class InProgressTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelOperatorsBetween01() {
|
public void testRelOperatorsBetween01() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,17 +13,20 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.expression.spel.ast.InlineList;
|
import org.springframework.expression.spel.ast.InlineList;
|
||||||
import org.springframework.expression.spel.standard.SpelExpression;
|
import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test usage of inline lists.
|
* Test usage of inline lists.
|
||||||
*
|
*
|
||||||
|
|
@ -31,11 +34,13 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
* @author Giovanni Dall'Oglio Risso
|
* @author Giovanni Dall'Oglio Risso
|
||||||
* @since 3.0.4
|
* @since 3.0.4
|
||||||
*/
|
*/
|
||||||
public class ListTests extends ExpressionTestCase {
|
public class ListTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
// if the list is full of literals then it will be of the type unmodifiableClass rather than ArrayList
|
// if the list is full of literals then it will be of the type unmodifiableClass
|
||||||
|
// rather than ArrayList
|
||||||
Class<?> unmodifiableClass = Collections.unmodifiableList(new ArrayList<Object>()).getClass();
|
Class<?> unmodifiableClass = Collections.unmodifiableList(new ArrayList<Object>()).getClass();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInlineListCreation01() {
|
public void testInlineListCreation01() {
|
||||||
evaluate("{1, 2, 3, 4, 5}", "[1, 2, 3, 4, 5]", unmodifiableClass);
|
evaluate("{1, 2, 3, 4, 5}", "[1, 2, 3, 4, 5]", unmodifiableClass);
|
||||||
|
|
@ -111,10 +116,14 @@ public class ListTests extends ExpressionTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelOperatorsBetween04() {
|
public void testRelOperatorsBetween04() {
|
||||||
evaluate("new java.math.BigDecimal('1') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
|
evaluate("new java.math.BigDecimal('1') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||||
evaluate("new java.math.BigDecimal('3') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
|
"true", Boolean.class);
|
||||||
evaluate("new java.math.BigDecimal('5') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "true", Boolean.class);
|
evaluate("new java.math.BigDecimal('3') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||||
evaluate("new java.math.BigDecimal('8') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}", "false", Boolean.class);
|
"true", Boolean.class);
|
||||||
|
evaluate("new java.math.BigDecimal('5') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||||
|
"true", Boolean.class);
|
||||||
|
evaluate("new java.math.BigDecimal('8') between {new java.math.BigDecimal('1'),new java.math.BigDecimal('5')}",
|
||||||
|
"false", Boolean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -136,23 +145,19 @@ public class ListTests extends ExpressionTestCase {
|
||||||
SpelExpressionParser parser = new SpelExpressionParser();
|
SpelExpressionParser parser = new SpelExpressionParser();
|
||||||
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
|
SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
|
||||||
SpelNode node = expression.getAST();
|
SpelNode node = expression.getAST();
|
||||||
Assert.assertTrue(node instanceof InlineList);
|
assertTrue(node instanceof InlineList);
|
||||||
InlineList inlineList = (InlineList) node;
|
InlineList inlineList = (InlineList) node;
|
||||||
if (expectedToBeConstant) {
|
if (expectedToBeConstant) {
|
||||||
Assert.assertTrue(inlineList.isConstant());
|
assertTrue(inlineList.isConstant());
|
||||||
} else {
|
}
|
||||||
Assert.assertFalse(inlineList.isConstant());
|
else {
|
||||||
|
assertFalse(inlineList.isConstant());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
public void testInlineListWriting() {
|
public void testInlineListWriting() {
|
||||||
// list should be unmodifiable
|
// list should be unmodifiable
|
||||||
try {
|
|
||||||
evaluate("{1, 2, 3, 4, 5}[0]=6", "[1, 2, 3, 4, 5]", unmodifiableClass);
|
evaluate("{1, 2, 3, 4, 5}[0]=6", "[1, 2, 3, 4, 5]", unmodifiableClass);
|
||||||
Assert.fail();
|
|
||||||
} catch (UnsupportedOperationException uoe) {
|
|
||||||
// success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class LiteralTests extends ExpressionTestCase {
|
public class LiteralTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLiteralBoolean01() {
|
public void testLiteralBoolean01() {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import static org.junit.Assert.*;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class MapAccessTests extends ExpressionTestCase {
|
public class MapAccessTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleMapAccess01() {
|
public void testSimpleMapAccess01() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
@ -26,8 +23,8 @@ import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.expression.AccessException;
|
import org.springframework.expression.AccessException;
|
||||||
import org.springframework.expression.BeanResolver;
|
import org.springframework.expression.BeanResolver;
|
||||||
|
|
@ -42,13 +39,15 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests invocation of methods.
|
* Tests invocation of methods.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class MethodInvocationTests extends ExpressionTestCase {
|
public class MethodInvocationTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleAccess01() {
|
public void testSimpleAccess01() {
|
||||||
|
|
@ -110,15 +109,15 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
|
||||||
eContext.setVariable("bar",3);
|
eContext.setVariable("bar",3);
|
||||||
Object o = expr.getValue(eContext);
|
Object o = expr.getValue(eContext);
|
||||||
Assert.assertEquals(o,3);
|
assertEquals(o, 3);
|
||||||
Assert.assertEquals(1,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(1, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
// Now the expression has cached that throwException(int) is the right thing to call
|
// Now the expression has cached that throwException(int) is the right thing to call
|
||||||
// Let's change 'bar' to be a PlaceOfBirth which indicates the cached reference is
|
// Let's change 'bar' to be a PlaceOfBirth which indicates the cached reference is
|
||||||
// out of date.
|
// out of date.
|
||||||
eContext.setVariable("bar",new PlaceOfBirth("London"));
|
eContext.setVariable("bar",new PlaceOfBirth("London"));
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.assertEquals("London", o);
|
assertEquals("London", o);
|
||||||
// That confirms the logic to mark the cached reference stale and retry is working
|
// That confirms the logic to mark the cached reference stale and retry is working
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -128,39 +127,39 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
// First, switch back to throwException(int)
|
// First, switch back to throwException(int)
|
||||||
eContext.setVariable("bar",3);
|
eContext.setVariable("bar",3);
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.assertEquals(3, o);
|
assertEquals(3, o);
|
||||||
Assert.assertEquals(2,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(2, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
|
|
||||||
// Now cause it to throw an exception:
|
// Now cause it to throw an exception:
|
||||||
eContext.setVariable("bar",1);
|
eContext.setVariable("bar",1);
|
||||||
try {
|
try {
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e instanceof SpelEvaluationException) {
|
if (e instanceof SpelEvaluationException) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.fail("Should not be a SpelEvaluationException");
|
fail("Should not be a SpelEvaluationException");
|
||||||
}
|
}
|
||||||
// normal
|
// normal
|
||||||
}
|
}
|
||||||
// If counter is 4 then the method got called twice!
|
// If counter is 4 then the method got called twice!
|
||||||
Assert.assertEquals(3,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(3, parser.parseExpression("counter").getValue(eContext));
|
||||||
|
|
||||||
eContext.setVariable("bar",4);
|
eContext.setVariable("bar",4);
|
||||||
try {
|
try {
|
||||||
o = expr.getValue(eContext);
|
o = expr.getValue(eContext);
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 4 means it will throw a checked exception - this will be wrapped
|
// 4 means it will throw a checked exception - this will be wrapped
|
||||||
if (!(e instanceof ExpressionInvocationTargetException)) {
|
if (!(e instanceof ExpressionInvocationTargetException)) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.fail("Should have been wrapped");
|
fail("Should have been wrapped");
|
||||||
}
|
}
|
||||||
// normal
|
// normal
|
||||||
}
|
}
|
||||||
// If counter is 5 then the method got called twice!
|
// If counter is 5 then the method got called twice!
|
||||||
Assert.assertEquals(4,parser.parseExpression("counter").getValue(eContext));
|
assertEquals(4, parser.parseExpression("counter").getValue(eContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -180,11 +179,11 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
eContext.setVariable("bar",2);
|
eContext.setVariable("bar",2);
|
||||||
try {
|
try {
|
||||||
expr.getValue(eContext);
|
expr.getValue(eContext);
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (e instanceof SpelEvaluationException) {
|
if (e instanceof SpelEvaluationException) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assert.fail("Should not be a SpelEvaluationException");
|
fail("Should not be a SpelEvaluationException");
|
||||||
}
|
}
|
||||||
// normal
|
// normal
|
||||||
}
|
}
|
||||||
|
|
@ -204,13 +203,15 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
eContext.setVariable("bar",4);
|
eContext.setVariable("bar",4);
|
||||||
try {
|
try {
|
||||||
expr.getValue(eContext);
|
expr.getValue(eContext);
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (ExpressionInvocationTargetException e) {
|
} catch (ExpressionInvocationTargetException e) {
|
||||||
Throwable t = e.getCause();
|
Throwable t = e.getCause();
|
||||||
Assert.assertEquals("org.springframework.expression.spel.testresources.Inventor$TestException", t.getClass().getName());
|
assertEquals(
|
||||||
|
"org.springframework.expression.spel.testresources.Inventor$TestException",
|
||||||
|
t.getClass().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Assert.fail("Should not be a SpelEvaluationException");
|
fail("Should not be a SpelEvaluationException");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -224,24 +225,24 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
// Filter will be called but not do anything, so first doit() will be invoked
|
// Filter will be called but not do anything, so first doit() will be invoked
|
||||||
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
|
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||||
String result = expr.getValue(context,String.class);
|
String result = expr.getValue(context,String.class);
|
||||||
Assert.assertEquals("1",result);
|
assertEquals("1", result);
|
||||||
Assert.assertTrue(filter.filterCalled);
|
assertTrue(filter.filterCalled);
|
||||||
|
|
||||||
// Filter will now remove non @Anno annotated methods
|
// Filter will now remove non @Anno annotated methods
|
||||||
filter.removeIfNotAnnotated = true;
|
filter.removeIfNotAnnotated = true;
|
||||||
filter.filterCalled = false;
|
filter.filterCalled = false;
|
||||||
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||||
result = expr.getValue(context,String.class);
|
result = expr.getValue(context,String.class);
|
||||||
Assert.assertEquals("double 1.0",result);
|
assertEquals("double 1.0", result);
|
||||||
Assert.assertTrue(filter.filterCalled);
|
assertTrue(filter.filterCalled);
|
||||||
|
|
||||||
// check not called for other types
|
// check not called for other types
|
||||||
filter.filterCalled=false;
|
filter.filterCalled=false;
|
||||||
context.setRootObject(new String("abc"));
|
context.setRootObject(new String("abc"));
|
||||||
expr = (SpelExpression) parser.parseExpression("charAt(0)");
|
expr = (SpelExpression) parser.parseExpression("charAt(0)");
|
||||||
result = expr.getValue(context,String.class);
|
result = expr.getValue(context,String.class);
|
||||||
Assert.assertEquals("a",result);
|
assertEquals("a", result);
|
||||||
Assert.assertFalse(filter.filterCalled);
|
assertFalse(filter.filterCalled);
|
||||||
|
|
||||||
// check de-registration works
|
// check de-registration works
|
||||||
filter.filterCalled = false;
|
filter.filterCalled = false;
|
||||||
|
|
@ -249,8 +250,8 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
context.setRootObject(new TestObject());
|
context.setRootObject(new TestObject());
|
||||||
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||||
result = expr.getValue(context,String.class);
|
result = expr.getValue(context,String.class);
|
||||||
Assert.assertEquals("1",result);
|
assertEquals("1", result);
|
||||||
Assert.assertFalse(filter.filterCalled);
|
assertFalse(filter.filterCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple filter
|
// Simple filter
|
||||||
|
|
@ -312,20 +313,20 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||||
|
|
||||||
// reflective method accessor is the only one by default
|
// reflective method accessor is the only one by default
|
||||||
List<MethodResolver> methodResolvers = ctx.getMethodResolvers();
|
List<MethodResolver> methodResolvers = ctx.getMethodResolvers();
|
||||||
Assert.assertEquals(1,methodResolvers.size());
|
assertEquals(1, methodResolvers.size());
|
||||||
|
|
||||||
MethodResolver dummy = new DummyMethodResolver();
|
MethodResolver dummy = new DummyMethodResolver();
|
||||||
ctx.addMethodResolver(dummy);
|
ctx.addMethodResolver(dummy);
|
||||||
Assert.assertEquals(2,ctx.getMethodResolvers().size());
|
assertEquals(2, ctx.getMethodResolvers().size());
|
||||||
|
|
||||||
List<MethodResolver> copy = new ArrayList<MethodResolver>();
|
List<MethodResolver> copy = new ArrayList<MethodResolver>();
|
||||||
copy.addAll(ctx.getMethodResolvers());
|
copy.addAll(ctx.getMethodResolvers());
|
||||||
Assert.assertTrue(ctx.removeMethodResolver(dummy));
|
assertTrue(ctx.removeMethodResolver(dummy));
|
||||||
Assert.assertFalse(ctx.removeMethodResolver(dummy));
|
assertFalse(ctx.removeMethodResolver(dummy));
|
||||||
Assert.assertEquals(1,ctx.getMethodResolvers().size());
|
assertEquals(1, ctx.getMethodResolvers().size());
|
||||||
|
|
||||||
ctx.setMethodResolvers(copy);
|
ctx.setMethodResolvers(copy);
|
||||||
Assert.assertEquals(2,ctx.getMethodResolvers().size());
|
assertEquals(2, ctx.getMethodResolvers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DummyMethodResolver implements MethodResolver {
|
static class DummyMethodResolver implements MethodResolver {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class OperatorOverloaderTests extends ExpressionTestCase {
|
public class OperatorOverloaderTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
static class StringAndBooleanAddition implements OperatorOverloader {
|
static class StringAndBooleanAddition implements OperatorOverloader {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Giovanni Dall'Oglio Risso
|
* @author Giovanni Dall'Oglio Risso
|
||||||
*/
|
*/
|
||||||
public class OperatorTests extends ExpressionTestCase {
|
public class OperatorTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntegerLiteral() {
|
public void testIntegerLiteral() {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import org.junit.Test;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ParserErrorMessagesTests extends ExpressionTestCase {
|
public class ParserErrorMessagesTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBrokenExpression01() {
|
public void testBrokenExpression01() {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class PropertyAccessTests extends ExpressionTestCase {
|
public class PropertyAccessTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleAccess01() {
|
public void testSimpleAccess01() {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ScenariosForSpringSecurity extends ExpressionTestCase {
|
public class ScenariosForSpringSecurity extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScenario01_Roles() throws Exception {
|
public void testScenario01_Roles() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class SetValueTests extends ExpressionTestCase {
|
public class SetValueTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
private final static boolean DEBUG = false;
|
private final static boolean DEBUG = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class SpelDocumentationTests extends ExpressionTestCase {
|
public class SpelDocumentationTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
static Inventor tesla ;
|
static Inventor tesla ;
|
||||||
static Inventor pupin ;
|
static Inventor pupin ;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -34,7 +34,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class TemplateExpressionParsingTests extends ExpressionTestCase {
|
public class TemplateExpressionParsingTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
public static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
|
public static final ParserContext DEFAULT_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class VariableAndFunctionTests extends ExpressionTestCase {
|
public class VariableAndFunctionTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariableAccess01() {
|
public void testVariableAccess01() {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import org.springframework.expression.EvaluationContext;
|
||||||
import org.springframework.expression.ParseException;
|
import org.springframework.expression.ParseException;
|
||||||
import org.springframework.expression.PropertyAccessor;
|
import org.springframework.expression.PropertyAccessor;
|
||||||
import org.springframework.expression.TypedValue;
|
import org.springframework.expression.TypedValue;
|
||||||
import org.springframework.expression.spel.ExpressionTestCase;
|
import org.springframework.expression.spel.AbstractExpressionTests;
|
||||||
import org.springframework.expression.spel.SpelEvaluationException;
|
import org.springframework.expression.spel.SpelEvaluationException;
|
||||||
import org.springframework.expression.spel.SpelMessage;
|
import org.springframework.expression.spel.SpelMessage;
|
||||||
import org.springframework.expression.spel.SpelUtilities;
|
import org.springframework.expression.spel.SpelUtilities;
|
||||||
|
|
@ -44,7 +44,7 @@ import static org.junit.Assert.*;
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
public class ReflectionHelperTests extends ExpressionTestCase {
|
public class ReflectionHelperTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatHelperForClassName() {
|
public void testFormatHelperForClassName() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -18,8 +18,8 @@ package org.springframework.expression.spel.support;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.expression.EvaluationException;
|
import org.springframework.expression.EvaluationException;
|
||||||
import org.springframework.expression.Operation;
|
import org.springframework.expression.Operation;
|
||||||
|
|
@ -28,45 +28,42 @@ import org.springframework.expression.TypeComparator;
|
||||||
import org.springframework.expression.TypeConverter;
|
import org.springframework.expression.TypeConverter;
|
||||||
import org.springframework.expression.TypeLocator;
|
import org.springframework.expression.TypeLocator;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class StandardComponentsTests {
|
public class StandardComponentsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandardEvaluationContext() {
|
public void testStandardEvaluationContext() {
|
||||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||||
Assert.assertNotNull(context.getTypeComparator());
|
assertNotNull(context.getTypeComparator());
|
||||||
|
|
||||||
TypeComparator tc = new StandardTypeComparator();
|
TypeComparator tc = new StandardTypeComparator();
|
||||||
context.setTypeComparator(tc);
|
context.setTypeComparator(tc);
|
||||||
Assert.assertEquals(tc,context.getTypeComparator());
|
assertEquals(tc, context.getTypeComparator());
|
||||||
|
|
||||||
TypeLocator tl = new StandardTypeLocator();
|
TypeLocator tl = new StandardTypeLocator();
|
||||||
context.setTypeLocator(tl);
|
context.setTypeLocator(tl);
|
||||||
Assert.assertEquals(tl,context.getTypeLocator());
|
assertEquals(tl, context.getTypeLocator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = EvaluationException.class)
|
||||||
public void testStandardOperatorOverloader() throws EvaluationException {
|
public void testStandardOperatorOverloader() throws EvaluationException {
|
||||||
OperatorOverloader oo = new StandardOperatorOverloader();
|
OperatorOverloader oo = new StandardOperatorOverloader();
|
||||||
Assert.assertFalse(oo.overridesOperation(Operation.ADD, null, null));
|
assertFalse(oo.overridesOperation(Operation.ADD, null, null));
|
||||||
try {
|
|
||||||
oo.operate(Operation.ADD, 2, 3);
|
oo.operate(Operation.ADD, 2, 3);
|
||||||
Assert.fail("should have failed");
|
|
||||||
} catch (EvaluationException e) {
|
|
||||||
// success
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandardTypeLocator() {
|
public void testStandardTypeLocator() {
|
||||||
StandardTypeLocator tl = new StandardTypeLocator();
|
StandardTypeLocator tl = new StandardTypeLocator();
|
||||||
List<String> prefixes = tl.getImportPrefixes();
|
List<String> prefixes = tl.getImportPrefixes();
|
||||||
Assert.assertEquals(1,prefixes.size());
|
assertEquals(1, prefixes.size());
|
||||||
tl.registerImport("java.util");
|
tl.registerImport("java.util");
|
||||||
prefixes = tl.getImportPrefixes();
|
prefixes = tl.getImportPrefixes();
|
||||||
Assert.assertEquals(2,prefixes.size());
|
assertEquals(2, prefixes.size());
|
||||||
tl.removeImport("java.util");
|
tl.removeImport("java.util");
|
||||||
prefixes = tl.getImportPrefixes();
|
prefixes = tl.getImportPrefixes();
|
||||||
Assert.assertEquals(1,prefixes.size());
|
assertEquals(1, prefixes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -76,4 +73,3 @@ public class StandardComponentsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -28,7 +28,6 @@ import org.custommonkey.xmlunit.NamespaceContext;
|
||||||
import org.custommonkey.xmlunit.SimpleNamespaceContext;
|
import org.custommonkey.xmlunit.SimpleNamespaceContext;
|
||||||
import org.custommonkey.xmlunit.XMLUnit;
|
import org.custommonkey.xmlunit.XMLUnit;
|
||||||
import org.custommonkey.xmlunit.XpathEngine;
|
import org.custommonkey.xmlunit.XpathEngine;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
@ -42,7 +41,7 @@ import org.xml.sax.ContentHandler;
|
||||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.*;
|
import static org.mockito.Matchers.*;
|
||||||
import static org.mockito.BDDMockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link CastorMarshaller} class.
|
* Tests the {@link CastorMarshaller} class.
|
||||||
|
|
@ -55,53 +54,53 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
/**
|
/**
|
||||||
* Represents the expected result that doesn't contain the xml declaration.
|
* Represents the expected result that doesn't contain the xml declaration.
|
||||||
*/
|
*/
|
||||||
private static final String DOCUMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String DOCUMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
+ "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">"
|
||||||
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
|
+ "<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result that doesn't contain the xml namespaces.
|
* Represents the expected result that doesn't contain the xml namespaces.
|
||||||
*/
|
*/
|
||||||
private static final String SUPPRESSED_NAMESPACE_EXPECTED_STRING =
|
private static final String SUPPRESSED_NAMESPACE_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flights><flight><number>42</number></flight></flights>";
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><flights><flight><number>42</number></flight></flights>";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result with modified root element name.
|
* Represents the expected result with modified root element name.
|
||||||
*/
|
*/
|
||||||
private static final String ROOT_ELEMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String ROOT_ELEMENT_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<tns:canceledFlights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
+ "<tns:canceledFlights xmlns:tns=\"http://samples.springframework.org/flight\">"
|
||||||
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:canceledFlights>";
|
+ "<tns:flight><tns:number>42</tns:number></tns:flight></tns:canceledFlights>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result with 'xsi:type' attribute.
|
* Represents the expected result with 'xsi:type' attribute.
|
||||||
*/
|
*/
|
||||||
private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
+ "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
|
||||||
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
|
+ " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">"
|
||||||
"<name>test</name><value>8</value></castor-object></objects>";
|
+ "<name>test</name><value>8</value></castor-object></objects>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result with suppressed 'xsi:type' attribute.
|
* Represents the expected result with suppressed 'xsi:type' attribute.
|
||||||
*/
|
*/
|
||||||
private static final String SUPPRESSED_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String SUPPRESSED_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<objects><castor-object><name>test</name><value>8</value></castor-object></objects>";
|
+ "<objects><castor-object><name>test</name><value>8</value></castor-object></objects>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result with 'xsi:type' attribute for root element.
|
* Represents the expected result with 'xsi:type' attribute for root element.
|
||||||
*/
|
*/
|
||||||
private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
+ "<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
|
||||||
" xsi:type=\"java:java.util.Arrays$ArrayList\">" +
|
+ " xsi:type=\"java:java.util.Arrays$ArrayList\">"
|
||||||
"<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
|
+ "<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">"
|
||||||
"<name>test</name><value>8</value></castor-object></objects>";
|
+ "<name>test</name><value>8</value></castor-object></objects>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the expected result without 'xsi:type' attribute for root element.
|
* Represents the expected result without 'xsi:type' attribute for root element.
|
||||||
*/
|
*/
|
||||||
private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
+ "<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
|
||||||
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
|
+ " xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">"
|
||||||
"<name>test</name><value>8</value></castor-object></objects>";
|
+ "<name>test</name><value>8</value></castor-object></objects>";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Marshaller createMarshaller() throws Exception {
|
protected Marshaller createMarshaller() throws Exception {
|
||||||
|
|
@ -129,10 +128,13 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
InOrder ordered = inOrder(contentHandler);
|
InOrder ordered = inOrder(contentHandler);
|
||||||
ordered.verify(contentHandler).startDocument();
|
ordered.verify(contentHandler).startDocument();
|
||||||
ordered.verify(contentHandler).startPrefixMapping("tns", "http://samples.springframework.org/flight");
|
ordered.verify(contentHandler).startPrefixMapping("tns", "http://samples.springframework.org/flight");
|
||||||
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("tns:flights"), isA(Attributes.class));
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flights"),
|
||||||
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("tns:flight"), isA(Attributes.class));
|
eq("tns:flights"), isA(Attributes.class));
|
||||||
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("tns:number"), isA(Attributes.class));
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flight"),
|
||||||
ordered.verify(contentHandler).characters(eq(new char[]{'4', '2'}), eq(0), eq(2));
|
eq("tns:flight"), isA(Attributes.class));
|
||||||
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("number"),
|
||||||
|
eq("tns:number"), isA(Attributes.class));
|
||||||
|
ordered.verify(contentHandler).characters(eq(new char[] { '4', '2' }), eq(0), eq(2));
|
||||||
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "tns:number");
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "tns:number");
|
||||||
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "tns:flight");
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "tns:flight");
|
||||||
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flights", "tns:flights");
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flights", "tns:flights");
|
||||||
|
|
@ -142,8 +144,8 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supports() throws Exception {
|
public void supports() throws Exception {
|
||||||
Assert.assertTrue("CastorMarshaller does not support Flights", marshaller.supports(Flights.class));
|
assertTrue("CastorMarshaller does not support Flights", marshaller.supports(Flights.class));
|
||||||
Assert.assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class));
|
assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -186,7 +188,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
getCastorMarshaller().setMarshalAsDocument(true);
|
getCastorMarshaller().setMarshalAsDocument(true);
|
||||||
String result = marshalFlights();
|
String result = marshalFlights();
|
||||||
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result);
|
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result);
|
||||||
Assert.assertTrue("Result doesn't contain xml declaration.",
|
assertTrue("Result doesn't contain xml declaration.",
|
||||||
result.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
result.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +198,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
getCastorMarshaller().setMarshalAsDocument(true);
|
getCastorMarshaller().setMarshalAsDocument(true);
|
||||||
String result = marshalFlights();
|
String result = marshalFlights();
|
||||||
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
||||||
Assert.assertFalse("Result contains xml declaration.", result.matches("<\\?\\s*xml"));
|
assertFalse("Result contains xml declaration.", result.matches("<\\?\\s*xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -253,7 +255,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||||
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result);
|
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private CastorMarshaller getCastorMarshaller() {
|
private CastorMarshaller getCastorMarshaller() {
|
||||||
return (CastorMarshaller) marshaller;
|
return (CastorMarshaller) marshaller;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,16 +13,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.servlet;
|
package org.springframework.test.web.servlet;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -39,6 +36,11 @@ import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SPR-10025.
|
* Test for SPR-10025.
|
||||||
*
|
*
|
||||||
|
|
@ -57,6 +59,7 @@ public class Spr10025Tests {
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.mockMvc = webAppContextSetup(this.wac).build();
|
this.mockMvc = webAppContextSetup(this.wac).build();
|
||||||
|
|
@ -86,8 +89,8 @@ public class Spr10025Tests {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public void handle() {
|
public void handle() {
|
||||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||||
Assert.assertNull(attributes.getAttribute("foo1", RequestAttributes.SCOPE_REQUEST));
|
assertNull(attributes.getAttribute("foo1", RequestAttributes.SCOPE_REQUEST));
|
||||||
Assert.assertNotNull(attributes.getAttribute("foo2", RequestAttributes.SCOPE_REQUEST));
|
assertNotNull(attributes.getAttribute("foo2", RequestAttributes.SCOPE_REQUEST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,18 +13,15 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.test.web.servlet;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
|
package org.springframework.test.web.servlet;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -39,8 +36,14 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for SPR-10093 (support for OPTIONS requests).
|
* Tests for SPR-10093 (support for OPTIONS requests).
|
||||||
|
*
|
||||||
* @author Arnaud Cogoluègnes
|
* @author Arnaud Cogoluègnes
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
|
@ -53,6 +56,7 @@ public class Spr10093Tests {
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build();
|
this.mockMvc = webAppContextSetup(this.wac).dispatchOptions(true).build();
|
||||||
|
|
@ -64,7 +68,7 @@ public class Spr10093Tests {
|
||||||
int initialCount = controller.counter.get();
|
int initialCount = controller.counter.get();
|
||||||
this.mockMvc.perform(options("/myUrl")).andExpect(status().isOk());
|
this.mockMvc.perform(options("/myUrl")).andExpect(status().isOk());
|
||||||
|
|
||||||
Assert.assertEquals(initialCount+1,controller.counter.get());
|
assertEquals(initialCount + 1, controller.counter.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,12 +87,12 @@ public class Spr10093Tests {
|
||||||
|
|
||||||
private AtomicInteger counter = new AtomicInteger(0);
|
private AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
@RequestMapping(value="/myUrl",method=RequestMethod.OPTIONS)
|
|
||||||
|
@RequestMapping(value = "/myUrl", method = RequestMethod.OPTIONS)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public void handle() {
|
public void handle() {
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,8 +23,6 @@ import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -37,6 +35,8 @@ import org.springframework.util.StreamUtils;
|
||||||
import org.springframework.util.concurrent.ListenableFuture;
|
import org.springframework.util.concurrent.ListenableFuture;
|
||||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||||
AbstractJettyServerTestCase {
|
AbstractJettyServerTestCase {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,6 +19,7 @@ package org.springframework.http.client;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import javax.servlet.GenericServlet;
|
import javax.servlet.GenericServlet;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
|
|
@ -30,13 +31,15 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.util.SocketUtils;
|
import org.springframework.util.SocketUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/** @author Arjen Poutsma */
|
/** @author Arjen Poutsma */
|
||||||
public class AbstractJettyServerTestCase {
|
public class AbstractJettyServerTestCase {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,12 +17,6 @@
|
||||||
package org.springframework.web.servlet.support;
|
package org.springframework.web.servlet.support;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -33,11 +27,14 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||||
import org.springframework.web.servlet.FlashMap;
|
import org.springframework.web.servlet.FlashMap;
|
||||||
import org.springframework.web.util.WebUtils;
|
import org.springframework.web.util.WebUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture for testing {@link AbstractFlashMapManager} methods.
|
* Test fixture for testing {@link AbstractFlashMapManager} methods.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue