1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.unitedinternet.portal.selenium.utils.logging;
18
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class EventQueuePostProcessor {
36 private LoggingResultsFormatter formatter;
37
38 boolean logMethodsAsComments = true;
39
40
41
42
43
44
45
46
47
48
49 public EventQueuePostProcessor(LoggingResultsFormatter outputFormatter, List<LoggingBean> loggingEventsQueue,
50 TestMetricsBean seleniumTestMetrics, boolean logMethodsAsComments) {
51 this.formatter = outputFormatter;
52 this.logMethodsAsComments = logMethodsAsComments;
53 formatAllGatheredInformations(loggingEventsQueue, seleniumTestMetrics);
54 }
55
56
57
58
59
60
61
62 void formatAndOutputCommand(LoggingBean loggingBean) {
63
64 if (SeleniumCommandExtensions.COMMAND_EXTENSION_LOG_COMMENT.getName().equals(loggingBean.getCommandName())) {
65 formatter.commentLogEvent(loggingBean);
66 return;
67 }
68
69 boolean srcResult = false;
70 String result = loggingBean.getResult();
71
72
73 if (result.startsWith(LoggingCommandProcessor.SELENIUM_RC_OK_RESULT)) {
74 if (result.endsWith(LoggingCommandProcessor.SELENIUM_CORE_BOOLEAN_RESULT_TRUE)
75 || result.endsWith(LoggingCommandProcessor.SELENIUM_CORE_BOOLEAN_RESULT_FALSE)) {
76 loggingBean.setCommandSuccessful(result.endsWith(LoggingCommandProcessor.SELENIUM_CORE_BOOLEAN_RESULT_TRUE));
77 formatter.booleanCommandLogEvent(loggingBean);
78 return;
79 } else {
80 srcResult = true;
81 }
82 }
83 loggingBean.setCommandSuccessful(srcResult);
84 formatter.commandLogEvent(loggingBean);
85 }
86
87
88
89
90 private static final String WAIT_PREFIX = "(Wait)";
91
92
93
94
95
96
97
98
99
100 void formatAllGatheredInformations(List<LoggingBean> loggingEventsQueue, TestMetricsBean seleniumTestMetrics) {
101 formatter.headerLogEvent(seleniumTestMetrics);
102
103 boolean insideWait = false;
104 long startWaitMillis = 0;
105 LoggingBean lastWaitLoggingEvent = null;
106 String currentMethodName = "";
107 LoggingBean rootLoggingBean = new LoggingBean();
108 boolean completeResult = true;
109 for (LoggingBean currentLoggingEvent : loggingEventsQueue) {
110
111 if (currentLoggingEvent.isWaitInvolved()) {
112 lastWaitLoggingEvent = currentLoggingEvent;
113 if (!insideWait) {
114 insideWait = true;
115 startWaitMillis = currentLoggingEvent.getCmdStartMillis();
116 }
117 } else {
118 if (insideWait) {
119 insideWait = false;
120 lastWaitLoggingEvent.setWaitDeltaMillis(currentLoggingEvent.getCmdEndMillis() - startWaitMillis);
121 startWaitMillis = 0;
122
123 String s = lastWaitLoggingEvent.getCommandName();
124 if (!s.startsWith(WAIT_PREFIX)) {
125 lastWaitLoggingEvent.setCommandName(WAIT_PREFIX + s);
126 }
127 formatAndOutputCommand(lastWaitLoggingEvent);
128 }
129 if (!currentLoggingEvent.getSourceMethod().equals(currentMethodName)) {
130 if (StringUtils.isNotEmpty(currentMethodName)) {
131 postProcessMethod(completeResult, rootLoggingBean, currentMethodName);
132 completeResult = true;
133 }
134
135 currentMethodName = currentLoggingEvent.getSourceMethod();
136 rootLoggingBean = new LoggingBean();
137 rootLoggingBean.setCallingClass(currentLoggingEvent.getCallingClass());
138 logNewMethodEntered(currentMethodName, rootLoggingBean);
139 }
140 formatAndOutputCommand(currentLoggingEvent);
141 rootLoggingBean.addChild(currentLoggingEvent);
142 }
143 completeResult = completeResult && currentLoggingEvent.isCommandSuccessful();
144 }
145
146 postProcessMethod(completeResult, rootLoggingBean, currentMethodName);
147 formatter.footerLogEvent();
148 }
149
150
151
152
153
154
155
156
157 void postProcessMethod(boolean completeMethodResult, LoggingBean currentLoggingBean, String currentMethod) {
158 currentLoggingBean.setCommandSuccessful(completeMethodResult);
159 currentLoggingBean.setArgs(new String[] {"executing " + currentLoggingBean.getCallingClass() + "::" + currentMethod});
160 formatter.methodLogEvent(currentLoggingBean);
161 }
162
163
164
165
166
167
168 void logNewMethodEntered(final String currentMethodName, LoggingBean loggingBean) {
169 if (logMethodsAsComments) {
170 loggingBean.setCommandName(SeleniumCommandExtensions.COMMAND_EXTENSION_LOG_COMMENT.getName());
171 loggingBean.setArgs(new String[] {"executing " + currentMethodName + "()"});
172 formatAndOutputCommand(loggingBean);
173 }
174 }
175 }