1 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 s) { 26 super(s); 27 } 28 29 static public void main(String 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 e) { 38 e.printStackTrace(); 39 } 40 } 41 42 public static void testSimpleContinuable() throws Exception { 43 ContinuationClassLoader cl = new ContinuationClassLoader(Thread 44 .currentThread().getContextClassLoader()); 45 Continuation continuation = new Continuation(null); 46 continuation.registerThread(); 47 Class clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.SimpleContinuable"); 48 Object 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 { 58 ContinuationClassLoader cl = new ContinuationClassLoader(Thread 59 .currentThread().getContextClassLoader()); 60 Continuation continuation = new Continuation(null); 61 continuation.registerThread(); 62 Class clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.WrapperContinuable"); 63 Object 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 { 73 ContinuationClassLoader cl = new ContinuationClassLoader(Thread 74 .currentThread().getContextClassLoader()); 75 Continuation continuation = new Continuation(null); 76 continuation.registerThread(); 77 Class clazz = cl.loadClass("org.apache.cocoon.components.flow.java.test.ExtendedContinuable"); 78 Object 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 |