KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
21 import java.util.LinkedHashMap JavaDoc;
22
23 import javax.xml.parsers.ParserConfigurationException JavaDoc;
24 import junit.framework.TestCase;
25
26 import org.objectweb.kilim.InternalException;
27 import org.objectweb.kilim.KilimException;
28 import org.objectweb.kilim.KilimConfiguration;
29
30 import org.objectweb.kilim.description.TemplateDescription;
31 import org.objectweb.kilim.model.Component;
32 import org.objectweb.kilim.model.ComponentFactory;
33 import org.objectweb.kilim.model.ComponentInterface;
34 import org.objectweb.kilim.model.RtExternalValue;
35
36 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy;
37 import org.objectweb.kilim.model.instanciation.InstanciationStrategy;
38
39 import org.objectweb.kilim.model.mapping.DefaultMappingContext;
40 import org.objectweb.kilim.model.mapping.DefaultMappingStrategy;
41 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper;
42 import org.objectweb.kilim.model.mapping.Mapper;
43 import org.objectweb.kilim.model.mapping.MappingContext;
44 import org.objectweb.kilim.model.mapping.MappingStrategy;
45 import org.objectweb.kilim.model.mapping.NullMapper;
46 import org.objectweb.kilim.model.mapping.TextAreaMapper;
47 import org.objectweb.kilim.model.mapping.TreeModelMapper;
48
49 import org.objectweb.kilim.model.services.Annotations;
50 import org.objectweb.kilim.model.services.ExternalValueReferences;
51
52 import org.objectweb.kilim.tools.KilimComponentViewer;
53 import org.objectweb.kilim.tools.KilimTemplateViewer;
54 import org.objectweb.kilim.tools.KilimTraceTreeModel;
55 import org.objectweb.kilim.tools.KilimTraceTreeViewer;
56
57 import org.xml.sax.SAXException JavaDoc;
58
59 /**
60  * @author delpiano
61  *
62  * To change this generated comment edit the template variable "typecomment":
63  * Window>Preferences>Java>Templates.
64  * To enable and disable the creation of type comments go to
65  * Window>Preferences>Java>Code Generation.
66  */

67 public class MonoFeatureTests extends TestCase {
68     
69     private ResourceRepository rep;
70     private ResourceRepository rep1;
71     
72     /**
73      * Constructor for TemplateParserTest.
74      * @param arg0 for junit
75      * @throws SAXException should not happen
76      * @throws ParserConfigurationException should not happen
77      */

78     public MonoFeatureTests(String JavaDoc arg0) throws SAXException JavaDoc, ParserConfigurationException JavaDoc {
79         super(arg0);
80         TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
81         rep = new ResourceRepository(parser);
82         rep.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
83         rep1 = new ResourceRepository1(parser);
84         rep1.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
85     }
86     
87     /**
88      * Teste les tableaux de properties, nommées et non nommées.
89      * @throws ResourceNotFoundException :
90      * @throws SAXException :
91      * @throws ParserConfigurationException :
92      */

93     public void testPropertiesArrays() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
94         try {
95             TemplateDescription ts0 = rep1.getTemplateDescription("writers/ArrayDummyExample");
96             //KilimTemplateViewer.viewTemplate(ts0);
97
Component compo = ComponentFactory.newComponent(ts0);
98             ComponentInterface interf = compo.getInterface("array");
99             interf.getValue();
100             interf = compo.getInterface("array2");
101             interf.getValue();
102         } catch (Exception JavaDoc ex) {
103             ex.printStackTrace();
104             throw new InternalException(ex);
105         }
106     }
107     
108     /**
109      * Teste le mécanisme de surcharge des valeurs de properties par des fichiers .prop.
110      * @throws SAXException :
111      * @throws ParserConfigurationException :
112      * @throws ResourceNotFoundException :
113      */

