KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > latka > jelly > SuiteTag


1 /*
2  * Copyright 1999-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.latka.jelly;
18
19 import java.io.IOException JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
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 /**
36  *
37  * @author Morgan Delagrange
38  */

39 public class SuiteTag extends TagSupport {
40         
41     protected String JavaDoc _defaultHost = null;
42     protected int _defaultPort = -1;
43     protected String JavaDoc _defaultProxyHost = null;
44     protected int _defaultProxyPort = -1;
45     protected String JavaDoc _label = null;
46
47     protected SuiteSettings _settings = null;
48     protected Map JavaDoc _sessionCache = new HashMap JavaDoc();
49
50     /**
51      * Wraps Latka tests, provides some defaults for host, port etc.
52      *
53      * @param xmlOutput a place to write output
54      * @throws JellyTagException if the suite fails, either as a result of test failures
55      * or from problems executing tags, generating reports, etc.
56      */

57     public void doTag(XMLOutput xmlOutput) throws JellyTagException {
58         // if an enclosing tag does not specify a listener, provide a default
59
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 JavaDoc 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 JavaDoc 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 JavaDoc getSessionCache() {
110         return _sessionCache;
111     }
112
113     /**
114      * Setter for defaultHost
115      *
116      * @param defaultHost
117      * defaultHost for all requests
118      */

119     public void setDefaultHost(String JavaDoc defaultHost) {
120         _defaultHost = defaultHost;
121     }
122     
123     /**
124      * Setter for defaultPort
125      *
126      * @param defaultPort
127      * defaultPort for all requests
128      */

129     public void setDefaultPort(int defaultPort) {
130         _defaultPort = defaultPort;
131     }
132
133
134     /**
135      * Setter for defaultProxyHost
136      *
137      * @param defaultHost
138      * defaultProxyHost for all requests
139      */

140     public void setDefaultProxyHost(String JavaDoc defaultHost) {
141         _defaultProxyHost = defaultHost;
142     }
143
144     /**
145      * Setter for defaultProxyPort
146      *
147      * @param defaultPort
148      * defaultProxyPort for all requests
149      */

150     public void setDefaultProxyPort(int defaultPort) {
151         _defaultProxyPort = defaultPort;
152     }
153
154     /**
155      * Set the label for this suite
156      *
157      * @param label suite label
158      */

159     public void setLabel(String JavaDoc label) {
160         _label = label;
161     }
162
163 }
164
Popular Tags