KickJava   Java API By Example, From Geeks To Geeks.

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


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.Interface;
28 import org.objectweb.fractal.api.NoSuchInterfaceException;
29 import org.objectweb.fractal.api.control.ContentController;
30 import org.objectweb.fractal.api.factory.GenericFactory;
31 import org.objectweb.fractal.api.type.TypeFactory;
32 import org.objectweb.fractal.api.type.ComponentType;
33 import org.objectweb.fractal.api.type.InterfaceType;
34
35 import org.objectweb.fractal.julia.conform.components.C;
36 import org.objectweb.fractal.julia.conform.components.I;
37
38 import org.objectweb.fractal.util.Fractal;
39
40 import java.util.HashSet JavaDoc;
41 import java.util.Arrays JavaDoc;
42
43 public class TestCollection extends Test {
44
45   protected Component boot;
46   protected TypeFactory tf;
47   protected GenericFactory gf;
48
49   protected ComponentType t;
50
51   protected final static String JavaDoc serverI = "server/"+PKG+".I/false,false,false";
52   protected final static String JavaDoc servers0I = "servers0/"+PKG+".I/false,false,true";
53   protected final static String JavaDoc servers1I = "servers1/"+PKG+".I/false,false,true";
54   protected final static String JavaDoc servers2I = "servers2/"+PKG+".I/true,false,true";
55   protected final static String JavaDoc servers3I = "servers3/"+PKG+".I/true,false,true";
56   protected final static String JavaDoc clientI = "client/"+PKG+".I/true,true,false";
57   protected final static String JavaDoc clients0I = "clients0/"+PKG+".I/true,true,true";
58   protected final static String JavaDoc clients1I = "clients1/"+PKG+".I/true,true,true";
59   protected final static String JavaDoc clients2I = "clients2/"+PKG+".I/false,true,true";
60   protected final static String JavaDoc clients3I = "clients3/"+PKG+".I/false,true,true";
61
62   // -------------------------------------------------------------------------
63
// Constructor ans setup
64
// -------------------------------------------------------------------------
65

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

86   public void testPrimitiveWithCollection () throws Exception JavaDoc {
87     Component c = gf.newFcInstance(t, "primitive", C.class.getName());
88     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
89       COMP, BC, LC, SC, NC, serverI, clientI
90     })));
91   }
92
93   public void testCompositeWithCollection () throws Exception JavaDoc {
94     Component c = gf.newFcInstance(t, "composite", null);
95     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
96       COMP, BC, CC, LC, SC, NC, serverI, clientI
97     })));
98   }
99
100   public void testPrimitiveTemplateWithCollection () throws Exception JavaDoc {
101     Component c = gf.newFcInstance(
102       t, "primitiveTemplate", new Object JavaDoc[] { "primitive", C.class.getName() });
103     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
104       COMP, BC, F, SC, NC, serverI, clientI
105     })));
106     c = Fractal.getFactory(c).newFcInstance();
107     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
108       COMP, BC, LC, SC, NC, serverI, clientI
109     })));
110   }
111
112   public void testCompositeTemplateWithCollection () throws Exception JavaDoc {
113     Component c = gf.newFcInstance(
114       t, "compositeTemplate", new Object JavaDoc[] { "composite", null });
115     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
116       COMP, BC, CC, F, SC, NC, serverI, clientI
117     })));
118     c = Fractal.getFactory(c).newFcInstance();
119     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
120       COMP, BC, CC, LC, SC, NC, serverI, clientI
121     })));
122   }
123
124   // -------------------------------------------------------------------------
125
// Test lazy interface creation through getFc(Internal)Interface
126
// -------------------------------------------------------------------------
127