114     public void testPropertiesOverloading() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
115         try {
116             TemplateDescription ts0 = rep1.getTemplateDescription("test/two");
117             Component compo = ComponentFactory.newComponent(ts0);
118                     
119             ComponentInterface interf = compo.getInterface("string port");
120             Object JavaDoc res = interf.getValue();
121             assertEquals(res.toString() , "Ceci est un test réussi");
122             
123             interf = compo.getInterface("integer port");
124             res = interf.getValue();
125
126             assertEquals(((Integer JavaDoc) res).intValue() , 42);
127
128             interf = compo.getInterface("long port");
129             res = interf.getValue();
130
131             assertEquals(((Long JavaDoc) res).longValue() , 42);
132         } catch (Exception JavaDoc ex) {
133             ex.printStackTrace();
134             throw new InternalException(ex);
135         }
136     }
137     
138     /**
139      * Teste l'ordre dans lequel les triggers sont exécutés.
140      * @throws SAXException :
141      * @throws ParserConfigurationException :
142      * @throws ResourceNotFoundException :
143      */

144     public void testTriggersOrder() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
145         try {
146             TemplateDescription ts0 = rep1.getTemplateDescription("test/B states");
147             Component compo = ComponentFactory.newComponent(ts0);
148             ComponentInterface interf = compo.getInterface("initial");
149             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
150             assertEquals("123", rslt.toString());
151         } catch (Exception JavaDoc ex) {
152             ex.printStackTrace();
153             throw new InternalException(ex);
154         }
155     }
156         
157     /**
158      * Teste les bindings de property à interface, de provider à interface.
159      * @throws SAXException :
160      * @throws ParserConfigurationException :
161      * @throws ResourceNotFoundException :
162      */

163     public void testPropertiesInterfaceAndProvidersBindings() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
164         try {
165             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container");
166             Component compo = ComponentFactory.newComponent(ts0);
167             ComponentInterface interf = compo.getInterface("result");
168             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
169             assertEquals(rslt.toString() , "42-is-the answer");
170         } catch (Exception JavaDoc ex) {
171             ex.printStackTrace();
172             throw new InternalException(ex);
173         }
174     }
175     
176     /**
177      * Teste la surcharge d'instances par super.
178      * @throws SAXException :
179      * @throws ParserConfigurationException :
180      * @throws ResourceNotFoundException :
181      */

182     public void testSuperAndSuperSuper() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
183         try {
184             TemplateDescription ts0 = rep1.getTemplateDescription("test/PLentyOfInstances A");
185             TemplateDescription ts1 = rep1.getTemplateDescription("test/PLenty of Instances B");
186             Component compo = ComponentFactory.newComponent(ts0);
187             ComponentInterface interf = compo.getInterface("a of level 1");
188             String JavaDoc rslt = (String JavaDoc) interf.getValue();
189             assertEquals(rslt , "Valeur de a modifiée");
190             
191             compo = ComponentFactory.newComponent(ts1);
192             interf = compo.getInterface("a of level 2");
193             rslt = (String JavaDoc) interf.getValue();
194             assertEquals(rslt , "Valeur de a modifiée");
195         } catch (Exception JavaDoc ex) {
196             ex.printStackTrace();
197             throw new InternalException(ex);
198         }
199     }
200
201     /**
202      * Tests the overloading of properties by providers/ports, and ports by properties.
203      * @throws SAXException :
204      * @throws ParserConfigurationException :
205      * @throws ResourceNotFoundException :
206      * @throws KilimException :
207      */

