1 18 package org.objectweb.kilim.repository; 19 20 import javax.xml.parsers.ParserConfigurationException ; 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 ; 42 43 51 public class ViewerTests extends TestCase { 52 53 private ResourceRepository rep; 54 private ResourceRepository rep1; 55 56 62 public ViewerTests(String arg0) throws SAXException , ParserConfigurationException { 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 78 public void testViewers() throws ResourceNotFoundException, SAXException , ParserConfigurationException , 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 rslt = (StringBuffer ) interf.getValue(); 91 assertEquals(rslt.toString() , "42-is-the answer42-is-the answer"); 94 } catch (Exception ex) { 95 ex.printStackTrace(); 96 throw new InternalException(ex); 97 } 98 } 99 100 107 public void testViewer2() throws ResourceNotFoundException, SAXException , ParserConfigurationException , 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 rslt = (StringBuffer ) interf.getValue(); 121 KilimTraceTreeViewer.updateView(); 122 assertEquals(rslt.toString() , "424242-is--is--is-the answerthe answerthe answer"); 123 } catch (Exception ex) { 126 ex.printStackTrace(); 127 throw new InternalException(ex); 128 } 129 } 130 } 131 | Popular Tags |