View Javadoc

1   /*
2    * Copyright 2007 united internet (unitedinternet.com) Robert Zimmermann
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 com.unitedinternet.portal.selenium.utils.logging;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.ArrayUtils;
23  
24  /**
25   * All data of a Selenium command already processed by remote-control and other informations to be formatted and logged.
26   * 
27   * @author Robert Zimmermann
28   * 
29   * $Id: LoggingBean.java 114 2008-05-02 13:10:44Z Steffen_K $
30   */
31  public class LoggingBean {
32      private String commandName = "";
33  
34      private String[] args;
35  
36      private String result = "";
37  
38      private String callingClass = "";
39  
40      private boolean commandSuccessful;
41  
42      private boolean waitInvolved;
43  
44      private long cmdStartMillis;
45  
46      private long cmdEndMillis;
47  
48      private String sourceMethod;
49  
50      private boolean excludeFromLogging = false;
51  
52      private long waitDeltaMillis = 0;
53  
54      private List<LoggingBean> children = new ArrayList<LoggingBean>();
55  
56      public void addChild(LoggingBean loggingBean) {
57          children.add(loggingBean);
58      }
59  
60      public List<LoggingBean> getChildren() {
61          return children;
62      }
63  
64      public boolean hasChildren() {
65          return getChildren().size() > 0;
66      }
67  
68      public String getCommandName() {
69          return commandName;
70      }
71  
72      public void setCommandName(String commandName) {
73          this.commandName = commandName;
74      }
75  
76      public String[] getArgs() {
77          return (String[]) ArrayUtils.clone(args);
78      }
79  
80      public void setArgs(String[] args) {
81          this.args = (String[]) ArrayUtils.clone(args);
82      }
83  
84      public String getResult() {
85          return result;
86      }
87  
88      public void setResult(String result) {
89          this.result = result;
90      }
91  
92      public String getCallingClass() {
93          return callingClass;
94      }
95  
96      public void setCallingClass(String callingClass) {
97          this.callingClass = callingClass;
98      }
99  
100     public boolean isCommandSuccessful() {
101         return commandSuccessful;
102     }
103 
104     public void setCommandSuccessful(boolean commandSuccessful) {
105         this.commandSuccessful = commandSuccessful;
106     }
107 
108     /**
109      * Extract remote-control part out of combined result.
110      * 
111      * @return the remote-control part of the combined result
112      */
113     public String getSrcResult() {
114         String[] results = this.result.split(",");
115         String srcResult = "";
116         if (results.length > 0) {
117             srcResult = results[0];
118         }
119         return srcResult;
120     }
121 
122     /**
123      * Extract core part out of combined result.
124      * 
125      * @return the selenium-core part of the combined result
126      */
127     public String getSelResult() {
128         int firstCommaIndex = this.result.indexOf(",");
129         return this.result.substring(firstCommaIndex + 1);
130     }
131 
132     /**
133      * Do not rely on stability of this method. Subject to change in further releases.
134      * 
135      * @return commandName and its args as one String
136      */
137     @Override
138     public String toString() {
139         return "commandName=" + commandName + ", args=" + ArrayUtils.toString(args);
140     }
141 
142     public long getCmdStartMillis() {
143         return cmdStartMillis;
144     }
145 
146     public void setCmdStartMillis(long cmdStartMillis) {
147         this.cmdStartMillis = cmdStartMillis;
148     }
149 
150     public long getCmdEndMillis() {
151         return cmdEndMillis;
152     }
153 
154     public void setCmdEndMillis(long cmdEndMillis) {
155         this.cmdEndMillis = cmdEndMillis;
156     }
157 
158     public boolean isWaitInvolved() {
159         return waitInvolved;
160     }
161 
162     public void setWaitInvolved(boolean waitInvolved) {
163         this.waitInvolved = waitInvolved;
164     }
165 
166     public String getSourceMethod() {
167         return sourceMethod;
168     }
169 
170     public void setSourceMethod(String sourceMethod) {
171         this.sourceMethod = sourceMethod;
172     }
173 
174     /**
175      * Return time spent depending on type of command.
176      * 
177      * Current differentiation:
178      * 
179      * 1) inside Wait (wait's are combined into one event)
180      * 
181      * 2) how long on single command took
182      * 
183      * @return time (millis) spent for a command or summarized over all issued wait's
184      */
185     public long getDeltaMillis() {
186         if (getWaitDeltaMillis() > 0) {
187             return getWaitDeltaMillis();
188         } else {
189             return this.cmdEndMillis - this.cmdStartMillis;
190         }
191     }
192 
193     public boolean isExcludeFromLogging() {
194         return excludeFromLogging;
195     }
196 
197     public void setExcludeFromLogging(boolean excludeFromLogging) {
198         this.excludeFromLogging = excludeFromLogging;
199     }
200 
201     public long getWaitDeltaMillis() {
202         return waitDeltaMillis;
203     }
204 
205     public void setWaitDeltaMillis(long waitDeltaMillis) {
206         this.waitDeltaMillis = waitDeltaMillis;
207     }
208 }