01: /*
02: * Copyright 2006, 2007 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.el;
17:
18: import java.io.ByteArrayInputStream;
19: import java.io.ByteArrayOutputStream;
20: import java.io.ObjectInput;
21: import java.io.ObjectInputStream;
22: import java.io.ObjectOutput;
23: import java.io.ObjectOutputStream;
24:
25: import de.odysseus.el.tree.Tree;
26: import de.odysseus.el.tree.impl.Builder;
27:
28: public abstract class TestCase extends junit.framework.TestCase {
29: protected static final Builder BUILDER = new Builder();
30:
31: protected static final Tree parse(String expression) {
32: return BUILDER.build(expression);
33: }
34:
35: protected static byte[] serialize(Object value) throws Exception {
36: ByteArrayOutputStream bout = new ByteArrayOutputStream();
37: ObjectOutput out = new ObjectOutputStream(bout);
38: out.writeObject(value);
39: out.close();
40: return bout.toByteArray();
41: }
42:
43: protected static Object deserialize(byte[] bytes) throws Exception {
44: ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
45: ObjectInput in = new ObjectInputStream(bin);
46: return in.readObject();
47: }
48: }
|