1 18 package org.objectweb.kilim.repository; 19 20 import javax.swing.JTextArea ; 21 import javax.xml.parsers.ParserConfigurationException ; 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 ; 45 46 54 public class WritersTest extends TestCase { 55 56 private ResourceRepository rep; 57 private ResourceRepository rep1; 58 59 65 public WritersTest(String arg0) throws SAXException , ParserConfigurationException { 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 80 public void testProvidingPortWithInstanciationWithoutArgument() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 81 try { 82 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV1"); 83 Component compo = ComponentFactory.newComponent(ts0); 85 ComponentInterface interf = compo.getInterface("writer"); 86 Object res = interf.getValue(); 87 assertEquals(((writers.Writer) res).getString(), "a word"); 88 } catch (Exception ex) { 89 throw new InternalException(ex); 90 } 91 } 92 93 99 public void testProvidingPortWithProviderWithoutArgument() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 100 try { 101 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV2"); 102 Component compo = ComponentFactory.newComponent(ts0); 103 ComponentInterface interf = compo.getInterface("writer"); 104 Object res = interf.getValue(); 105 assertEquals(((writers.Writer) res).getString(), "a word"); 106 } catch (Exception ex) { 107 throw new InternalException(ex); 108 } 109 } 110 111 117 public void testProvidingPortWithInstanciationWithArgument() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 118 try { 119 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterV3"); 120 Component compo = ComponentFactory.newComponent(ts0); 121 ComponentInterface interf = compo.getInterface("writer"); 122 Object res = interf.getValue(); 123 assertEquals(((writers.Writer) res).getString(), "new word"); 124 125 } catch (Exception ex) { 126 throw new InternalException(ex); 127 } 128 } 129 130 136 public void testProvidingPortWithInstanciationWithArgument2() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 137 try { 138 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterFrancois"); 139 Component compo = ComponentFactory.newComponent(ts0); 140 ComponentInterface interf = compo.getInterface("writer"); 141 Object res = interf.getValue(); 142 assertEquals(((writers.Writer) res).getString(), "Francois"); 143 } catch (Exception ex) { 144 throw new InternalException(ex); 145 } 146 } 147 148 154 public void testPortProvidedByInstanciationAndSetByTrigger() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 155 try { 156 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEst"); 157 Component compo = ComponentFactory.newComponent(ts0); 159 ComponentInterface interf = compo.getInterface("writer"); 160 Object res = interf.getValue(); 161 assertEquals(((writers.Writer) res).getString(), "est"); 162 } catch (Exception ex) { 163 throw new InternalException(ex); 164 } 165 } 166 167 173 public void testPortProvidedByInstanciationAndSetByTriggerWithDirectFieldAccess() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 174 try { 175 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEstV2"); 176 Component compo = ComponentFactory.newComponent(ts0); 177 ComponentInterface interf = compo.getInterface("writer"); 178 Object res = interf.getValue(); 179 assertEquals(((writers.Writer) res).getString(), "est"); 180 } catch (Exception ex) { 181 throw new InternalException(ex); 182 } 183 } 184 185 191 public void testPortProvidedByInstanciationAndSetByTriggerWithSetterInvocation() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 192 try { 193 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterEstV3"); 194 Component compo = ComponentFactory.newComponent(ts0); 195 ComponentInterface interf = compo.getInterface("writer"); 196 Object res = interf.getValue(); 197 assertEquals(((writers.Writer) res).getString(), "est"); 198 } catch (Exception ex) { 199 throw new InternalException(ex); 200 } 201 } 202 203 209 public void testPortProvidedByInstanciationAndSetByTransformer() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 210 try { 211 TemplateDescription ts0 = rep.getTemplateDescription("writers/WordWriterPoilu"); 212 Component compo = ComponentFactory.newComponent(ts0); 213 ComponentInterface interf = compo.getInterface("writer"); 214 Object res = interf.getValue(); 215 assertEquals(((writers.Writer) res).getString(), "poilu"); 216 } catch (Exception ex) { 217 throw new InternalException(ex); 218 } 219 } 220 221 227 public void testInstanciation() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 228 try { 229 TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV1"); 230 Component compo = ComponentFactory.newComponent(ts0); 231 ComponentInterface interf = compo.getInterface("writer"); 232 Object res = interf.getValue(); 233 assertEquals(((writers.Writer) res).getString(), "Francois est poilu"); 234 } catch (Exception ex) { 235 throw new InternalException(ex); 236 } 237 } 238 239 245 public void testInstanciation2() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 246 try { 247 TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV2"); 248 Component compo = ComponentFactory.newComponent(ts0); 249 ComponentInterface interf = compo.getInterface("writer"); 250 Object res = interf.getValue(); 251 assertEquals(((writers.Writer) res).getString(), "Francois est POILU"); 252 } catch (Exception ex) { 253 throw new InternalException(ex); 254 } 255 } 256 257 263 public void testInstanciation3() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 264 try { 265 TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV3"); 266 Component compo = ComponentFactory.newComponent(ts0); 272 ComponentInterface interf = compo.getInterface("writer"); 273 Object res = interf.getValue(); 274 assertEquals(((writers.Writer) res).getString(), "poilu est poilu"); 276 } catch (Exception ex) { 277 throw new InternalException(ex); 278 } 279 } 280 281 287 public void testArraysAndInstanciation() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 288 try { 289 TemplateDescription ts0 = rep.getTemplateDescription("writers/ArrayWriter"); 290 Component compo = ComponentFactory.newComponent(ts0); 291 ComponentInterface interf = compo.getInterface("writer"); 292 Object res = interf.getValue(); 293 assertEquals(((writers.Writer) res).getString(), "poilu est Francois"); 294 } catch (Exception ex) { 295 throw new InternalException(ex); 296 } 297 } 298 299 305 public void testTriggeringOrder() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 306 try { 307 TemplateDescription ts0 = rep.getTemplateDescription("writers/ArrayWriterV2"); 308 InstanciationStrategy strgy = new DefaultInstanciationStrategy(); 309 Component compo = ComponentFactory.newComponent(ts0); 314 ComponentInterface interf = compo.getInterface("writer"); 315 Object res = interf.getValue(); 316 String rslt = ((writers.Writer) res).getString(); 317 assertEquals(rslt, "poilu est Francois"); 318 } catch (Exception ex) { 319 throw new InternalException(ex); 320 } 321 } 322 323 329 public void testInstanciationwithMultipleArguments() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 330 try { 331 TemplateDescription ts0 = rep.getTemplateDescription("writers/LoopWriter"); 332 Component compo = ComponentFactory.newComponent(ts0); 334 ComponentInterface interf = compo.getInterface("writer"); 336 Object res = interf.getValue(); 337 assertEquals(((writers.Writer) res).getString(), "Francois est poilu Francois est poilu Francois est poilu"); 338 } catch (Exception ex) { 339 throw new InternalException(ex); 340 } 341 } 342 343 349 public void testOfNullProvider() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 350 try { 351 TemplateDescription ts0 = rep.getTemplateDescription("writers/SimpleSentenceWriterV3"); 352 Component compo = ComponentFactory.newComponent(ts0); 357 ComponentInterface interf = compo.getInterface("writer"); 358 Object res = interf.getValue(); 359 } catch (Exception ex) { 361 throw new InternalException(ex); 362 } 363 } 364 } 365 | Popular Tags |