KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

78     public void testQuotes1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
79         try {
80             TemplateDescription ts0 = rep.getTemplateDescription("quoteswire/TradingConsoleV3");
81             //KilimTemplateViewer.viewTemplate(ts0)
82
//this specific strategy should be defined in order to obtain the expected behaviour ...
83
InstanciationStrategy strgy = new DefaultInstanciationStrategy();
84             TextAreaMapper textMapper = new TextAreaMapper(new JavaRuntimeMapper());
85             TreeModelMapper treeMapper = new TreeModelMapper(textMapper);
86             KilimTraceTreeModel treeModel = treeMapper.getTraceTree();
87             //Component compo = ComponentFactory.newComponent(ts0, treeMapper, new DefaultMappingContext(), strgy);
88
Component compo = ComponentFactory.newComponent(ts0);
89             ComponentInterface interf = compo.getInterface("publishers");
90             Object JavaDoc res = interf.getValue();
91             interf = compo.getInterface("trader's workspace");
92             res = interf.getValue();
93             Thread.sleep(5000);
94             //KilimComponentViewer.viewComponent(compo);
95
//KilimTraceTreeViewer.viewTrace(treeModel, textMapper.getTextArea());
96

97         } catch (Exception JavaDoc ex) {
98             ex.printStackTrace();
99             throw new InternalException(ex);
100         }
101     }
102     
103     /**
104      * Method plugsAndSlots.
105      * @throws ResourceNotFoundException :
106      * @throws SAXException :
107      * @throws ParserConfigurationException :
108      */

109     private void plugsAndSlots(String JavaDoc tmpl_nm) throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
110         try {
111             //this specific strategy should be defined in order to obtain the expected behaviour ...
112
InstanciationStrategy strgy = new DefaultInstanciationStrategy();
113             Component compo = org.objectweb.kilim.helpers.KilimHelper.newComponent(tmpl_nm , this.getClass(), strgy);
114             ComponentInterface interf = compo.getInterface("console");
115             Object JavaDoc res = interf.getValue();
116             Thread.sleep(5000);
117         } catch (Exception JavaDoc ex) {
118             ex.printStackTrace();
119             throw new InternalException(ex);
120         }
121     }
122     
123     /**
124      * Method testQuotes2.
125      * @throws ResourceNotFoundException :
126      * @throws SAXException :
127      * @throws ParserConfigurationException :
128      */

129     public void testQuotes2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
130         plugsAndSlots("quoteswire/ExtensibleConsole");
131     }
132     
133     /**
134      * Method testQuotes3.
135      * @throws ResourceNotFoundException :
136      * @throws SAXException :
137      * @throws ParserConfigurationException :
138      */

139     public void testQuotes3() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
140         plugsAndSlots("quoteswire/ExtensibleConsole2");
141     }
142     
143     /**
144      * Method testQuotes4.
145      * @throws ResourceNotFoundException :
146      * @throws SAXException :
147      * @throws ParserConfigurationException :
148      */

149     public void testQuotes4() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
150         plugsAndSlots("quoteswire/AnotherExtensibleConsole");
151     }
152     /**
153      * Method testQuotes5.
154      * @throws ResourceNotFoundException :
155      * @throws SAXException :
156      * @throws ParserConfigurationException :
157      */

158     public void testQuotes5() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
159         plugsAndSlots("quoteswire/AnotherExtensibleConsole2");
160     }
161     
162     /**
163      * Method testQuotes6.
164      * @throws ResourceNotFoundException :
165      * @throws SAXException :
166      * @throws ParserConfigurationException :
167      */

168     public void testQuotes6() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
169         try {
170             TemplateDescription ts0 = rep1.getTemplateDescription("quoteswire/channels/SimpleChannelWithSlot");
171             //KilimTemplateViewer.viewTemplate(ts0);
172
Component compo = ComponentFactory.newComponent(ts0);
173             ComponentInterface interf = compo.getInterface("channel");
174             Object JavaDoc res = interf.getValue();
175             Thread.sleep(5000);
176         } catch (Exception JavaDoc ex) {
177             ex.printStackTrace();
178             throw new InternalException(ex);
179         }
180     }
181
182 }
183
Popular Tags