Changeset 1984
- Timestamp:
- 07/06/15 10:59:02 (9 years ago)
- Location:
- trunk/autoquest-plugin-http
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http/pom.xml
r1945 r1984 35 35 <version>${project.parent.version}</version> 36 36 </dependency> 37 <dependency> 38 <groupId>org.apache.commons</groupId> 39 <artifactId>commons-collections4</artifactId> 40 <version>4.0</version> 41 </dependency> 37 42 </dependencies> 38 43 <build> -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java
r1928 r1984 17 17 import java.io.ByteArrayInputStream; 18 18 import java.io.IOException; 19 import java.util.Collections; 20 import java.util.HashMap; 21 import java.util.Map; 22 import java.util.Random; 23 import java.util.Set; 19 24 20 25 import javax.xml.parsers.DocumentBuilderFactory; 21 26 import javax.xml.parsers.ParserConfigurationException; 22 27 28 import org.apache.commons.collections4.set.ListOrderedSet; 23 29 import org.w3c.dom.Element; 24 30 import org.xml.sax.SAXException; … … 40 46 /** */ 41 47 private static final long serialVersionUID = 1L; 48 49 /** 50 * see {@link RequestBodyMode} 51 */ 52 private static RequestBodyMode requestBodyMode = RequestBodyMode.LOCALEVENT; 42 53 43 54 /** … … 94 105 this.clientName = clientName; 95 106 this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody); 107 EqualSOAPDataMap.INSTANCE.add(this, this.soapRequestBody); 96 108 } 97 109 … … 129 141 } 130 142 143 /** 144 * <p> 145 * returns the body of the SOAP request; how the body is determined is defined by the {@link RequestBodyMode}. 146 * </p> 147 * 148 * @return body of the SOAP request 149 */ 131 150 public Element getSoapRequestBody() { 151 String requestBody; 152 switch (requestBodyMode) 153 { 154 case LOCALEVENT: 155 requestBody = soapRequestBody; 156 break; 157 case RANDOM: 158 requestBody = EqualSOAPDataMap.INSTANCE.getRandom(this); 159 break; 160 default: 161 throw new RuntimeException("undefined RequestBodyMode"); 162 } 163 if( requestBody==null ) { 164 System.err.println("foobar" + this); 165 System.err.println(EqualSOAPDataMap.INSTANCE.getAll(this)); 166 } 132 167 try { 133 168 return DocumentBuilderFactory.newInstance().newDocumentBuilder() 134 .parse(new ByteArrayInputStream( soapRequestBody.getBytes())).getDocumentElement();169 .parse(new ByteArrayInputStream(requestBody.getBytes())).getDocumentElement(); 135 170 } 136 171 catch (SAXException | IOException | ParserConfigurationException e) { … … 138 173 } 139 174 } 175 176 140 177 141 178 /* … … 189 226 return "SimpleSOAPEventType(" + serviceName + ", " + calledMethod + ")"; 190 227 } 228 229 /** 230 * <p> 231 * returns the current {@link RequestBodyMode} 232 * </p> 233 * 234 * @return the requestBodyMode 235 */ 236 public static RequestBodyMode getRequestBodyMode() { 237 return requestBodyMode; 238 } 239 240 /** 241 * <p> 242 * sets the {@link RequestBodyMode} 243 * </p> 244 * 245 * @param new requestBodyMode 246 */ 247 public static void setRequestBodyMode(RequestBodyMode requestBodyMode) { 248 SimpleSOAPEventType.requestBodyMode = requestBodyMode; 249 } 250 251 /** 252 * <p> 253 * Determines how getSoapRequestBody works. 254 * <ul> 255 * <li>LOCALEVENT: returns the request body of the event type itself</li> 256 * <li>RANDOM: returns a randomly draw request body for the called method using {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)}. 257 * </ul> 258 * </p> 259 * 260 * @author Steffen Herbold 261 */ 262 public static enum RequestBodyMode {LOCALEVENT, RANDOM}; 263 264 /** 265 * <p> 266 * Handles all request bodies of equal SOAP events. Can be used to view either all request bodies sent to an operation or to randomly draw one of the bodies. 267 * </p> 268 * 269 * @author Steffen Herbold 270 */ 271 public static class EqualSOAPDataMap { 272 273 /** 274 * Singleton. Handle to only instance of this class 275 */ 276 public final static EqualSOAPDataMap INSTANCE = new EqualSOAPDataMap(); 277 278 /** 279 * Map with all soapRequestBodies for all equal {@link SimpleSOAPEventType}s 280 */ 281 private final Map<SimpleSOAPEventType, ListOrderedSet<String>> soapRequestBodies = new HashMap<>(); 282 283 /** 284 * random number generator for picking a random request body 285 */ 286 private final Random random = new Random(1); // TODO static seed for testing 287 288 private EqualSOAPDataMap() { 289 // private constructor to avoid initialization 290 } 291 292 /** 293 * <p> 294 * Adds a new body to the map. 295 * </p> 296 * 297 * @param simpleSOAPEventType 298 */ 299 public void add(SimpleSOAPEventType simpleSOAPEventType, String soapRequestBody) { 300 if( soapRequestBody!=null ) { 301 ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType); 302 if( requestBodySet==null ) { 303 requestBodySet = new ListOrderedSet<>(); 304 soapRequestBodies.put(simpleSOAPEventType, requestBodySet); 305 } 306 requestBodySet.add(soapRequestBody); 307 } 308 } 309 310 /** 311 * <p> 312 * Retrieves all bodies associated with the simpleSoapEventType; null if not found 313 * </p> 314 * 315 * @param simpleSoapEventType 316 * @return 317 */ 318 public Set<String> getAll(SimpleSOAPEventType simpleSoapEventType) { 319 return Collections.unmodifiableSet(soapRequestBodies.get(simpleSoapEventType)); 320 } 321 322 /** 323 * <p> 324 * Randomly draws one of the SOAP event type bodies associated with the event 325 * </p> 326 * 327 * @param simpleSOAPEventType 328 * @return 329 */ 330 public String getRandom(SimpleSOAPEventType simpleSOAPEventType) { 331 ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType); 332 if( requestBodySet==null || requestBodySet.isEmpty() ) { 333 throw new RuntimeException("no request body known for SimpleSOAPEventType: " + simpleSOAPEventType); 334 } 335 336 return requestBodySet.get(random.nextInt(requestBodySet.size())); 337 } 338 } 191 339 }
Note: See TracChangeset
for help on using the changeset viewer.