KickJava   Java API By Example, From Geeks To Geeks.

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


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.factory.InstantiationException;
29 import org.objectweb.fractal.api.type.TypeFactory;
30 import org.objectweb.fractal.api.type.InterfaceType;
31 import org.objectweb.fractal.api.type.ComponentType;
32
33 import org.objectweb.fractal.julia.conform.components.C;
34 import org.objectweb.fractal.julia.conform.components.I;
35 import org.objectweb.fractal.julia.conform.components.W;
36 import org.objectweb.fractal.julia.conform.components.X;
37 import org.objectweb.fractal.julia.conform.components.Y;
38 import org.objectweb.fractal.julia.conform.components.Z;
39 import org.objectweb.fractal.julia.conform.components.CAttributes;
40
41 import org.objectweb.fractal.util.Fractal;
42
43 import java.util.HashSet JavaDoc;
44 import java.util.Arrays JavaDoc;
45
46 public class TestGenericFactory extends Test {
47
48   protected Component boot;
49   protected TypeFactory tf;
50   protected GenericFactory gf;
51
52   protected ComponentType t, u;
53
54   protected final static String JavaDoc AC = "attribute-controller/"+PKG+".CAttributes/false,false,false";
55   protected final static String JavaDoc sI = "server/"+PKG+".I/false,false,false";
56   protected final static String JavaDoc cI = "client/"+PKG+".I/true,false,false";
57
58   // -------------------------------------------------------------------------
59
// Constructor ans setup
60
// -------------------------------------------------------------------------
61

62   public TestGenericFactory (final String JavaDoc name) {
63     super(name);
64   }
65
66   protected void setUp () throws Exception JavaDoc {
67     boot = Fractal.getBootstrapComponent();
68     tf = Fractal.getTypeFactory(boot);
69     gf = Fractal.getGenericFactory(boot);
70     t = tf.createFcType(new InterfaceType[] {
71       tf.createFcItfType("server", I.class.getName(), false, false, false),
72       tf.createFcItfType("client", I.class.getName(), true, false, false)
73     });
74     u = tf.createFcType(new InterfaceType[] {
75       tf.createFcItfType("attribute-controller", CAttributes.class.getName(), false, false, false),
76       tf.createFcItfType("server", I.class.getName(), false, false, false),
77       tf.createFcItfType("client", I.class.getName(), true, false, false)
78     });
79   }
80
81   // -------------------------------------------------------------------------
82
// Test direct component creation
83
// -------------------------------------------------------------------------
84

85   public void testFPrimitive () throws Exception JavaDoc {
86     Component c = gf.newFcInstance(t, "flatPrimitive", C.class.getName());
87     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
88       COMP, BC, LC, NC, sI, cI
89     })));
90   }
91
92   public void testFParametricPrimitive () throws Exception JavaDoc {
93     Component c = gf.newFcInstance(u, "flatParametricPrimitive", C.class.getName());
94     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
95       COMP, BC, LC, AC, NC, sI, cI
96     })));
97   }
98
99   public void testPrimitive () throws Exception JavaDoc {
100     Component c = gf.newFcInstance(t, "primitive", C.class.getName());
101     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
102       COMP, BC, LC, SC, NC, sI, cI
103     })));
104   }
105
106   public void testParametricPrimitive () throws Exception JavaDoc {
107     Component c = gf.newFcInstance(u, "parametricPrimitive", C.class.getName());
108     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
109       COMP, BC, LC, SC, AC, NC, sI, cI
110     })));
111   }
112
113   public void testComposite () throws Exception JavaDoc {
114     Component c = gf.newFcInstance(t, "composite", null);
115     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
116       COMP, BC, CC, LC, SC, NC, sI, cI
117     })));
118   }
119
120   public void testParametricComposite () throws Exception JavaDoc {
121     Component c = gf.newFcInstance(u, "parametricComposite", C.class.getName());
122     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
123       COMP, BC, CC, LC, SC, AC, NC, sI, cI
124     })));
125   }
126
127   // -------------------------------------------------------------------------
128
// Test component creation via templates
129
// -------------------------------------------------------------------------
130

