01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14: * License for the specific language governing permissions and limitations under
15: * the License.
16: */
17: package org.apache.cocoon.components.flow.java.test;
18:
19: import junit.framework.TestCase;
20:
21: import org.apache.cocoon.components.flow.java.Continuation;
22: import org.apache.cocoon.components.flow.java.ContinuationClassLoader;
23:
24: public class InheritanceFlowTest extends TestCase {
25:
26: public InheritanceFlowTest(String s) {
27: super (s);
28: }
29:
30: static public void main(String args[]) {
31: try {
32: testSimpleContinuable();
33: System.out.println("SimpleContinuable test done");
34: testExtendedContinuable();
35: System.out.println("ExtendedContinuable test done");
36: testWrapperContinuable();
37: System.out.println("Wrapper continuable test done");
38: } catch (Throwable e) {
39: e.printStackTrace();
40: }
41: }
42:
43: public static void testSimpleContinuable() throws Exception {
44: ContinuationClassLoader cl = new ContinuationClassLoader(Thread
45: .currentThread().getContextClassLoader());
46: Continuation continuation = new Continuation(null);
47: continuation.registerThread();
48: Class clazz = cl
49: .loadClass("org.apache.cocoon.components.flow.java.test.SimpleContinuable");
50: Object object = clazz.newInstance();
51: clazz.getMethod("suspend", null).invoke(object, null);
52: if (continuation.isCapturing())
53: continuation.getStack().popReference();
54: continuation = new Continuation(continuation, null);
55: continuation.registerThread();
56: clazz.getMethod("suspend", null).invoke(object, null);
57: }
58:
59: public static void testWrapperContinuable() throws Exception {
60: ContinuationClassLoader cl = new ContinuationClassLoader(Thread
61: .currentThread().getContextClassLoader());
62: Continuation continuation = new Continuation(null);
63: continuation.registerThread();
64: Class clazz = cl
65: .loadClass("org.apache.cocoon.components.flow.java.test.WrapperContinuable");
66: Object object = clazz.newInstance();
67: clazz.getMethod("test", null).invoke(object, null);
68: if (continuation.isCapturing())
69: continuation.getStack().popReference();
70: continuation = new Continuation(continuation, null);
71: continuation.registerThread();
72: clazz.getMethod("test", null).invoke(object, null);
73: }
74:
75: public static void testExtendedContinuable() throws Exception {
76: ContinuationClassLoader cl = new ContinuationClassLoader(Thread
77: .currentThread().getContextClassLoader());
78: Continuation continuation = new Continuation(null);
79: continuation.registerThread();
80: Class clazz = cl
81: .loadClass("org.apache.cocoon.components.flow.java.test.ExtendedContinuable");
82: Object object = clazz.newInstance();
83: clazz.getMethod("test", null).invoke(object, null);
84: if (continuation.isCapturing())
85: continuation.getStack().popReference();
86: continuation = new Continuation(continuation, null);
87: continuation.registerThread();
88: clazz.getMethod("test", null).invoke(object, null);
89: }
90: }
|