KickJava   Java API By Example, From Geeks To Geeks.

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


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.Type;
28 import org.objectweb.fractal.api.factory.GenericFactory;
29 import org.objectweb.fractal.api.factory.InstantiationException;
30 import org.objectweb.fractal.api.type.InterfaceType;
31 import org.objectweb.fractal.api.type.TypeFactory;
32
33 import org.objectweb.fractal.julia.conform.components.I;
34
35 import org.objectweb.fractal.util.Fractal;
36
37 import junit.framework.TestCase;
38
39 public class TestTypeFactory extends TestCase {
40
41   protected Component boot;
42   protected TypeFactory tf;
43   protected GenericFactory gf;
44
45   // -------------------------------------------------------------------------
46
// Constructor ans setup
47
// -------------------------------------------------------------------------
48

49   public TestTypeFactory (final String JavaDoc name) {
50     super(name);
51   }
52
53   protected void setUp () throws Exception JavaDoc {
54     boot = Fractal.getBootstrapComponent();
55     tf = Fractal.getTypeFactory(boot);
56     gf = Fractal.getGenericFactory(boot);
57   }
58
59   // -------------------------------------------------------------------------
60
// Test interface types
61
// -------------------------------------------------------------------------
62

63   public void testInterfaceType () throws Exception JavaDoc {
64     tf.createFcItfType("i", I.class.getName(), false, false, false);
65     tf.createFcItfType("i", I.class.getName(), true, false, false);
66   }
67
68   public void testNoSuchClass () {
69     try {
70       // no such class
71
Type t = tf.createFcItfType("i", "xyz", false, false, false);
72       gf.newFcInstance(t, "composite", null);
73       fail();
74     } catch (InstantiationException JavaDoc e) {
75     }
76   }
77
78   public void testNotAnInterface () {
79     try {
80       // not an interface
81
Type t = tf.createFcItfType("i", TestTypeFactory.class.getName(), false, false, false);
82       gf.newFcInstance(t, "composite", null);
83       fail();
84     } catch (InstantiationException JavaDoc e) {
85     }
86   }
87
88   // -------------------------------------------------------------------------
89
// Test component types
90
// -------------------------------------------------------------------------
91

92   public void testComponentType () throws Exception JavaDoc {
93     InterfaceType sType =
94       tf.createFcItfType("s", I.class.getName(), false, false, false);
95     InterfaceType i1Type =
96       tf.createFcItfType("i1", I.class.getName(), true, false, false);
97     InterfaceType i2Type =
98       tf.createFcItfType("i2", I.class.getName(), true, false, false);
99     tf.createFcType(null);
100     tf.createFcType(new InterfaceType[] { sType });
101     tf.createFcType(new InterfaceType[] { i1Type, i2Type });
102     tf.createFcType(new InterfaceType[] { sType, i1Type, i2Type });
103   }
104
105   public void testBadPrefixes () {
106     try {
107       // bad prefixes
108
tf.createFcType(
109         new InterfaceType[] {
110           tf.createFcItfType("i", I.class.getName(), false, false, false),
111           tf.createFcItfType("i", I.class.getName(), true, false, false)
112         });
113       fail();
114     } catch (InstantiationException JavaDoc e) {
115     }
116     try {
117       // bad prefixes
118
tf.createFcType(
119         new InterfaceType[] {
120           tf.createFcItfType("i", I.class.getName(), true, true, true),
121           tf.createFcItfType("ij", I.class.getName(), true, true, true)
122         });
123       fail();
124     } catch (InstantiationException JavaDoc e) {
125     }
126   }
127 }
128
Popular Tags