KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.kilim.repository;
19
20 import javax.swing.JTextArea JavaDoc;
21 import javax.xml.parsers.ParserConfigurationException JavaDoc;
22 import junit.framework.TestCase;
23
24 import org.objectweb.kilim.InternalException;
25 import org.objectweb.kilim.description.TemplateDescription;
26 import org.objectweb.kilim.model.Component;
27 import org.objectweb.kilim.model.ComponentFactory;
28 import org.objectweb.kilim.model.ComponentInterface;
29
30 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy;
31 import org.objectweb.kilim.model.instanciation.InstanciationStrategy;
32 import org.objectweb.kilim.model.instanciation.NullInstanciationMger;
33
34 import org.objectweb.kilim.model.mapping.DefaultMappingContext;
35 import org.objectweb.kilim.model.mapping.NullMapper;
36 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper;
37 import org.objectweb.kilim.model.mapping.TextAreaMapper;
38 import org.objectweb.kilim.model.mapping.TreeModelMapper;
39
40 import org.objectweb.kilim.tools.KilimTemplateViewer;
41 import org.objectweb.kilim.tools.KilimTraceTreeModel;
42 import org.objectweb.kilim.tools.KilimTraceTreeViewer;
43
44 import org.xml.sax.SAXException JavaDoc;
45
46 /**
47  * @author delpiano
48  *
49  * To change this generated comment edit the template variable "typecomment":
50  * Window>Preferences>Java>Templates.
51  * To enable and disable the creation of type comments go to
52  * Window>Preferences>Java>Code Generation.
53  */

54 public class WritersTest extends TestCase {
55
56     private ResourceRepository rep;
57     private ResourceRepository rep1;
58
59     /**
60      * Constructor for TemplateParserTest.
61      * @param arg0 for junit
62      * @throws SAXException should not happen
63      * @throws ParserConfigurationException should not happen
64      */

65     public WritersTest(String JavaDoc arg0) throws SAXException JavaDoc, ParserConfigurationException JavaDoc {
66         super(arg0);
67         TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
68         rep = new ResourceRepository(parser);
69         rep.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
70         rep1 = new ResourceRepository1(parser);
71         rep1.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
72     }
73
74     /**
75      * Method testParsing3.
76      * @throws ResourceNotFoundException :
77      * @throws SAXException :
78      * @throws ParserConfigurationException :
79      */

80     public void testProvidingPortWithInstanciationWithoutArgument() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
81         try {
82             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV1");
83             //KilimTemplateViewer.viewTemplate(ts0);
84
Component compo = ComponentFactory.newComponent(ts0);
85             ComponentInterface interf = compo.getInterface("writer");
86             Object JavaDoc res = interf.getValue();
87             assertEquals(((writers.Writer) res).getString(), "a word");
88         } catch (Exception JavaDoc ex) {
89             throw new InternalException(ex);
90         }
91     }
92     
93     /**
94      * Method testParsing4.
95      * @throws ResourceNotFoundException :
96      * @throws SAXException :
97      * @throws ParserConfigurationException :
98      */

99     public void testProvidingPortWithProviderWithoutArgument() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
100         try {
101             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV2");
102             Component compo = ComponentFactory.newComponent(ts0);
103             ComponentInterface interf = compo.getInterface("writer");
104             Object JavaDoc res = interf.getValue();
105             assertEquals(((writers.Writer) res).getString(), "a word");
106         } catch (Exception JavaDoc ex) {
107             throw new InternalException(ex);
108         }
109     }
110     
111     /**
112      * Method testParsing5.
113      * @throws ResourceNotFoundException :
114      * @throws SAXException :
115      * @throws ParserConfigurationException :
116      */

117     public void testProvidingPortWithInstanciationWithArgument() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
118         try {
119             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV3");
120             Component compo = ComponentFactory.newComponent(ts0);
121             ComponentInterface interf = compo.getInterface("writer");
122             Object JavaDoc res = interf.getValue();
123             assertEquals(((writers.Writer) res).getString(), "new word");
124             
125         } catch (Exception JavaDoc ex) {
126             throw new InternalException(ex);
127         }
128     }
129
130     /**
131      * Method testParsing6.
132      * @throws ResourceNotFoundException :
133      * @throws SAXException :
134      * @throws ParserConfigurationException :
135      */

