serialization testing
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELResolver;
|
||||
|
||||
@@ -28,7 +30,7 @@ import javax.el.ELResolver;
|
||||
* @author Keith Donald
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public interface ELContextFactory {
|
||||
public interface ELContextFactory extends Serializable {
|
||||
|
||||
/**
|
||||
* Configures and returns an {@link ELContext} to be used in evaluating EL expressions on the given base target
|
||||
|
||||
@@ -69,16 +69,16 @@ class OgnlExpression implements Expression {
|
||||
this.expressionString = expressionString;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return expression.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof OgnlExpression)) {
|
||||
return false;
|
||||
}
|
||||
OgnlExpression other = (OgnlExpression) o;
|
||||
return expression.equals(other.expression);
|
||||
return expressionString.equals(other.expressionString);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return expressionString.hashCode();
|
||||
}
|
||||
|
||||
public Object getValue(Object context) throws EvaluationException {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.springframework.binding.expression.el;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -227,4 +232,25 @@ public class ELExpressionParserTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testSerializeExpression() throws IOException, ClassNotFoundException {
|
||||
String exp = "value";
|
||||
Expression e = parser.parseExpression(exp, null);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
oos.writeObject(e);
|
||||
oos.flush();
|
||||
bytes = baos.toByteArray();
|
||||
} finally {
|
||||
oos.close();
|
||||
}
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
try {
|
||||
Expression e2 = (Expression) ois.readObject();
|
||||
assertEquals(e, e2);
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
*/
|
||||
package org.springframework.binding.expression.ognl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.expression.Expression;
|
||||
@@ -161,4 +167,26 @@ public class OgnlExpressionParserTests extends TestCase {
|
||||
assertEquals(boolean.class, e.getValueType(bean));
|
||||
}
|
||||
|
||||
public void testSerializeExpression() throws IOException, ClassNotFoundException {
|
||||
String exp = "flag";
|
||||
Expression e = parser.parseExpression(exp, null);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
oos.writeObject(e);
|
||||
oos.flush();
|
||||
bytes = baos.toByteArray();
|
||||
} finally {
|
||||
oos.close();
|
||||
}
|
||||
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
|
||||
try {
|
||||
Expression e2 = (Expression) ois.readObject();
|
||||
assertEquals(e, e2);
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user