KickJava   Java API By Example, From Geeks To Geeks.

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


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.components.CAttributes;
35
36 import org.objectweb.fractal.util.Fractal;
37
38 public class TestComponent extends Test {
39
40   protected Component boot;
41   protected TypeFactory tf;
42   protected GenericFactory gf;
43
44   protected ComponentType t;
45
46   protected final static String JavaDoc AC = "attribute-controller/"+PKG+".CAttributes/false,false,false";
47   protected final static String JavaDoc sI = "server/"+PKG+".I/false,false,false";
48   protected final static String JavaDoc cI = "client/"+PKG+".I/true,false,false";
49
50   // -------------------------------------------------------------------------
51
// Constructor ans setup
52
// -------------------------------------------------------------------------
53

54   public TestComponent (final String JavaDoc name) {
55     super(name);
56   }
57
58   protected void setUp () throws Exception JavaDoc {
59     boot = Fractal.getBootstrapComponent();
60     tf = Fractal.getTypeFactory(boot);
61     gf = Fractal.getGenericFactory(boot);
62     t = tf.createFcType(new InterfaceType[] {
63       tf.createFcItfType("attribute-controller", CAttributes.class.getName(), false, false, false),
64       tf.createFcItfType("server", I.class.getName(), false, false, false),
65       tf.createFcItfType("client", I.class.getName(), true, true, false)
66     });
67   }
68
69   // -------------------------------------------------------------------------
70
// Test functional and attribute controller interfaces
71
// -------------------------------------------------------------------------
72

73   public void testParametricPrimitive () throws Exception JavaDoc {
74     Component c = gf.newFcInstance(t, "parametricPrimitive", C.class.getName());
75     Fractal.getLifeCycleController(c).startFc();
76     I i = (I)c.getFcInterface("server");
77     checkInterface(i);
78
79     CAttributes ca = (CAttributes)c.getFcInterface("attribute-controller");
80     ca.setX1(true);
81     assertEquals(true, ca.getX1());
82     ca.setX2((byte)1);
83     assertEquals((byte)1, ca.getX2());
84     ca.setX3((char)1);
85     assertEquals((char)1, ca.getX3());
86     ca.setX4((short)1);
87     assertEquals((short)1, ca.getX4());
88     ca.setX5((int)1);
89     assertEquals((int)1, ca.getX5());
90     ca.setX6(1);
91     assertEquals((long)1, ca.getX6());
92     ca.setX7(1);
93     assertEquals((float)1, ca.getX7(), 0);
94     ca.setX8(1);
95     assertEquals((double)1, ca.getX8(), 0);
96     ca.setX9("1");
97     assertEquals("1", ca.getX9());
98     ca.setWriteOnlyX11(true);
99     assertEquals(true, i.n(false, null));
100   }
101
102   public void testParametricPrimitiveTemplate () throws Exception JavaDoc {
103     Component c = gf.newFcInstance(
104       t, "parametricPrimitiveTemplate", new Object JavaDoc[] { "parametricPrimitive", C.class.getName() });
105
106     CAttributes ca = (CAttributes)c.getFcInterface("attribute-controller");
107     ca.setX1(true);
108     ca.setX2((byte)1);
109     ca.setX3((char)1);
110     ca.setX4((short)1);
111     ca.setX5((int)1);
112     ca.setX6(1);
113     ca.setX7(1);
114     ca.setX8(1);
115     ca.setX9("1");
116     ca.setWriteOnlyX11(true);
117
118     c = Fractal.getFactory(c).newFcInstance();
119     Fractal.getLifeCycleController(c).startFc();
120     ca = (CAttributes)c.getFcInterface("attribute-controller");
121
122     assertEquals(true, ca.getX1());
123     assertEquals((byte)1, ca.getX2());
124     assertEquals((char)1, ca.getX3());
125     assertEquals((short)1, ca.getX4());
126     assertEquals((int)1, ca.getX5());
127     assertEquals((long)1, ca.getX6());
128     assertEquals((float)1, ca.getX7(), 0);
129     assertEquals((double)1, ca.getX8(), 0);
130     assertEquals("1", ca.getX9());
131     assertEquals(true, ((I)c.getFcInterface("server")).n(false, null));
132   }
133 }
134
Popular Tags