208     public void testExternalReference() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
209         try {
210             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container for Externals");
211             //Annotations xServ = new Annotations();
212
ExternalValueReferences xRefs = new ExternalValueReferences();
213             xRefs.addExternalValueReference("/extern/b", new String JavaDoc("-is-"));
214             xRefs.addExternalValueReference("/extern/c", new String JavaDoc("" + 42));
215             xRefs.addExternalValueReference("/extern/a", new String JavaDoc("the answer"));
216             //xServ.addAnnotation("external references", xRefs);
217
//InstanciationStrategy strgy = new DefaultInstanciationStrategy();
218
//xServ.addAnnotation("instanciation strategy", strgy);
219
KilimConfiguration.setExternalReferences(xRefs);
220             Component compo = ComponentFactory.newComponent(ts0);
221             ComponentInterface interf = compo.getInterface("result");
222             StringBuffer JavaDoc rslt_bff = (StringBuffer JavaDoc) interf.getValue();
223             
224             String JavaDoc rslt = rslt_bff.toString();
225             assertEquals(rslt, "the answer-is-42");
226         } catch (Exception JavaDoc ex) {
227             ex.printStackTrace();
228             throw new InternalException(ex);
229         }
230     }
231     
232     /**
233      * Teste si le binding multiple lève bien une exception.
234      * @throws SAXException :
235      * @throws ParserConfigurationException :
236      * @throws ResourceNotFoundException :
237      */

238     public void testMultipleBindingsDetection() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
239         boolean exception_thrown = false;
240         try {
241             TemplateDescription ts0 = rep1.getTemplateDescription("test/Multiple Bindings Subtemplate");
242             Component compo = ComponentFactory.newComponent(ts0);
243         } catch (KilimException e) {
244             e.printStackTrace();
245             exception_thrown = true;
246         } finally {
247             assertEquals (exception_thrown , false);
248         }
249     }
250
251     /**
252      * Tests the overloading of properties by providers/ports, and ports by properties.
253      * @throws SAXException :
254      * @throws ParserConfigurationException :
255      * @throws ResourceNotFoundException :
256      * @throws KilimException :
257      */

258     public void testMultipleTypesOfOverloading() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
259         TemplateDescription ts0 = rep1.getTemplateDescription("test/Overloading Things");
260         Component compo = ComponentFactory.newComponent(ts0);
261         assertEquals(compo.getInterface("a").getValue() , "a modified");
262         assertEquals(compo.getInterface("b").getValue() , "b modified");
263     }
264     
265     /**
266      * Tests the overloading of properties by providers/ports, and ports by properties.
267      * @throws SAXException :
268      * @throws ParserConfigurationException :
269      * @throws ResourceNotFoundException :
270      * @throws KilimException :
271      */

272     public void testOrderOnCompositionOfMultiplePort() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
273         try {
274             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
275             Component compo = ComponentFactory.newComponent(ts0);
276             ComponentInterface interf = compo.getInterface("result");
277             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
278             assertEquals(rslt.toString() , "4242-is--is-the answerthe answer");
279             //correct result when using the preplug implementation
280
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer");
281
} catch (Exception JavaDoc ex) {
282             ex.printStackTrace();
283             throw new InternalException(ex);
284         }
285     }
286     
287     /**
288      * Tests the overloading of properties by providers/ports, and ports by properties.
289      * @throws SAXException :
290      * @throws ParserConfigurationException :
291      * @throws ResourceNotFoundException :
292      * @throws KilimException :
293      */

294     public void testDynamicPlugOnNAryPort() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
295         try {
296             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container with NAry Slot");
297             Component compo = ComponentFactory.newComponent(ts0);
298             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
299             Component compo1 = ComponentFactory.newComponent(ts1);
300             Component compo2 = ComponentFactory.newComponent(ts1);
301             compo.plug("slot", compo1);
302             compo.plug("slot", compo2);
303             ComponentInterface interf = compo.getInterface("result");
304             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
305             assertEquals(rslt.toString() , "4242-is--is-the answerthe answer");
306             //correct result when using the preplug implementation
307
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer");
308
} catch (Exception JavaDoc ex) {
309             ex.printStackTrace();
310             throw new InternalException(ex);
311         }
312     }
313     
314     /**
315      * Tests the overloading of properties by providers/ports, and ports by properties.
316      * @throws SAXException :
317      * @throws ParserConfigurationException :
318      * @throws ResourceNotFoundException :
319      * @throws KilimException :
320      */

