1 23 24 package org.objectweb.fractal.julia.conform; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.factory.GenericFactory; 28 import org.objectweb.fractal.api.type.TypeFactory; 29 import org.objectweb.fractal.api.type.ComponentType; 30 import org.objectweb.fractal.api.type.InterfaceType; 31 32 import org.objectweb.fractal.julia.conform.components.I; 33 import org.objectweb.fractal.julia.conform.components.C; 34 import org.objectweb.fractal.julia.conform.controllers.StatController; 35 36 import org.objectweb.fractal.util.Fractal; 37 38 public class TestInterceptor extends Test { 39 40 protected Component boot; 41 protected TypeFactory tf; 42 protected GenericFactory gf; 43 44 protected ComponentType t; 45 protected Component r, c, d; 46 47 51 public TestInterceptor (final String name) { 52 super(name); 53 } 54 55 protected void setUp () throws Exception { 56 boot = Fractal.getBootstrapComponent(); 57 tf = Fractal.getTypeFactory(boot); 58 gf = Fractal.getGenericFactory(boot); 59 t = tf.createFcType(new InterfaceType[] { 60 tf.createFcItfType("server", I.class.getName(), false, false, false), 61 tf.createFcItfType("servers", I.class.getName(), false, false, true), 62 tf.createFcItfType("client", I.class.getName(), true, true, false), 63 tf.createFcItfType("clients", I.class.getName(), true, true, true) 64 }); 65 r = gf.newFcInstance(t, "composite", null); 66 c = gf.newFcInstance(t, "statComposite", null); 67 d = gf.newFcInstance(t, "statPrimitive", C.class.getName()); 68 Fractal.getContentController(r).addFcSubComponent(c); 69 Fractal.getContentController(c).addFcSubComponent(d); 70 } 71 72 76 public void testInterceptors () throws Exception { 77 Fractal.getBindingController(d).bindFc( 78 "client", 79 d.getFcInterface("server")); 80 Fractal.getLifeCycleController(d).startFc(); 81 82 StatController sd = (StatController)d.getFcInterface("stat-controller"); 83 assertEquals(0, sd.getNumberOfMethodCalled()); 84 85 I i = (I)d.getFcInterface("server"); 86 assertEquals(3, i.n(0, (long)3)); 87 assertEquals(7, sd.getNumberOfMethodCalled()); 88 } 89 90 public void testCompositeInterceptors () throws Exception { 91 Fractal.getBindingController(c).bindFc( 92 "server", 93 d.getFcInterface("server")); 94 Fractal.getBindingController(d).bindFc( 95 "client", 96 Fractal.getContentController(c).getFcInternalInterface("client")); 97 Fractal.getBindingController(c).bindFc( 98 "client", 99 c.getFcInterface("server")); 100 Fractal.getLifeCycleController(c).startFc(); 101 102 StatController sc = (StatController)c.getFcInterface("stat-controller"); 103 StatController sd = (StatController)d.getFcInterface("stat-controller"); 104 assertEquals(0, sc.getNumberOfMethodCalled()); 105 assertEquals(0, sd.getNumberOfMethodCalled()); 106 107 I i = (I)c.getFcInterface("server"); 108 assertEquals(3, i.n(0, (long)3)); 109 assertEquals(7, sc.getNumberOfMethodCalled()); 110 assertEquals(7, sd.getNumberOfMethodCalled()); 111 } 112 113 public void testCollectionInterceptors () throws Exception { 114 Fractal.getBindingController(d).bindFc( 115 "clients0", 116 d.getFcInterface("servers0")); 117 Fractal.getLifeCycleController(d).startFc(); 118 119 StatController sd = (StatController)d.getFcInterface("stat-controller"); 120 assertEquals(0, sd.getNumberOfMethodCalled()); 121 122 I i = (I)d.getFcInterface("servers0"); 123 assertEquals(3, i.n(0, (long)3)); 124 assertEquals(7, sd.getNumberOfMethodCalled()); 125 } 126 127 public void testCollectionCompositeInterceptors () throws Exception { 128 Fractal.getBindingController(c).bindFc( 129 "servers0", 130 d.getFcInterface("servers0")); 131 Fractal.getBindingController(d).bindFc( 132 "clients0", 133 Fractal.getContentController(c).getFcInternalInterface("clients0")); 134 Fractal.getBindingController(c).bindFc( 135 "clients0", 136 c.getFcInterface("servers0")); 137 Fractal.getLifeCycleController(c).startFc(); 138 139 StatController sc = (StatController)c.getFcInterface("stat-controller"); 140 StatController sd = (StatController)d.getFcInterface("stat-controller"); 141 assertEquals(0, sc.getNumberOfMethodCalled()); 142 assertEquals(0, sd.getNumberOfMethodCalled()); 143 144 I i = (I)c.getFcInterface("servers0"); 145 assertEquals(3, i.n(0, (long)3)); 146 assertEquals(7, sc.getNumberOfMethodCalled()); 147 assertEquals(7, sd.getNumberOfMethodCalled()); 148 } 149 } 150 | Popular Tags |