KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > conform > TestInterceptor


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

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   // -------------------------------------------------------------------------
48
// Constructor ans setup
49
// -------------------------------------------------------------------------
50

51   public TestInterceptor (final String JavaDoc name) {
52     super(name);
53   }
54
55   protected void setUp () throws Exception JavaDoc {
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   // -------------------------------------------------------------------------
73
// Test interceptors
74
// -------------------------------------------------------------------------
75

76   public void testInterceptors () throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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