321     public void testDynamicPlug() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
322         try {
323             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container");
324             Component compo = ComponentFactory.newComponent(ts0);
325             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
326             Component compo1 = ComponentFactory.newComponent(ts1);
327             compo.plug("slot", compo1);
328             ComponentInterface interf = compo.getInterface("result");
329             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
330             assertEquals(rslt.toString() , "42-is-the answer");
331         } catch (Exception JavaDoc ex) {
332             ex.printStackTrace();
333             throw new InternalException(ex);
334         }
335     }
336     
337     /**
338      * Tests the overloading of properties by providers/ports, and ports by properties.
339      * @throws SAXException :
340      * @throws ParserConfigurationException :
341      * @throws ResourceNotFoundException :
342      * @throws KilimException :
343      */

344     public void testSimpleFork1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
345         try {
346             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container");
347             Component compo = ComponentFactory.newComponent(ts0);
348             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
349             Component compo1 = ComponentFactory.newComponent(ts1);
350             Component compo2 = compo1.fork();
351             compo.plug("slot", compo2);
352             ComponentInterface interf = compo.getInterface("result");
353             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
354             assertEquals(rslt.toString() , "42-is-the answer");
355         } catch (Exception JavaDoc ex) {
356             ex.printStackTrace();
357             throw new InternalException(ex);
358         }
359     }
360     
361     /**
362      * Tests the overloading of properties by providers/ports, and ports by properties.
363      * @throws SAXException :
364      * @throws ParserConfigurationException :
365      * @throws ResourceNotFoundException :
366      * @throws KilimException :
367      */

368     public void testSimpleFork1A() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
369         try {
370             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container with Plug");
371             Component compo = ComponentFactory.newComponent(ts0);
372             ComponentInterface interf = compo.getInterface("result");
373             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
374             assertEquals(rslt.toString() , "42-is-the answer");
375             Component compo1 = compo.getSubComponent("Plug");
376             Component compo2 = compo1.fork();
377             interf.update();
378             rslt = (StringBuffer JavaDoc) interf.getValue();
379             assertEquals(rslt.toString() , "42-is-the answer42-is-the answer");
380         } catch (Exception JavaDoc ex) {
381             ex.printStackTrace();
382             throw new InternalException(ex);
383         }
384     }
385     
386     /**
387      * Tests the overloading of properties by providers/ports, and ports by properties.
388      * @throws SAXException :
389      * @throws ParserConfigurationException :
390      * @throws ResourceNotFoundException :
391      * @throws KilimException :
392      */

393     public void testSimpleFork2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
394         try {
395             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container with NAry Slot");
396             Component compo = ComponentFactory.newComponent(ts0);
397             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
398             Component compo1 = ComponentFactory.newComponent(ts1);
399             Component compo2 = compo1.fork();
400             Component compo3 = compo2.fork();
401             compo.plug("slot", compo1);
402             compo.plug("slot", compo2);
403             compo.plug("slot", compo3);
404             ComponentInterface interf = compo.getInterface("result");
405             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
406             assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer");
407             //correct result when using the preplug implementation
408
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer");
409
} catch (Exception JavaDoc ex) {
410             ex.printStackTrace();
411             throw new InternalException(ex);
412         }
413     }
414
415     /**
416      * Tests the overloading of properties by providers/ports, and ports by properties.
417      * @throws SAXException :
418      * @throws ParserConfigurationException :
419      * @throws ResourceNotFoundException :
420      * @throws KilimException :
421      */

