KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > flow > java > test > InheritanceFlowTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package org.apache.cocoon.components.flow.java.test;
17
18 import junit.framework.TestCase;
19
20 import org.apache.cocoon.components.flow.java.Continuation;
21 import org.apache.cocoon.components.flow.java.ContinuationClassLoader;
22
23 public class InheritanceFlowTest extends TestCase {
24     
25     public InheritanceFlowTest(String JavaDoc s) {
26         super(s);
27     }
28
29     static public void main(String JavaDoc args[]) {
30         try {
31             testSimpleContinuable();
32             System.out.println("SimpleContinuable test done");
33             testExtendedContinuable();
34             System.out.println("ExtendedContinuable test done");
35             testWrapperContinuable();
36             System.out.println("Wrapper continuable test done");
37         } catch (Throwable JavaDoc e) {
38             e.printStackTrace();
39         }
40     }
41
42     public static void testSimpleContinuable() throws Exception JavaDoc {
43         ContinuationClassLoader cl = new ContinuationClassLoader(Thread
44                 .currentThread().getContextClassLoader());
45         Continuation continuation = new Continuation(null);
46         continuation.registerThread();
47         Class JavaDoc clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.SimpleContinuable");
48         Object JavaDoc object = clazz.newInstance();
49         clazz.getMethod("suspend", null).invoke(object, null);
50         if (continuation.isCapturing())
51             continuation.getStack().popReference();
52         continuation = new Continuation(continuation, null);
53         continuation.registerThread();
54         clazz.getMethod("suspend", null).invoke(object, null);
55     }
56
57     public static void testWrapperContinuable() throws Exception JavaDoc {
58         ContinuationClassLoader cl = new ContinuationClassLoader(Thread
59                 .currentThread().getContextClassLoader());
60         Continuation continuation = new Continuation(null);
61         continuation.registerThread();
62         Class JavaDoc clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.WrapperContinuable");
63         Object JavaDoc object = clazz.newInstance();
64         clazz.getMethod("test", null).invoke(object, null);
65                 if (continuation.isCapturing())
66             continuation.getStack().popReference();
67         continuation = new Continuation(continuation, null);
68         continuation.registerThread();
69         clazz.getMethod("test", null).invoke(object, null);
70     }
71
72     public static void testExtendedContinuable() throws Exception JavaDoc {
73         ContinuationClassLoader cl = new ContinuationClassLoader(Thread
74                 .currentThread().getContextClassLoader());
75         Continuation continuation = new Continuation(null);
76         continuation.registerThread();
77         Class JavaDoc clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.ExtendedContinuable");
78         Object JavaDoc object = clazz.newInstance();
79         clazz.getMethod("test", null).invoke(object, null);
80                 if (continuation.isCapturing())
81             continuation.getStack().popReference();
82         continuation = new Continuation(continuation, null);
83         continuation.registerThread();
84         clazz.getMethod("test", null).invoke(object, null);
85     }
86 }
87
Popular Tags