128   public void testPrimitiveGetFcInterface () throws Exception JavaDoc {
129     Component c = gf.newFcInstance(t, "primitive", C.class.getName());
130     Fractal.getLifeCycleController(c).startFc();
131     Interface i;
132     i = (Interface)c.getFcInterface("servers0");
133     assertEquals("Bad interface", servers0I, getItf(i, false));
134     checkInterface((I)i);
135     i = (Interface)c.getFcInterface("servers1");
136     assertEquals("Bad interface", servers1I, getItf(i, false));
137     checkInterface((I)i);
138     i = (Interface)c.getFcInterface("clients0");
139     assertEquals("Bad interface", clients0I, getItf(i, false));
140     i = (Interface)c.getFcInterface("clients1");
141     assertEquals("Bad interface", clients1I, getItf(i, false));
142   }
143
144   public void testCompositeGetFcInterface () throws Exception JavaDoc {
145     Component c = gf.newFcInstance(t, "composite", null);
146     Interface i;
147     i = (Interface)c.getFcInterface("servers0");
148     assertEquals("Bad interface", servers0I, getItf(i, false));
149     i = (Interface)c.getFcInterface("servers1");
150     assertEquals("Bad interface", servers1I, getItf(i, false));
151     i = (Interface)c.getFcInterface("clients0");
152     assertEquals("Bad interface", clients0I, getItf(i, false));
153     i = (Interface)c.getFcInterface("clients1");
154     assertEquals("Bad interface", clients1I, getItf(i, false));
155
156     ContentController cc = Fractal.getContentController(c);
157     i = (Interface)cc.getFcInternalInterface("servers2");
158     assertEquals("Bad interface", servers2I, getItf(i, false));
159     i = (Interface)cc.getFcInternalInterface("servers3");
160     assertEquals("Bad interface", servers3I, getItf(i, false));
161     i = (Interface)cc.getFcInternalInterface("clients2");
162     assertEquals("Bad interface", clients2I, getItf(i, false));
163     i = (Interface)cc.getFcInternalInterface("clients3");
164     assertEquals("Bad interface", clients3I, getItf(i, false));
165   }
166
167   public void testPrimitiveTemplateGetFcInterface () throws Exception JavaDoc {
168     Component c = gf.newFcInstance(
169       t, "primitiveTemplate", new Object JavaDoc[] { "primitive", C.class.getName() });
170     Interface i;
171     i = (Interface)c.getFcInterface("servers0");
172     assertEquals("Bad interface", servers0I, getItf(i, false));
173     i = (Interface)c.getFcInterface("servers1");
174     assertEquals("Bad interface", servers1I, getItf(i, false));
175     i = (Interface)c.getFcInterface("clients0");
176     assertEquals("Bad interface", clients0I, getItf(i, false));
177     i = (Interface)c.getFcInterface("clients1");
178     assertEquals("Bad interface", clients1I, getItf(i, false));
179
180     c = Fractal.getFactory(c).newFcInstance();
181     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
182       COMP, BC, LC, SC, NC, serverI, clientI
183     })));
184   }
185
186   public void testCompositeTemplateGetFcInterface () throws Exception JavaDoc {
187     Component c = gf.newFcInstance(
188       t, "compositeTemplate", new Object JavaDoc[] { "composite", null });
189     Interface i;
190     i = (Interface)c.getFcInterface("servers0");
191     assertEquals("Bad interface", servers0I, getItf(i, false));
192     i = (Interface)c.getFcInterface("servers1");
193     assertEquals("Bad interface", servers1I, getItf(i, false));
194     i = (Interface)c.getFcInterface("clients0");
195     assertEquals("Bad interface", clients0I, getItf(i, false));
196     i = (Interface)c.getFcInterface("clients1");
197     assertEquals("Bad interface", clients1I, getItf(i, false));
198
199     ContentController cc = Fractal.getContentController(c);
200     i = (Interface)cc.getFcInternalInterface("servers2");
201     assertEquals("Bad interface", servers2I, getItf(i, false));
202     i = (Interface)cc.getFcInternalInterface("servers3");
203     assertEquals("Bad interface", servers3I, getItf(i, false));
204     i = (Interface)cc.getFcInternalInterface("clients2");
205     assertEquals("Bad interface", clients2I, getItf(i, false));
206     i = (Interface)cc.getFcInternalInterface("clients3");
207     assertEquals("Bad interface", clients3I, getItf(i, false));
208
209     c = Fractal.getFactory(c).newFcInstance();
210     checkComponent(c, new HashSet JavaDoc(Arrays.asList(new Object JavaDoc[] {
211       COMP, BC, CC, LC, SC, NC, serverI, clientI
212     })));
213   }
214
215   // -------------------------------------------------------------------------
216
// Test errors of lazy interface creation through getFc(Internal)Interface
217
// -------------------------------------------------------------------------
218

219   public void testPrimitiveNoSuchCollectionItf () throws Exception JavaDoc {
220     Component c = gf.newFcInstance(t, "primitive", C.class.getName());
221     try {
222       c.getFcInterface("server0");
223       fail();
224     } catch (NoSuchInterfaceException e) {
225     }
226     try {
227       c.getFcInterface("client0");
228       fail();
229     } catch (NoSuchInterfaceException e) {
230     }
231   }
232
233   public void testCompositeNoSuchCollectionItf () throws Exception JavaDoc {
234     Component c = gf.newFcInstance(t, "composite", null);
235     try {
236       c.getFcInterface("server0");
237       fail();
238     } catch (NoSuchInterfaceException e) {
239     }
240     try {
241       c.getFcInterface("client0");
242       fail();
243     } catch (NoSuchInterfaceException e) {
244     }
245   }
246
247   public void testPrimitiveTemplateNoSuchCollectionItf () throws Exception JavaDoc {
248     Component c = gf.newFcInstance(
249       t, "primitiveTemplate", new Object JavaDoc[] { "primitive", C.class.getName() });
250     try {
251       c.getFcInterface("server0");
252       fail();
253     } catch (NoSuchInterfaceException e) {
254     }
255     try {
256       c.getFcInterface("client0");
257       fail();
258     } catch (NoSuchInterfaceException e) {
259     }
260   }
261
262   public void testCompositeTemplateNoSuchCollectionItf () throws Exception JavaDoc {
263     Component c = gf.newFcInstance(
264       t, "compositeTemplate", new Object JavaDoc[] { "composite", null });
265     try {
266       c.getFcInterface("server0");
267       fail();
268     } catch (NoSuchInterfaceException e) {
269     }
270     try {
271       c.getFcInterface("client0");
272       fail();
273     } catch (NoSuchInterfaceException e) {
274     }
275   }
276 }
277
Popular Tags