KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.parsers.ParserConfigurationException JavaDoc;
21 import junit.framework.TestCase;
22
23 import org.objectweb.kilim.InternalException;
24 import org.objectweb.kilim.KilimException;
25
26 import org.objectweb.kilim.description.TemplateDescription;
27 import org.objectweb.kilim.model.Component;
28 import org.objectweb.kilim.model.ComponentFactory;
29 import org.objectweb.kilim.model.ComponentInterface;
30
31 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper;
32
33 import org.objectweb.kilim.model.mapping.TextAreaMapper;
34 import org.objectweb.kilim.model.mapping.TreeModelMapper;
35
36 import org.objectweb.kilim.tools.KilimComponentViewer;
37 import org.objectweb.kilim.tools.KilimTemplateViewer;
38 import org.objectweb.kilim.tools.KilimTraceTreeModel;
39 import org.objectweb.kilim.tools.KilimTraceTreeViewer;
40
41 import org.xml.sax.SAXException JavaDoc;
42
43 /**
44  * @author delpiano
45  *
46  * To change this generated comment edit the template variable "typecomment":
47  * Window>Preferences>Java>Templates.
48  * To enable and disable the creation of type comments go to
49  * Window>Preferences>Java>Code Generation.
50  */

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

62     public ViewerTests(String JavaDoc arg0) throws SAXException JavaDoc, ParserConfigurationException JavaDoc {
63         super(arg0);
64         TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
65         rep = new ResourceRepository(parser);
66         rep.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
67         rep1 = new ResourceRepository1(parser);
68         rep1.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
69     }
70     
71     /**
72      * Tests the template and component viewers.
73      * @throws SAXException :
74      * @throws ParserConfigurationException :
75      * @throws ResourceNotFoundException :
76      * @throws KilimException :
77      */

78     public void testViewers() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
79         try {
80             TemplateDescription ts0 = rep1.getTemplateDescription("test/Container with NAry Slot");
81             KilimTemplateViewer.viewTemplate(ts0);
82             Component compo = ComponentFactory.newComponent(ts0);
83             KilimComponentViewer.viewComponent(compo);
84             TemplateDescription ts1 = rep1.getTemplateDescription("test/Plug");
85             Component compo1 = ComponentFactory.newComponent(ts1);
86             Component compo2 = ComponentFactory.newComponent(ts1);
87             compo.plug("slot", compo1);
88             compo.plug("slot", compo2);
89             ComponentInterface interf = compo.getInterface("result");
90             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
91             //assertEquals(rslt.toString() , "4242-is--is-the answerthe answer");
92
//correct result when using the preplug implementation
93
assertEquals(rslt.toString() , "42-is-the answer42-is-the answer");
94         } catch (Exception JavaDoc ex) {
95             ex.printStackTrace();
96             throw new InternalException(ex);
97         }
98     }
99     
100     /**
101      * Tests the overloading of properties by providers/ports, and ports by properties.
102      * @throws SAXException :
103      * @throws ParserConfigurationException :
104      * @throws ResourceNotFoundException :
105      * @throws KilimException :
106      */

107     public void testViewer2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
108         try {
109             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
110             TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
111             TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
112             KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
113             Component compo = ComponentFactory.newComponent(ts0);
114             KilimTraceTreeViewer.viewTrace(treeModel, textMapper.getTextArea());
115             Component compo1 = compo.getSubComponent("Container");
116             Component compo2 = compo.getSubComponent("Plug");
117             Component compo3 = compo2.fork();
118             KilimTraceTreeViewer.updateView();
119             ComponentInterface interf = compo.getInterface("result");
120             StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf.getValue();
121             KilimTraceTreeViewer.updateView();
122             assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer");
123             //correct result when using the preplug implementation
124
//assertEquals(rslt.toString() , "42-is-the answer42-is-the answer42-is-the answer");
125
} catch (Exception JavaDoc ex) {
126             ex.printStackTrace();
127             throw new InternalException(ex);
128         }
129     }
130 }
131
Popular Tags