1 16 package org.apache.commons.latka; 17 18 import org.apache.commons.latka.event.LatkaEventInfo; 19 import org.apache.commons.latka.event.LatkaEventListener; 20 import org.apache.commons.latka.event.ReportMessageEvent; 21 import org.apache.commons.latka.event.RequestEvent; 22 import org.apache.commons.latka.event.SuiteEvent; 23 import org.apache.commons.latka.http.Request; 24 import org.apache.commons.latka.http.Session; 25 26 import java.util.HashMap ; 27 import java.util.LinkedList ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import org.apache.log4j.Category; 32 33 43 public class DefaultLatkaEventInfo implements LatkaEventInfo { 44 45 48 protected Map _requestSucceeded = new HashMap (); 49 50 53 protected Map _sessionSucceeded = new HashMap (); 54 55 59 protected boolean _suiteSucceeded = true; 60 61 65 protected List _failedResponses = new LinkedList (); 66 67 protected LatkaEventListener _listener = null; 68 69 72 protected static final Category _log = 73 Category.getInstance(DefaultLatkaEventInfo.class); 74 75 public DefaultLatkaEventInfo(LatkaEventListener listener) { 76 _listener = listener; 77 } 78 79 85 public void requestSucceeded(RequestEvent event) { 86 recordSuccess(event, true); 87 _listener.requestSucceeded(event); 88 } 89 90 97 public void requestFailed(RequestEvent event) { 98 recordSuccess(event, false); 99 _failedResponses.add(event.getResponse()); 100 _listener.requestFailed(event); 101 } 102 103 109 public void requestSkipped(RequestEvent event) { 110 recordSuccess(event, false); 111 _listener.requestSkipped(event); 112 } 113 114 120 public void requestError(RequestEvent event) { 121 recordSuccess(event, false); 122 _listener.requestError(event); 123 } 124 125 132 public void reportMessage(ReportMessageEvent event) { 133 _listener.reportMessage(event); 134 } 135 136 141 public void suiteCompleted(SuiteEvent event) { 142 _listener.suiteCompleted(event); 143 } 144 145 154 protected void recordSuccess (RequestEvent event, boolean bool) { 155 if (bool == false) { 156 _suiteSucceeded = false; 157 _requestSucceeded.put(event.getRequest(), new Boolean (bool)); 158 _sessionSucceeded.put(event.getSession(), new Boolean (bool)); 159 _log.info("request failed"); 160 } 161 } 162 163 170 public boolean didRequestSucceed(Request request) { 171 Boolean bool = (Boolean ) _requestSucceeded.get(request); 172 173 if (bool == null || bool.booleanValue() == true) { 174 return true; 175 } else { 176 return false; 177 } 178 179 } 180 181 190 public boolean didSessionSucceed(Session session) { 191 Boolean bool = (Boolean ) _sessionSucceeded.get(session); 192 193 if (bool == null || bool.booleanValue() == true) { 194 return true; 195 } else { 196 return false; 197 } 198 } 199 200 205 public boolean didSuiteSucceed() { 206 return _suiteSucceeded; 207 } 208 209 213 public List getFailedResponses() { 214 return _failedResponses; 215 } 216 } 217 | Popular Tags |