Changeset 1992
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java
r1988 r1992 18 18 import java.util.ArrayList; 19 19 import java.util.Collection; 20 import java.util.HashSet; 20 21 import java.util.Iterator; 21 22 import java.util.LinkedList; 22 23 import java.util.List; 24 import java.util.Set; 23 25 24 26 import javax.xml.transform.Transformer; … … 51 53 /** 52 54 * <p> 55 * Defines how sequences are ordered: 56 * <ul> 57 * <li>REQUEST: by the request order id</li> 58 * <li>RESPONSE: by the response order id</li> 59 * </ul> 60 * </p> 61 * 62 * @author Steffen Herbold 63 */ 64 public enum SequenceOrder { 65 REQUEST, RESPONSE 66 } 67 68 /** 69 * <p> 53 70 * Replaces events with a {@link SOAPEventType} with new events of {@link SimpleSOAPEventType} 54 71 * and no target. … … 63 80 */ 64 81 public static Collection<List<Event>> convertToSimpleSOAPEvent(Collection<List<Event>> sequences, 65 boolean keepOnlySOAPEvents)82 boolean keepOnlySOAPEvents) 66 83 { 67 84 Collection<List<Event>> newSequences = new LinkedList<>(); 68 85 EqualSOAPDataMap equalSOAPDataMap = new EqualSOAPDataMap(); 69 for ( List<Event> sequence : sequences) {86 for (List<Event> sequence : sequences) { 70 87 List<Event> newSequence = null; 71 88 if (sequence != null) { … … 74 91 if (event.getType() instanceof SOAPEventType) { 75 92 SOAPEventType eventType = (SOAPEventType) event.getType(); 76 newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(), 77 eventType.getServiceName(), 78 eventType.getClientName(), 79 eventType 80 .getSoapRequestBody(), 81 equalSOAPDataMap))); 93 newSequence.add(new Event(new SimpleSOAPEventType(eventType 94 .getCalledMethod(), eventType.getServiceName(), eventType 95 .getClientName(), eventType.getSoapRequestBody(), equalSOAPDataMap))); 82 96 } 83 97 else { … … 92 106 return newSequences; 93 107 } 94 95 /** 96 * <p> 97 * Removes all non SOAP events from a sequence. Warning: this change is performed in-place! 108 109 /** 110 * <p> 111 * Removes all non SOAP events from the contained sequences 112 * </p> 113 * 114 * @param sequences 115 * sequences where the events are replaced 116 */ 117 public static Collection<List<Event>> removeNonSOAPEvents(Collection<List<Event>> sequences) { 118 Collection<List<Event>> soapOnlySequences = new LinkedList<>(); 119 for (List<Event> sequence : sequences) { 120 soapOnlySequences.add(removeNonSOAPEvents(sequence)); 121 } 122 return soapOnlySequences; 123 } 124 125 /** 126 * <p> 127 * Removes all non SOAP events from a sequence 98 128 * </p> 99 129 * … … 101 131 * sequence where the events are replaced 102 132 */ 103 public static void removeNonSOAPEvents(List<Event> sequence) { 104 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 105 Event event = eventIter.next(); 106 if (!(event.getType() instanceof SOAPEventType)) { 107 eventIter.remove(); 108 } 109 } 133 public static List<Event> removeNonSOAPEvents(List<Event> sequence) { 134 List<Event> soapOnlySequence = new LinkedList<>(); 135 for (Event event : sequence) { 136 if (event.getType() instanceof SOAPEventType) { 137 soapOnlySequence.add(event); 138 } 139 } 140 return soapOnlySequence; 110 141 } 111 142 … … 192 223 return getSoapRequestBodyFromEvent(event, false); 193 224 } 194 225 195 226 /** 196 227 * <p> … … 210 241 } 211 242 else if (event.getType() instanceof SimpleSOAPEventType) { 212 if ( useRandomRequestBodies) {243 if (useRandomRequestBodies) { 213 244 requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapRequestBody(); 214 } else { 245 } 246 else { 215 247 requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 216 248 } … … 316 348 return attributeValues; 317 349 } 318 319 /** 320 * <p> 321 * Allows the removal of pre- and suffixes from SOAP operation names in {@link SimpleSOAPEventType}. 322 * </p> 323 * 324 * @param sequences sequences where the operation names are normalized 325 */ 326 public static Collection<List<Event>> normalizeOperationNames(Collection<List<Event>> sequences, String prefixToRemove, String suffixToRemove) { 350 351 /** 352 * <p> 353 * Allows the removal of pre- and suffixes from SOAP operation names in 354 * {@link SimpleSOAPEventType}. 355 * </p> 356 * 357 * @param sequences 358 * sequences where the operation names are normalized 359 */ 360 public static Collection<List<Event>> normalizeOperationNames(Collection<List<Event>> sequences, 361 String prefixToRemove, 362 String suffixToRemove) 363 { 327 364 Collection<List<Event>> normalizedSequences = new LinkedList<>(); 328 for (List<Event> sequence : sequences) {365 for (List<Event> sequence : sequences) { 329 366 List<Event> normalizedSequence = new LinkedList<>(); 330 367 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { … … 333 370 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 334 371 String methodName = eventType.getCalledMethod(); 335 if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) { 336 methodName = methodName.substring(prefixToRemove.length(), methodName.length()); 372 if (prefixToRemove != null && methodName.startsWith(prefixToRemove)) { 373 methodName = 374 methodName.substring(prefixToRemove.length(), methodName.length()); 337 375 // remove prefix 338 } 339 if( suffixToRemove!=null && methodName.endsWith(suffixToRemove) ) { 340 methodName = methodName.substring(0, methodName.length()-suffixToRemove.length()); 341 } 342 event = new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), eventType.getClientName(), eventType.getSoapRequestBody(), eventType.getEqualSOAPDataMap()), event.getTarget()); 376 } 377 if (suffixToRemove != null && methodName.endsWith(suffixToRemove)) { 378 methodName = 379 methodName.substring(0, methodName.length() - suffixToRemove.length()); 380 } 381 event = 382 new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), 383 eventType.getClientName(), 384 eventType.getSoapRequestBody(), 385 eventType.getEqualSOAPDataMap()), 386 event.getTarget()); 343 387 } 344 388 normalizedSequence.add(event); … … 347 391 } 348 392 return normalizedSequences; 393 } 394 395 /** 396 * <p> 397 * Sorts the sequences by the orderingId of the requests/responses. This function only supports 398 * the ordering of {@link Event}s with a {@link SOAPEventType}. 399 * </p> 400 * 401 * @param sequences 402 * sequences to be order 403 * @param orderType 404 * determines if sequences are ordered by request or response 405 * @return sorted sequences 406 */ 407 public static Collection<List<Event>> sortSequences(Collection<List<Event>> sequences, 408 SequenceOrder orderType) 409 { 410 Collection<List<Event>> sortedSequences = new LinkedList<>(); 411 for (List<Event> sequence : sequences) { 412 // use insertion sort 413 List<Event> sortedSequence = new LinkedList<>(); 414 long lastOrderId = Long.MIN_VALUE; 415 long selectedOrderId; 416 Event selectedEvent; 417 while (sortedSequence.size() != sequence.size()) { 418 selectedEvent = null; 419 selectedOrderId = Long.MAX_VALUE; 420 for (Event event : sequence) { 421 if (!(event.getType() instanceof SOAPEventType)) { 422 throw new RuntimeException( 423 "Can only order SOAPEventTypes. SimpleSOAPEvent is also not supported. Event type found: " + 424 event.getType().getClass().getName()); 425 } 426 SOAPEventType soapEventType = (SOAPEventType) event.getType(); 427 long eventOrderId; 428 switch (orderType) 429 { 430 case REQUEST: 431 eventOrderId = soapEventType.getExchange().getRequest().getOrderingId(); 432 break; 433 case RESPONSE: 434 eventOrderId = 435 soapEventType.getExchange().getResponse().getOrderingId(); 436 break; 437 default: 438 throw new RuntimeException("unsupported order type: " + 439 orderType.toString()); 440 } 441 if (eventOrderId > lastOrderId && eventOrderId < selectedOrderId) { 442 selectedOrderId = eventOrderId; 443 selectedEvent = event; 444 } 445 } 446 if (selectedEvent != null) { 447 sortedSequence.add(selectedEvent); 448 lastOrderId = selectedOrderId; 449 } 450 else { 451 throw new RuntimeException( 452 "could not select next event; possibly the same order Id for multiple exchanges events!?"); 453 } 454 } 455 sortedSequences.add(sortedSequence); 456 } 457 return sortedSequences; 458 } 459 460 /** 461 * <p> 462 * Removes calls to and from all ignored services from the sequences. 463 * </p> 464 * 465 * @param sequences sequences where the ignored services are removed 466 * @param ignoredServicesString comma separted string that defines the ignored services 467 * @return sequences without events that reference the ignored services 468 */ 469 public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, String ignoredServicesString) { 470 Set<String> ignoredServices = new HashSet<>(); 471 if (ignoredServicesString != null) { 472 for (String service : ignoredServicesString.split(",")) { 473 ignoredServices.add(service.trim()); 474 } 475 } 476 return removeCallsToIgnoredServices(sequences, ignoredServices); 477 } 478 479 /** 480 * <p> 481 * Removes calls to and from all ignored services from the sequences. 482 * </p> 483 * 484 * @param sequences sequences where the ignored services are removed 485 * @param ignoredServices set with all ignored service names 486 * @return sequences without events that reference the ignored services 487 */ 488 public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, Set<String> ignoredServices) { 489 Collection<List<Event>> onlyAcceptedServicesSequences = new LinkedList<>(); 490 for (List<Event> sequence : sequences) { 491 List<Event> onlyAcceptedServicesSequence = new LinkedList<>(); 492 for (Event event : sequence) { 493 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 494 if (!ignoredServices.contains(eventType.getServiceName()) && 495 !ignoredServices.contains(eventType.getClientName()) ) { 496 onlyAcceptedServicesSequence.add(event); 497 } 498 } 499 onlyAcceptedServicesSequences.add(onlyAcceptedServicesSequence); 500 } 501 return onlyAcceptedServicesSequences; 349 502 } 350 503 -
trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java
r1989 r1992 42 42 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 43 43 import de.ugoe.cs.autoquest.plugin.http.SOAPUtils; 44 import de.ugoe.cs.autoquest.plugin.http.SOAPUtils.SequenceOrder; 44 45 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 45 46 import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; … … 330 331 "_" + i, 331 332 properties.getProperty("test.context"), 332 true));333 Boolean.parseBoolean(properties.getProperty("testcases.data.random", "false")))); 333 334 lengths[i - 1] = sequence.size(); 334 335 i++; … … 383 384 Collection<List<Event>> sequences = parser.getSequences(); 384 385 385 // remove non SOAP events and convert to SimpleSOAPEventType386 Collection<List<Event>> tmpSeqs = SOAPUtils.convertToSimpleSOAPEvent(sequences, true);387 // normalize method names388 Collection<List<Event>> simpleSOAPSequences = SOAPUtils.normalizeOperationNames(tmpSeqs, properties386 sequences = SOAPUtils.removeNonSOAPEvents(sequences); 387 sequences = SOAPUtils.sortSequences(sequences, SequenceOrder.REQUEST); 388 sequences = SOAPUtils.convertToSimpleSOAPEvent(sequences, true); 389 sequences = SOAPUtils.normalizeOperationNames(sequences, properties 389 390 .getProperty("methodName.prefixToRemove"), properties 390 391 .getProperty("methodName.suffixToRemove")); 391 392 // remove calls to ignored services 393 Set<String> ignoredServices = new HashSet<>(); 394 String ignoredServicesString = properties.getProperty("test.ignored.services"); 395 if (ignoredServicesString != null) { 396 for (String service : ignoredServicesString.split(",")) { 397 ignoredServices.add(service.trim()); 398 } 399 } 400 401 for (List<Event> sequence : simpleSOAPSequences) { 402 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 403 Event event = eventIter.next(); 404 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 405 if (ignoredServices.contains(eventType.getServiceName())) { 406 eventIter.remove(); 407 } 408 else if( ignoredServices.contains(eventType.getClientName())) { 409 eventIter.remove(); 410 } 411 } 412 } 413 return simpleSOAPSequences; 392 sequences = SOAPUtils.removeCallsToIgnoredServices(sequences, properties.getProperty("test.ignored.services")); 393 394 return sequences; 414 395 } 415 396
Note: See TracChangeset
for help on using the changeset viewer.