136     public void testProvidingPortWithInstanciationWithArgument2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
137         try {
138             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterFrancois");
139             Component compo = ComponentFactory.newComponent(ts0);
140             ComponentInterface interf = compo.getInterface("writer");
141             Object JavaDoc res = interf.getValue();
142             assertEquals(((writers.Writer) res).getString(), "Francois");
143         } catch (Exception JavaDoc ex) {
144             throw new InternalException(ex);
145         }
146     }
147
148     /**
149      * Method testParsing7.
150      * @throws ResourceNotFoundException :
151      * @throws SAXException :
152      * @throws ParserConfigurationException :
153      */

154     public void testPortProvidedByInstanciationAndSetByTrigger() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
155         try {
156             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEst");
157             //KilimTemplateViewer.viewTemplate(ts0);
158
Component compo = ComponentFactory.newComponent(ts0);
159             ComponentInterface interf = compo.getInterface("writer");
160             Object JavaDoc res = interf.getValue();
161             assertEquals(((writers.Writer) res).getString(), "est");
162         } catch (Exception JavaDoc ex) {
163             throw new InternalException(ex);
164         }
165     }
166
167     /**
168      * Method testParsing18.
169      * @throws ResourceNotFoundException :
170      * @throws SAXException :
171      * @throws ParserConfigurationException :
172      */

173     public void testPortProvidedByInstanciationAndSetByTriggerWithDirectFieldAccess() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
174         try {
175             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEstV2");
176             Component compo = ComponentFactory.newComponent(ts0);
177             ComponentInterface interf = compo.getInterface("writer");
178             Object JavaDoc res = interf.getValue();
179             assertEquals(((writers.Writer) res).getString(), "est");
180         } catch (Exception JavaDoc ex) {
181             throw new InternalException(ex);
182         }
183     }
184     
185     /**
186      * Method testParsing9.
187      * @throws ResourceNotFoundException :
188      * @throws SAXException :
189      * @throws ParserConfigurationException :
190      */

191     public void testPortProvidedByInstanciationAndSetByTriggerWithSetterInvocation() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
192         try {
193             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEstV3");
194             Component compo = ComponentFactory.newComponent(ts0);
195             ComponentInterface interf = compo.getInterface("writer");
196             Object JavaDoc res = interf.getValue();
197             assertEquals(((writers.Writer) res).getString(), "est");
198         } catch (Exception JavaDoc ex) {
199             throw new InternalException(ex);
200         }
201     }
202
203     /**
204      * Method testParsing10.
205      * @throws ResourceNotFoundException :
206      * @throws SAXException :
207      * @throws ParserConfigurationException :
208      */

209     public void testPortProvidedByInstanciationAndSetByTransformer() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
210         try {
211             TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterPoilu");
212             Component compo = ComponentFactory.newComponent(ts0);
213             ComponentInterface interf = compo.getInterface("writer");
214             Object JavaDoc res = interf.getValue();
215             assertEquals(((writers.Writer) res).getString(), "poilu");
216         } catch (Exception JavaDoc ex) {
217             throw new InternalException(ex);
218         }
219     }
220
221     /**
222      * Method testParsing11.
223      * @throws ResourceNotFoundException :
224      * @throws SAXException :
225      * @throws ParserConfigurationException :
226      */

227     public void testInstanciation() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
228         try {
229             TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV1");
230             Component compo = ComponentFactory.newComponent(ts0);
231             ComponentInterface interf = compo.getInterface("writer");
232             Object JavaDoc res = interf.getValue();
233             assertEquals(((writers.Writer) res).getString(), "Francois est poilu");
234         } catch (Exception JavaDoc ex) {
235             throw new InternalException(ex);
236         }
237     }
238
239     /**
240      * Method testParsing12.
241      * @throws ResourceNotFoundException :
242      * @throws SAXException :
243      * @throws ParserConfigurationException :
244      */

245     public void testInstanciation2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
246         try {
247             TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV2");
248             Component compo = ComponentFactory.newComponent(ts0);
249             ComponentInterface interf = compo.getInterface("writer");
250             Object JavaDoc res = interf.getValue();
251             assertEquals(((writers.Writer) res).getString(), "Francois est POILU");
252         } catch (Exception JavaDoc ex) {
253             throw new InternalException(ex);
254         }
255     }
256
257     /**
258      * Method testParsing13.
259      * @throws ResourceNotFoundException :
260      * @throws SAXException :
261      * @throws ParserConfigurationException :
262      */

