1 16 17 package org.apache.commons.latka.jelly; 18 19 import java.io.IOException ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.apache.commons.jelly.JellyTagException; 24 import org.apache.commons.jelly.TagSupport; 25 import org.apache.commons.jelly.XMLOutput; 26 27 import org.apache.commons.latka.DefaultLatkaEventInfo; 28 import org.apache.commons.latka.Latka; 29 import org.apache.commons.latka.LatkaException; 30 import org.apache.commons.latka.XMLReporter; 31 import org.apache.commons.latka.event.LatkaEventInfo; 32 import org.apache.commons.latka.event.LatkaEventListener; 33 import org.apache.commons.latka.event.SuiteCompletedEvent; 34 35 39 public class SuiteTag extends TagSupport { 40 41 protected String _defaultHost = null; 42 protected int _defaultPort = -1; 43 protected String _defaultProxyHost = null; 44 protected int _defaultProxyPort = -1; 45 protected String _label = null; 46 47 protected SuiteSettings _settings = null; 48 protected Map _sessionCache = new HashMap (); 49 50 57 public void doTag(XMLOutput xmlOutput) throws JellyTagException { 58 boolean defaultListener = false; 60 LatkaEventListener listener = null; 61 LatkaEventInfo eventInfo = null; 62 { 63 listener = 64 JellyUtils.getInstance().getLatkaEventListener(getContext()); 65 if (listener == null) { 66 listener = new XMLReporter(); 67 defaultListener = true; 68 } 69 70 eventInfo = new DefaultLatkaEventInfo(listener); 71 JellyUtils.getInstance().setLatkaEventInfo(getContext(), eventInfo); 72 } 73 74 75 _settings = 76 new SuiteSettings(_defaultHost, _defaultPort, _defaultProxyHost, 77 _defaultProxyPort); 78 invokeBody(xmlOutput); 79 80 eventInfo.suiteCompleted(new SuiteCompletedEvent()); 81 JellyUtils.getInstance().removeLatkaEventInfo(getContext()); 82 83 if (defaultListener == true) { 84 85 try { 86 Latka latka = new Latka(); 87 String transformedReport = 88 latka.transformXML(((XMLReporter) listener).getDocumentAsString()); 89 90 System.out.println(transformedReport); 91 } catch (LatkaException e) { 92 throw new JellyTagException("could not generate latka report",e); 93 } catch (IOException e) { 94 throw new JellyTagException("could not generate latka report",e); 95 } 96 97 if (eventInfo.didSuiteSucceed() == false) { 98 throw new JellyTagException("SUITE FAILED"); 99 } 100 } 101 102 103 } 104 105 public SuiteSettings getSuiteSettings() { 106 return _settings; 107 } 108 109 public Map getSessionCache() { 110 return _sessionCache; 111 } 112 113 119 public void setDefaultHost(String defaultHost) { 120 _defaultHost = defaultHost; 121 } 122 123 129 public void setDefaultPort(int defaultPort) { 130 _defaultPort = defaultPort; 131 } 132 133 134 140 public void setDefaultProxyHost(String defaultHost) { 141 _defaultProxyHost = defaultHost; 142 } 143 144 150 public void setDefaultProxyPort(int defaultPort) { 151 _defaultProxyPort = defaultPort; 152 } 153 154 159 public void setLabel(String label) { 160 _label = label; 161 } 162 163 } 164 | Popular Tags |