KickJava   Java API By Example, From Geeks To Geeks.

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


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.type.InterfaceType;
30 import org.objectweb.fractal.api.control.ContentController;
31
32 import org.objectweb.fractal.julia.conform.components.I;
33
34 import org.objectweb.fractal.util.Fractal;
35
36 import junit.framework.TestCase;
37
38 import java.util.Set JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.HashSet JavaDoc;
41
42 public class Test extends TestCase {
43
44   protected final static String JavaDoc COMP = "component/org.objectweb.fractal.api.Component/false,false,false";
45   protected final static String JavaDoc BC = "binding-controller/org.objectweb.fractal.api.control.BindingController/false,false,false";
46   protected final static String JavaDoc LC = "lifecycle-controller/org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator/false,false,false";
47   protected final static String JavaDoc CC = "content-controller/org.objectweb.fractal.api.control.ContentController/false,false,false";
48   protected final static String JavaDoc SC = "super-controller/org.objectweb.fractal.julia.control.content.SuperControllerNotifier/false,false,false";
49   protected final static String JavaDoc NC = "name-controller/org.objectweb.fractal.api.control.NameController/false,false,false";
50   protected final static String JavaDoc F = "factory/org.objectweb.fractal.julia.factory.Template/false,false,false";
51
52   protected final static String JavaDoc PKG = "org.objectweb.fractal.julia.conform.components";
53
54   public Test (final String JavaDoc name) {
55     super(name);
56   }
57
58   protected void checkInterface (I i) {
59     i.m(true);
60     i.m((byte)1);
61     i.m((char)1);
62     i.m((short)1);
63     i.m((int)1);
64     i.m((long)1);
65     i.m((float)1);
66     i.m((double)1);
67     i.m("1");
68     i.m(new String JavaDoc[] { "1" });
69
70     assertEquals(true, i.n(true, null));
71     assertEquals((byte)1, i.n((byte)1, null));
72     assertEquals((char)1, i.n((char)1, (double)0));
73     assertEquals((short)1, i.n((short)1, (float)0));
74     assertEquals((int)1, i.n((int)1, (long)0));
75     assertEquals((long)1, i.n((long)1, (int)0));
76     assertEquals((float)1, i.n((float)1, (short)0), 0);
77     assertEquals((double)1, i.n((double)1, (char)0), 0);
78     assertEquals("1", i.n("1", (byte)0));
79   }
80
81   protected void checkComponent (Component c, Set JavaDoc itfs) throws Exception JavaDoc {
82     Set JavaDoc extItfs = getExternalItfs(c);
83     assertEquals("Wrong external interface list", itfs, extItfs);
84     Iterator JavaDoc i = itfs.iterator();
85     while (i.hasNext()) {
86       String JavaDoc itf = (String JavaDoc)i.next();
87       String JavaDoc compItf = null;
88       try {
89         compItf = getItf((Interface)c.getFcInterface(getItfName(itf)), false);
90       } catch (NoSuchInterfaceException e) {
91         fail("Missing external interface: " + itf);
92       }
93       assertEquals("Wrong external interface", itf, compItf);
94     }
95
96     ContentController cc;
97     try {
98       cc = Fractal.getContentController(c);
99     } catch (NoSuchInterfaceException e) {
100       return;
101     }
102
103     itfs = new HashSet JavaDoc(itfs);
104     i = itfs.iterator();
105     while (i.hasNext()) {
106       String JavaDoc itf = (String JavaDoc)i.next();
107       if (itf.startsWith("component/") || itf.indexOf("-controller/") != -1) {
108         i.remove();
109       }
110     }
111
112     Set JavaDoc intItfs = getInternalItfs(cc);
113     assertEquals("Wrong internal interface list", itfs, intItfs);
114     i = itfs.iterator();
115     while (i.hasNext()) {
116       String JavaDoc itf = (String JavaDoc)i.next();
117       String JavaDoc compItf = null;
118       try {
119         compItf = getItf((Interface)cc.getFcInternalInterface(getItfName(itf)), true);
120       } catch (NoSuchInterfaceException e) {
121         fail("Missing internal interface: " + itf);
122       }
123       assertEquals("Wrong internal interface", itf, compItf);
124     }
125   }
126
127   private Set JavaDoc getExternalItfs (Component c) {
128     HashSet JavaDoc result = new HashSet JavaDoc();
129     Object JavaDoc[] extItfs = c.getFcInterfaces();
130     for (int i = 0; i < extItfs.length; ++i) {
131       String JavaDoc itf = getItf((Interface)extItfs[i], false);
132       if (!result.add(itf)) {
133         fail("Duplicated interface: " + itf);
134       }
135     }
136     return result;
137   }
138
139   private Set JavaDoc getInternalItfs (ContentController cc) {
140     HashSet JavaDoc result = new HashSet JavaDoc();
141     Object JavaDoc[] extItfs = cc.getFcInternalInterfaces();
142     for (int i = 0; i < extItfs.length; ++i) {
143       String JavaDoc itf = getItf((Interface)extItfs[i], true);
144       if (!result.add(itf)) {
145         fail("Duplicated interface: " + itf);
146       }
147     }
148     return result;
149   }
150
151   protected static String JavaDoc getItf (Interface itf, boolean internal) {
152     InterfaceType itfType = (InterfaceType)itf.getFcItfType();
153     return getItf(
154       itf.getFcItfName(),
155       itfType.getFcItfSignature(),
156       itfType.isFcClientItf() ^ internal,
157       itfType.isFcOptionalItf(),
158       itfType.isFcCollectionItf());
159   }
160
161   private static String JavaDoc getItf (
162     String JavaDoc name,
163     String JavaDoc signature,
164     boolean isClient,
165     boolean isOptional,
166     boolean isCollection)
167   {
168     return name+'/'+signature+'/'+isClient+','+isOptional+','+isCollection;
169   }
170
171   private static String JavaDoc getItfName (String JavaDoc itf) {
172     return itf.substring(0, itf.indexOf('/'));
173   }
174 }
175
Popular Tags