Coverage Report - org.apache.commons.latka.jelly.SuiteTag
 
Classes in this File Line Coverage Branch Coverage Complexity
SuiteTag
0%
0/45
0%
0/6
2
 
 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;
 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  
 /**
 36  
  *
 37  
  * @author  Morgan Delagrange
 38  
  */
 39  0
 public class SuiteTag extends TagSupport {
 40  
         
 41  0
     protected String _defaultHost = null;
 42  0
     protected int _defaultPort = -1;
 43  0
     protected String _defaultProxyHost = null;
 44  0
     protected int _defaultProxyPort = -1;
 45  0
     protected String _label = null;
 46  
 
 47  0
     protected SuiteSettings _settings = null;
 48  0
     protected Map _sessionCache = new HashMap();
 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  0
         boolean defaultListener = false;
 60  0
         LatkaEventListener listener = null;
 61  0
         LatkaEventInfo eventInfo = null;
 62  
         {
 63  0
             listener = 
 64  
                 JellyUtils.getInstance().getLatkaEventListener(getContext());
 65  0
             if (listener == null) {
 66  0
                 listener = new XMLReporter();
 67  0
                 defaultListener = true;
 68  
             }
 69  
 
 70  0
             eventInfo = new DefaultLatkaEventInfo(listener);
 71  0
             JellyUtils.getInstance().setLatkaEventInfo(getContext(), eventInfo);
 72  
         }
 73  
 
 74  
 
 75  0
         _settings = 
 76  
             new SuiteSettings(_defaultHost, _defaultPort, _defaultProxyHost, 
 77  
                               _defaultProxyPort);
 78  0
         invokeBody(xmlOutput);
 79  
 
 80  0
         eventInfo.suiteCompleted(new SuiteCompletedEvent());
 81  0
         JellyUtils.getInstance().removeLatkaEventInfo(getContext());
 82  
 
 83  0
         if (defaultListener == true) {
 84  
             
 85  
             try {
 86  0
                 Latka latka = new Latka();
 87  0
                 String transformedReport = 
 88  
                   latka.transformXML(((XMLReporter) listener).getDocumentAsString());
 89  
 
 90  0
                 System.out.println(transformedReport);
 91  0
             } catch (LatkaException e) {
 92  0
                 throw new JellyTagException("could not generate latka report",e);
 93  0
             } catch (IOException e) {
 94  0
                 throw new JellyTagException("could not generate latka report",e);
 95  0
             }
 96  
 
 97  0
             if (eventInfo.didSuiteSucceed() == false) {
 98  0
                 throw new JellyTagException("SUITE FAILED");
 99  
             }
 100  
         }
 101  
 
 102  
 
 103  0
     }
 104  
 
 105  
     public SuiteSettings getSuiteSettings() {
 106  0
         return _settings;
 107  
     }
 108  
 
 109  
     public Map getSessionCache() {
 110  0
         return _sessionCache;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Setter for defaultHost
 115  
      * 
 116  
      * @param defaultHost
 117  
      *               defaultHost for all requests
 118  
      */
 119  
     public void setDefaultHost(String defaultHost) {
 120  0
         _defaultHost = defaultHost;
 121  0
     }
 122  
     
 123  
     /**
 124  
      * Setter for defaultPort
 125  
      * 
 126  
      * @param defaultPort
 127  
      *               defaultPort for all requests
 128  
      */
 129  
     public void setDefaultPort(int defaultPort) {
 130  0
         _defaultPort = defaultPort;
 131  0
     }
 132  
 
 133  
 
 134  
     /**
 135  
      * Setter for defaultProxyHost
 136  
      * 
 137  
      * @param defaultHost
 138  
      *               defaultProxyHost for all requests
 139  
      */
 140  
     public void setDefaultProxyHost(String defaultHost) {
 141  0
         _defaultProxyHost = defaultHost;
 142  0
     }
 143  
 
 144  
     /**
 145  
      * Setter for defaultProxyPort
 146  
      * 
 147  
      * @param defaultPort
 148  
      *               defaultProxyPort for all requests
 149  
      */
 150  
     public void setDefaultProxyPort(int defaultPort) {
 151  0
         _defaultProxyPort = defaultPort;
 152  0
     }
 153  
 
 154  
     /**
 155  
      * Set the label for this suite
 156  
      * 
 157  
      * @param label  suite label
 158  
      */
 159  
     public void setLabel(String label) {
 160  0
         _label = label;
 161  0
     }
 162  
 
 163  
 }