422     public void testForkOfPlugged1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
423         try {
424             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container with NAry Slot");
425             Component compo = ComponentFactory.newComponent(ts0);
426             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
427             Component compo1 = ComponentFactory.newComponent(ts1);
428             compo.plug("slot", compo1);
429             Component compo2 = compo1.fork();
430             compo.plug("slot", compo2);
431             Component compo3 = compo2.fork();
432             compo.plug("slot", compo3);
433             ComponentInterface interf = compo.getInterface("result");
434             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
435             assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer");
436             //correct result when using the preplug implementation
437
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer");
438
} catch (Exception JavaDoc ex) {
439             ex.printStackTrace();
440             throw new InternalException(ex);
441         }
442     }
443     
444     /**
445      * Tests the overloading of properties by providers/ports, and ports by properties.
446      * @throws SAXException :
447      * @throws ParserConfigurationException :
448      * @throws ResourceNotFoundException :
449      * @throws KilimException :
450      */

451     public void testForkOfPlugged2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
452         try {
453             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
454             Component compo = ComponentFactory.newComponent(ts0);
455             Component compo1 = compo.getSubComponent("Container");
456             Component compo2 = compo.getSubComponent("Plug");
457             Component compo3 = compo2.fork();
458             ComponentInterface interf = compo.getInterface("result");
459             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
460             assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer");
461             //correct result when using the preplug implementation
462
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer");
463
} catch (Exception JavaDoc ex) {
464             ex.printStackTrace();
465             throw new InternalException(ex);
466         }
467     }
468     
469     /**
470      * Tests the overloading of properties by providers/ports, and ports by properties.
471      * @throws SAXException :
472      * @throws ParserConfigurationException :
473      * @throws ResourceNotFoundException :
474      * @throws KilimException :
475      */

476     public void testForkOfPlugged3() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
477         try {
478             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
479             Component compo = ComponentFactory.newComponent(ts0);
480             Component compo1 = compo.getSubComponent("Container");
481             Component compo2 = compo.getSubComponent("Plug");
482             Component compo3 = compo2.fork();
483             Component compo4 = compo3.fork();
484             ComponentInterface interf = compo.getInterface("result");
485             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
486             assertEquals(rslt.toString() , "42424242-is--is--is--is-the answerthe answerthe answerthe answer");
487             //correct result when using the preplug implementation
488
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer42-is-the answer");
489
} catch (Exception JavaDoc ex) {
490             ex.printStackTrace();
491             throw new InternalException(ex);
492         }
493     }
494     
495     /**
496      * Tests the overloading of properties by providers/ports, and ports by properties.
497      * @throws SAXException :
498      * @throws ParserConfigurationException :
499      * @throws ResourceNotFoundException :
500      * @throws KilimException :
501      */

502     public void testForkOfPlugged4() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
503         try {
504             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
505             Component compo = ComponentFactory.newComponent(ts0);
506             ComponentInterface interf = compo.getInterface("result");
507             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
508             Component compo1 = compo.getSubComponent("Container");
509             Component compo2 = compo.getSubComponent("Plug");
510             Component compo3 = compo2.fork();
511             Component compo4 = compo3.fork();
512             assertEquals(rslt.toString() , "4242-is--is-the answerthe answer42-is-the answer42-is-the answer");
513             //correct result when using the preplug implementation
514
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer42-is-the answer");
515
} catch (Exception JavaDoc ex) {
516             ex.printStackTrace();
517             throw new InternalException(ex);
518         }
519     }
520     
521     /**
522      * Tests the overloading of properties by providers/ports, and ports by properties.
523      * @throws SAXException :
524      * @throws ParserConfigurationException :
525      * @throws ResourceNotFoundException :
526      * @throws KilimException :
527      */

528     public void testForkOfPlugged5() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
529         try {
530             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
531             Component compo = ComponentFactory.newComponent(ts0);
532             ComponentInterface interf = compo.getInterface("result");
533             Component compo1 = compo.getSubComponent("Container");
534             Component compo2 = compo.getSubComponent("Plug");
535             Component compo3 = compo2.fork();
536             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
537             Component compo4 = compo3.fork();
538             assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer42-is-the answer");
539             //correct result when using the preplug implementation
540
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer42-is-the answer");
541
} catch (Exception JavaDoc ex) {
542             ex.printStackTrace();
543             throw new InternalException(ex);
544         }
545     }
546      
547     /** Tests the triggering of transformers in cycle prone templates.
548      * @throws SAXException :
549      * @throws ParserConfigurationException :
550      * @throws ResourceNotFoundException :
551      * @throws KilimException :
552      */