131   public void testFPrimitiveTemplate () throws Exception JavaDoc {
132     Component c = gf.newFcInstance(
133       t, "flatPrimitiveTemplate", new Object JavaDoc[] { "flatPrimitive", C.class.getName() });
134     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
135       COMP, BC, F, NC, sI, cI
136     })));
137     c = Fractal.getFactory(c).newFcInstance();
138     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
139       COMP, BC, LC, NC, sI, cI
140     })));
141   }
142
143   public void testFParametricPrimitiveTemplate () throws Exception JavaDoc {
144     Component c = gf.newFcInstance(
145       u, "flatParametricPrimitiveTemplate", new Object JavaDoc[] { "flatParametricPrimitive", C.class.getName() });
146     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
147       COMP, BC, F, AC, NC, sI, cI
148     })));
149     c = Fractal.getFactory(c).newFcInstance();
150     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
151       COMP, BC, LC, AC, NC, sI, cI
152     })));
153   }
154
155   public void testPrimitiveTemplate () throws Exception JavaDoc {
156     Component c = gf.newFcInstance(
157       t, "primitiveTemplate", new Object JavaDoc[] { "primitive", C.class.getName() });
158     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
159       COMP, BC, F, SC, NC, sI, cI
160     })));
161     c = Fractal.getFactory(c).newFcInstance();
162     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
163       COMP, BC, LC, SC, NC, sI, cI
164     })));
165   }
166
167   public void testParametricPrimitiveTemplate () throws Exception JavaDoc {
168     Component c = gf.newFcInstance(
169       u, "parametricPrimitiveTemplate", new Object JavaDoc[] { "parametricPrimitive", C.class.getName() });
170     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
171       COMP, BC, F, SC, AC, NC, sI, cI
172     })));
173     c = Fractal.getFactory(c).newFcInstance();
174     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
175       COMP, BC, LC, SC, AC, NC, sI, cI
176     })));
177   }
178
179   public void testCompositeTemplate () throws Exception JavaDoc {
180     Component c = gf.newFcInstance(
181       t, "compositeTemplate", new Object JavaDoc[] { "composite", null });
182     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
183       COMP, BC, CC, F, SC, NC, sI, cI
184     })));
185     c = Fractal.getFactory(c).newFcInstance();
186     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
187       COMP, BC, CC, LC, SC, NC, sI, cI
188     })));
189   }
190
191   public void testParametricCompositeTemplate () throws Exception JavaDoc {
192     Component c = gf.newFcInstance(
193       u, "parametricCompositeTemplate", new Object JavaDoc[] { "parametricComposite", C.class.getName() });
194     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
195       COMP, BC, CC, F, SC, AC, NC, sI, cI
196     })));
197     c = Fractal.getFactory(c).newFcInstance();
198     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
199       COMP, BC, CC, LC, SC, AC, NC, sI, cI
200     })));
201   }
202
203   // -------------------------------------------------------------------------
204
// Test component creation errors
205
// -------------------------------------------------------------------------
206

207   public void testUnknownControllerDescriptor () throws Exception JavaDoc {
208     try {
209       // no such controller descriptor
210
gf.newFcInstance(t, "unknownDescriptor", C.class.getName());
211       fail();
212     } catch (InstantiationException JavaDoc e) {
213     }
214   }
215
216   public void testBadControllerDescriptor1 () throws Exception JavaDoc {
217     try {
218       // error in controller descriptor
219
gf.newFcInstance(t, "badPrimitive", C.class.getName());
220       fail();
221     } catch (InstantiationException JavaDoc e) {
222     }
223   }
224
225   public void testBadControllerDescriptor2 () throws Exception JavaDoc {
226     try {
227       // error in controller descriptor
228
gf.newFcInstance(u, "badParametricPrimitive", C.class.getName());
229       fail();
230     } catch (InstantiationException JavaDoc e) {
231     }
232   }
233
234   public void testContentClassNotFound () throws Exception JavaDoc {
235     try {
236       // no such class
237
gf.newFcInstance(t, "primitive", "UnknownClass");
238       fail();
239     } catch (InstantiationException JavaDoc e) {
240     }
241   }
242
243   public void testContentClassAbstract () throws Exception JavaDoc {
244     try {
245       // X is an abstract class
246
gf.newFcInstance(t, "primitive", W.class.getName());
247       fail();
248     } catch (InstantiationException JavaDoc e) {
249     }
250   }
251
252   public void testContentClassNoDefaultConstructor () throws Exception JavaDoc {
253     try {
254       // X has no public constructor
255
gf.newFcInstance(t, "primitive", X.class.getName());
256       fail();
257     } catch (InstantiationException JavaDoc e) {
258     }
259   }
260
261   public void testContentClassControlInterfaceMissing () throws Exception JavaDoc {
262     try {
263       // Y does not implement BindingController
264
gf.newFcInstance(t, "primitive", Y.class.getName());
265       fail();
266     } catch (InstantiationException JavaDoc e) {
267     }
268   }
269
270   public void testContentClassInterfaceMissing () throws Exception JavaDoc {
271     try {
272       // Z does not implement I
273
gf.newFcInstance(t, "primitive", Z.class.getName());
274       fail();
275     } catch (InstantiationException JavaDoc e) {
276     }
277   }
278
279   public void testTemplateContentClassNotFound () throws Exception JavaDoc {
280     try {
281       // no such class
282
gf.newFcInstance(
283         t, "primitiveTemplate", new Object JavaDoc[] { "primitive", "UnknownClass" });
284       fail();
285     } catch (InstantiationException JavaDoc e) {
286     }
287   }
288
289   public void testTemplateContentClassAbstract () throws Exception JavaDoc {
290     try {
291       // X is an abstract class
292
gf.newFcInstance(
293         t, "primitiveTemplate", new Object JavaDoc[] { "primitive", W.class.getName() });
294       fail();
295     } catch (InstantiationException JavaDoc e) {
296     }
297   }
298
299   public void testTemplateContentClassNoDefaultConstructor () throws Exception JavaDoc {
300     try {
301       // X has no public constructor
302
gf.newFcInstance(
303         t, "primitiveTemplate", new Object JavaDoc[] { "primitive", X.class.getName() });
304       fail();
305     } catch (InstantiationException JavaDoc e) {
306     }
307   }
308
309   public void testTemplateContentClassControlInterfaceMissing () throws Exception JavaDoc {
310     try {
311       // Y does not implement BindingController
312
gf.newFcInstance(
313         t, "primitiveTemplate", new Object JavaDoc[] { "primitive", Y.class.getName() });
314       fail();
315     } catch (InstantiationException JavaDoc e) {
316     }
317   }
318
319   public void testTemplateContentClassInterfaceMissing () throws Exception JavaDoc {
320     try {
321       // Z does not implement I
322
gf.newFcInstance(
323         t, "primitiveTemplate", new Object JavaDoc[] { "primitive", Z.class.getName() });
324       fail();
325     } catch (InstantiationException JavaDoc e) {
326     }
327   }
328 }
329
Popular Tags