263     public void testInstanciation3() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
264         try {
265             TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV3");
266             //InstanciationStrategy strgy = new DefaultInstanciationStrategy(new FullTDInstanciationMger());
267
//TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
268
//TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
269
//KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
270
//Component compo = ComponentFactory.newComponent(ts0, treeMapper, new DefaultMappingContext());
271
Component compo = ComponentFactory.newComponent(ts0);
272             ComponentInterface interf = compo.getInterface("writer");
273             Object JavaDoc res = interf.getValue();
274             //KilimTraceTreeViewer.viewTrace(treeModel, textMapper.getTextArea());
275
assertEquals(((writers.Writer) res).getString(), "poilu est poilu");
276         } catch (Exception JavaDoc ex) {
277             throw new InternalException(ex);
278         }
279     }
280     
281     /**
282      * Method testParsing14.
283      *: @throws ResourceNotFoundException :
284      * @throws SAXException :
285      * @throws ParserConfigurationException :
286      */

287     public void testArraysAndInstanciation() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
288         try {
289             TemplateDescription ts0 = rep.getTemplateDescription("writers/ArrayWriter");
290             Component compo = ComponentFactory.newComponent(ts0);
291             ComponentInterface interf = compo.getInterface("writer");
292             Object JavaDoc res = interf.getValue();
293             assertEquals(((writers.Writer) res).getString(), "poilu est Francois");
294         } catch (Exception JavaDoc ex) {
295             throw new InternalException(ex);
296         }
297     }
298
299     /**
300      * Method testParsing15.
301      * @throws ResourceNotFoundException :
302      * @throws SAXException :
303      * @throws ParserConfigurationException :
304      */

305     public void testTriggeringOrder() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
306         try {
307             TemplateDescription ts0 = rep.getTemplateDescription("writers/ArrayWriterV2");
308             InstanciationStrategy strgy = new DefaultInstanciationStrategy();
309             //TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
310
//TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
311
//KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
312
//Component compo = ComponentFactory.newComponent(ts0, treeMapper, new DefaultMappingContext());
313
Component compo = ComponentFactory.newComponent(ts0);
314             ComponentInterface interf = compo.getInterface("writer");
315             Object JavaDoc res = interf.getValue();
316             String JavaDoc rslt = ((writers.Writer) res).getString();
317             assertEquals(rslt, "poilu est Francois");
318         } catch (Exception JavaDoc ex) {
319             throw new InternalException(ex);
320         }
321     }
322
323     /**
324      * Method testParsing16.
325      * @throws ResourceNotFoundException :
326      * @throws SAXException :
327      * @throws ParserConfigurationException :
328      */

329     public void testInstanciationwithMultipleArguments() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
330         try {
331             TemplateDescription ts0 = rep.getTemplateDescription("writers/LoopWriter");
332             //KilimTemplateViewer.viewTemplate(ts0);
333
Component compo = ComponentFactory.newComponent(ts0);
334             //KilimComponentViewer.viewComponent(compo);
335
ComponentInterface interf = compo.getInterface("writer");
336             Object JavaDoc res = interf.getValue();
337             assertEquals(((writers.Writer) res).getString(), "Francois est poilu Francois est poilu Francois est poilu");
338         } catch (Exception JavaDoc ex) {
339             throw new InternalException(ex);
340         }
341     }
342     
343     /**
344      * Method testParsing10.
345      * @throws ResourceNotFoundException :
346      * @throws SAXException :
347      * @throws ParserConfigurationException :
348      */

349     public void testOfNullProvider() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
350         try {
351             TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV3");
352             //InstanciationStrategy strgy = new DefaultInstanciationStrategy(new FullTDInstanciationMger());
353
//TreeModelMapper treeMapper = new TreeModelMapper(new JavaNullMapper(null));
354
//KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
355
//Component compo = ComponentFactory.newComponent(ts0, treeMapper, new DefaultMappingContext());
356
Component compo = ComponentFactory.newComponent(ts0);
357             ComponentInterface interf = compo.getInterface("writer");
358             Object JavaDoc res = interf.getValue();
359             //KilimTraceTreeViewer.viewTrace(treeModel, new JTextArea());
360
} catch (Exception JavaDoc ex) {
361             throw new InternalException(ex);
362         }
363     }
364 }
365
Popular Tags