553     public void testCycleAndTriggers() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
554         TemplateDescription ts0 = rep1.getTemplateDescription("test/Cycle via Trigger");
555         Component compo = ComponentFactory.newComponent(ts0);
556         assertEquals(compo.getInterface("Un").getValue() , "Toto est un héros");
557     }
558     
559     /**
560      * Tests the triggering of transformers on THIS.
561      * @throws SAXException :
562      * @throws ParserConfigurationException :
563      * @throws ResourceNotFoundException :
564      * @throws KilimException :
565      */

566     public void testTriggersOnTHIS() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
567         TemplateDescription ts0 = rep1.getTemplateDescription("test/Triggers on THIS");
568         Component compo = ComponentFactory.newComponent(ts0);
569         System.out.print("L'affichage correct doit être 12 : ");
570         assertEquals(compo.getInterface("bidon").getValue(), null);
571     }
572     
573     /** Tests the containment behaviour, respect to star ports.
574      * @throws SAXException :
575      * @throws ParserConfigurationException :
576      * @throws ResourceNotFoundException :
577      * @throws KilimException :
578      */

579     public void testContainmentAndStart() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
580         TemplateDescription ts0 = rep1.getTemplateDescription("test/Containment Test");
581         Component compo = ComponentFactory.newComponent(ts0);
582         assertEquals("ContentContent" , compo.getInterface("text").getValue().toString());
583     }
584     
585     /** Tests the triggering of transformers in cycle prone templates.
586      * @throws SAXException :
587      * @throws ParserConfigurationException :
588      * @throws ResourceNotFoundException :
589      * @throws KilimException :
590      */

591     public void testBindingValue1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
592         TemplateDescription ts0 = rep1.getTemplateDescription("test/BindingValue Test");
593         Component compo1 = ComponentFactory.newComponent(ts0);
594         Component compo2 = compo1.fork();
595         ComponentInterface interf1a = compo1.getInterface("toBeBound");
596         interf1a.bindValue("Toto est un héros");
597         ComponentInterface interf1b = compo1.getInterface("result");
598         assertEquals(interf1b.getValue() , "Toto est un héros");
599         ComponentInterface interf2a = compo2.getInterface("toBeBound");
600         interf2a.bindValue("Titi est un héros");
601         ComponentInterface interf2b = compo2.getInterface("result");
602         assertEquals(interf2b.getValue() , "Titi est un héros");
603         Component compo3 = compo2.fork();
604         ComponentInterface interf3a = compo3.getInterface("toBeBound");
605         interf3a.bindValue("Tutu est un héros");
606         ComponentInterface interf3b = compo3.getInterface("result");
607         assertEquals(interf3b.getValue() , "Tutu est un héros");
608     }
609     
610     /**
611      * Tests the triggering of transformers in cycle prone templates.
612      * @throws SAXException :
613      * @throws ParserConfigurationException :
614      * @throws ResourceNotFoundException :
615      * @throws KilimException :
616      */

