KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > repository > DynamicityTests


1 package org.objectweb.kilim.repository;
2
3 import houseexample.House;
4 import houseexample.Man;
5
6 import javax.swing.JFrame JavaDoc;
7 import javax.xml.parsers.ParserConfigurationException JavaDoc;
8 import junit.framework.TestCase;
9
10 import org.objectweb.kilim.InternalException;
11 import org.objectweb.kilim.description.Slot;
12 import org.objectweb.kilim.description.TemplateDescription;
13 import org.objectweb.kilim.model.Component;
14 import org.objectweb.kilim.model.ComponentFactory;
15 import org.objectweb.kilim.model.ComponentInterface;
16 import org.objectweb.kilim.model.ComponentProperty;
17 import org.objectweb.kilim.model.ComponentSlot;
18 import org.objectweb.kilim.model.RtSingleValuePort;
19 import org.objectweb.kilim.model.mapping.DefaultMappingContext;
20 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper;
21 import org.objectweb.kilim.model.mapping.TextAreaMapper;
22 import org.objectweb.kilim.model.mapping.TreeModelMapper;
23
24 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy;
25 import org.objectweb.kilim.model.instanciation.InstanciationStrategy;
26
27 import org.objectweb.kilim.tools.KilimComponentViewer;
28 import org.objectweb.kilim.tools.KilimTemplateViewer;
29 import org.objectweb.kilim.tools.KilimTraceTreeModel;
30 import org.objectweb.kilim.tools.KilimTraceTreeViewer;
31
32 import org.xml.sax.SAXException JavaDoc;
33
34 /**
35  * @author delpiano
36  *
37  * To change this generated comment edit the template variable "typecomment":
38  * Window>Preferences>Java>Templates.
39  * To enable and disable the creation of type comments go to
40  * Window>Preferences>Java>Code Generation.
41  */

42 public class DynamicityTests extends TestCase {
43
44     private ResourceRepository rep;
45     private ResourceRepository rep1;
46
47     public DynamicityTests(String JavaDoc arg0) throws SAXException JavaDoc, ParserConfigurationException JavaDoc {
48         super(arg0);
49         
50         TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
51         rep = new ResourceRepository(parser);
52         rep.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
53         rep1 = new ResourceRepository1(parser);
54         rep1.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
55     }
56     
57     public void testManualPlug() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
58         try {
59             TemplateDescription ts0 = rep.getTemplateDescription("dynamicity/Real House");
60             Component house_component = ComponentFactory.newComponent(ts0);
61             ComponentInterface interf1 = house_component.getInterface("house");
62
63
64             TemplateDescription ts1 = rep.getTemplateDescription("dynamicity/Real Man");
65             Component man_component = ComponentFactory.newComponent(ts1);
66             ComponentInterface interf2 = man_component.getInterface("man");
67             
68             House house;
69             house = (House) interf1.getValue();
70             assertEquals(((RtSingleValuePort) interf1).hasValue(), true);
71             assertEquals(house.readBoard() , "");
72             
73             Man man ;
74             man = (Man) interf2.getValue();
75             assertEquals(((RtSingleValuePort) interf2).hasValue(), true);
76             assertEquals(man.whereILive() , null);
77             
78             ComponentSlot vstr_slt = house_component.getSlot("visitor");
79             
80             vstr_slt.plug(man_component);
81             
82             //next line is useless
83
//man = (Man) interf2.getValue();
84
assertEquals(man.whereILive() , house);
85             
86             //next line is useless
87
//house = (House) interf1.getValue();
88
assertEquals(house.getInhibitants().next() , man);
89             assertEquals(house.readBoard() , "It's me Toto the heroe, I'm home !");
90         
91             vstr_slt.unplug(man_component);
92             assertEquals(house.readBoard() , "It's me Toto the heroe, I'm home !Bye folks, Toto the heroe is leaving !");
93             assertEquals(man.whereILive() , null);
94                         
95         } catch (Exception JavaDoc ex) {
96             throw new InternalException(ex);
97         }
98     }
99     
100     public void testStaticPlug() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
101         try {
102             TemplateDescription ts0 = rep.getTemplateDescription("dynamicity/SimpleAssembly");
103             
104             InstanciationStrategy strgy = new DefaultInstanciationStrategy();
105             TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
106             TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
107             KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
108             Component assembly = ComponentFactory.newComponent(ts0);
109             
110             ComponentInterface interf1 = assembly.getInterface("house");
111             ComponentInterface interf2 = assembly.getInterface("man");
112                         
113             House house = (House) interf1.getValue();
114             Man man = (Man) interf2.getValue();
115             
116             assertEquals(man.whereILive() , house);
117             assertEquals(house.getInhibitants().hasNext() , true);
118             assertEquals(house.getInhibitants().next() , man);
119             assertEquals(house.readBoard() , "It's me Toto the heroe, I'm home !");
120             
121         } catch (Exception JavaDoc ex) {
122             throw new InternalException(ex);
123         }
124     }
125         
126     public void testChangePropertyValue() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
127         try {
128             TemplateDescription ts0 = rep.getTemplateDescription("dynamicity/DynamicProperty");
129             Component frame_component = ComponentFactory.newComponent(ts0);
130             ComponentInterface wndw = frame_component.getInterface("window");
131             JFrame JavaDoc frm = (JFrame JavaDoc) wndw.getValue();
132             
133             assertEquals(frm.getWidth() , 200);
134             assertEquals(frm.getHeight() , 200);
135             
136             ComponentProperty prprt = (ComponentProperty) frame_component.getInterface("x");
137             prprt.setValue(new Integer JavaDoc(500));
138
139             prprt = (ComponentProperty) frame_component.getInterface("y");
140             prprt.setValue(new Integer JavaDoc(500));
141             wndw.update();
142                                             
143             assertEquals(frm.getWidth() , 500);
144             assertEquals(frm.getHeight() , 500);
145         } catch (Exception JavaDoc ex) {
146             throw new InternalException(ex);
147         }
148     }
149 }
150
Popular Tags