617     public void testBindingProvider1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
618         TemplateDescription ts0 = rep1.getTemplateDescription("test/BindingValue Test");
619         Mapper mapper = new JavaRuntimeMapper();
620         MappingContext mContext = new DefaultMappingContext();
621
622         Component compo1 = ComponentFactory.newComponent(ts0);
623         Component compo2 = compo1.fork();
624         ComponentInterface interf1a = compo1.getInterface("toBeBound");
625         interf1a.bindProvider(new RtExternalValue("toto", "Toto est un héros"), false);
626         ComponentInterface interf1b = compo1.getInterface("result");
627         assertEquals(interf1b.getValue() , "Toto est un héros");
628         ComponentInterface interf2a = compo2.getInterface("toBeBound");
629         interf2a.bindProvider(new RtExternalValue("toto", "Titi est un héros"), false);
630         ComponentInterface interf2b = compo2.getInterface("result");
631         assertEquals(interf2b.getValue() , "Titi est un héros");
632         Component compo3 = compo2.fork();
633         ComponentInterface interf3a = compo3.getInterface("toBeBound");
634         interf3a.bindProvider(new RtExternalValue("tutu", "Tutu est un héros"), false);
635         ComponentInterface interf3b = compo3.getInterface("result");
636         assertEquals(interf3b.getValue() , "Tutu est un héros");
637     }
638     
639     /**
640      * Method testNullParser
641      * @throws ResourceNotFoundException :
642      * @throws SAXException :
643      * @throws ParserConfigurationException :
644      * @throws KilimException :
645      */

646     public void testNullMapper() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
647         TemplateDescription ts0 = rep.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
648         //KilimTemplateViewer.viewTemplate(ts0);
649
try {
650             //this specific strategy should be defined in order to obtain the expected behaviour ...
651
MappingStrategy strgy = new DefaultMappingStrategy(new NullMapper(null));
652             KilimConfiguration.setMappingStrategy(strgy);
653             Component compo = ComponentFactory.newComponent(ts0);
654             Iterator JavaDoc iter = compo.getInterfaces();
655             while (iter.hasNext()) {
656                 ComponentInterface interf = ((ComponentInterface) iter.next());
657                 System.out.println("interface : " + interf.getQualifiedName());
658                 interf.getValue();
659             }
660         } catch (Exception JavaDoc ex) {
661             ex.printStackTrace();
662             throw new InternalException(ex);
663         }
664     }
665     
666     /**
667      * Tests the overloading of properties by providers/ports, and ports by properties.
668      * @throws SAXException :
669      * @throws ParserConfigurationException :
670      * @throws ResourceNotFoundException :
671      * @throws KilimException :
672      */

673     public void testOtherMapper1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
674         try {
675             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
676             TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
677             TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
678             KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
679             MappingStrategy strgy = new DefaultMappingStrategy(treeMapper);
680             KilimConfiguration.setMappingStrategy(strgy);
681             Component compo = ComponentFactory.newComponent(ts0);
682             Component compo1 = compo.getSubComponent("Container");
683             Component compo2 = compo.getSubComponent("Plug");
684             Component compo3 = compo2.fork();
685             Component compo4 = compo3.fork();
686             ComponentInterface interf = compo.getInterface("result");
687             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
688             //KilimTraceTreeViewer.viewTrace(treeModel, textMapper.getTextArea());
689
assertEquals(rslt.toString() , "42424242-is--is--is--is-the answerthe answerthe answerthe answer");
690             //correct result when using the preplug implementation
691
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer42-is-the answer");
692
} catch (Exception JavaDoc ex) {
693             ex.printStackTrace();
694             throw new InternalException(ex);
695         }
696     }
697
698     /* Tests the triggering of transformers on THIS.
699      * @throws SAXException :
700      * @throws ParserConfigurationException :
701      * @throws ResourceNotFoundException :
702      * @throws KilimException :
703      */

704     
705     /**
706      * Tests the overloading of properties by providers/ports, and ports by properties.
707      * @throws SAXException :
708      * @throws ParserConfigurationException :
709      * @throws ResourceNotFoundException :
710      * @throws KilimException :
711      *
712     public void testPrivateAccess() throws ResourceNotFoundException, SAXException, ParserConfigurationException, KilimException {
713         TemplateDescription ts0 = rep1.getTemplateDescription("test/Extends Private");
714         //KilimTemplateViewer.viewTemplate(ts0);
715         Component compo = ComponentFactory.newComponent(ts0);
716         assertEquals(compo.getInterface("public").getValue() , "private property");
717     }
718     */

719 }
720
Popular Tags