Changeset 1988 for trunk/autoquest-plugin-http/src/main/java/de
- Timestamp:
- 07/07/15 08:36:28 (9 years ago)
- Location:
- trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java
r1983 r1988 17 17 import java.io.StringWriter; 18 18 import java.util.ArrayList; 19 import java.util.Collection; 19 20 import java.util.Iterator; 20 21 import java.util.LinkedList; … … 34 35 35 36 import de.ugoe.cs.autoquest.eventcore.Event; 37 import de.ugoe.cs.autoquest.plugin.http.eventcore.EqualSOAPDataMap; 36 38 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 37 39 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; … … 53 55 * </p> 54 56 * 55 * @param sequence 56 * sequence where the events are replaced57 * @param sequences 58 * sequences where the events are replaced 57 59 * @param keepOnlySOAPEvents 58 60 * if true, all events that are not of SOAPEventType or SimpleSOAPEventType are 59 61 * removed 60 * @return sequence with {@link SimpleSOAPEventType}s instead of {@link SOAPEventType}s61 */ 62 public static List<Event> convertToSimpleSOAPEvent(List<Event> sequence,62 * @return sequences with {@link SimpleSOAPEventType}s instead of {@link SOAPEventType}s 63 */ 64 public static Collection<List<Event>> convertToSimpleSOAPEvent(Collection<List<Event>> sequences, 63 65 boolean keepOnlySOAPEvents) 64 66 { 65 List<Event> newSequence = null; 66 if (sequence != null) { 67 newSequence = new LinkedList<>(); 68 for (Event event : sequence) { 69 if (event.getType() instanceof SOAPEventType) { 70 SOAPEventType eventType = (SOAPEventType) event.getType(); 71 newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(), 72 eventType.getServiceName(), 73 eventType.getClientName(), 74 eventType 75 .getSoapRequestBody()))); 76 } 77 else { 78 if (!keepOnlySOAPEvents || event.getType() instanceof SimpleSOAPEventType) { 79 newSequence.add(event); 67 Collection<List<Event>> newSequences = new LinkedList<>(); 68 EqualSOAPDataMap equalSOAPDataMap = new EqualSOAPDataMap(); 69 for( List<Event> sequence : sequences ) { 70 List<Event> newSequence = null; 71 if (sequence != null) { 72 newSequence = new LinkedList<>(); 73 for (Event event : sequence) { 74 if (event.getType() instanceof SOAPEventType) { 75 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))); 82 } 83 else { 84 if (!keepOnlySOAPEvents || event.getType() instanceof SimpleSOAPEventType) { 85 newSequence.add(event); 86 } 80 87 } 81 88 } 82 89 } 83 } 84 return newSequence; 85 } 86 90 newSequences.add(newSequence); 91 } 92 return newSequences; 93 } 94 87 95 /** 88 96 * <p> … … 182 190 */ 183 191 public static Element getSoapRequestBodyFromEvent(Event event) { 192 return getSoapRequestBodyFromEvent(event, false); 193 } 194 195 /** 196 * <p> 197 * Helper function to get the body of a SOAP request. 198 * </p> 199 * 200 * @param event 201 * event for which the SOAP request body is retrieved 202 * @param useRandomRequestBodies 203 * defines is random request bodies are used or the body of the associated event 204 * @return body of the SOAP event 205 */ 206 public static Element getSoapRequestBodyFromEvent(Event event, boolean useRandomRequestBodies) { 184 207 Element requestBody = null; 185 208 if (event.getType() instanceof SOAPEventType) { … … 187 210 } 188 211 else if (event.getType() instanceof SimpleSOAPEventType) { 189 requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 212 if( useRandomRequestBodies ) { 213 requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapRequestBody(); 214 } else { 215 requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 216 } 190 217 } 191 218 return requestBody; … … 295 322 * </p> 296 323 * 297 * @param sequence sequences where the operation names are normalized 298 */ 299 public static List<Event> normalizeOperationNames(List<Event> sequence, String prefixToRemove, String suffixToRemove) { 300 List<Event> normalizedSequence = new LinkedList<>(); 301 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 302 Event event = eventIter.next(); 303 if ((event.getType() instanceof SimpleSOAPEventType)) { 304 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 305 String methodName = eventType.getCalledMethod(); 306 if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) { 307 methodName = methodName.substring(prefixToRemove.length(), methodName.length()); 308 // remove prefix 309 } 310 if( suffixToRemove!=null && methodName.endsWith(suffixToRemove) ) { 311 methodName = methodName.substring(0, methodName.length()-suffixToRemove.length()); 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) { 327 Collection<List<Event>> normalizedSequences = new LinkedList<>(); 328 for(List<Event> sequence : sequences ) { 329 List<Event> normalizedSequence = new LinkedList<>(); 330 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 331 Event event = eventIter.next(); 332 if ((event.getType() instanceof SimpleSOAPEventType)) { 333 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 334 String methodName = eventType.getCalledMethod(); 335 if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) { 336 methodName = methodName.substring(prefixToRemove.length(), methodName.length()); 337 // 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()); 312 343 } 313 event = new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), eventType.getClientName(), eventType.getSoapRequestBody()), event.getTarget());314 } 315 normalizedSequence .add(event);316 } 317 return normalizedSequence ;344 normalizedSequence.add(event); 345 } 346 normalizedSequences.add(normalizedSequence); 347 } 348 return normalizedSequences; 318 349 } 319 350 -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/EqualSOAPDataMap.java
r1986 r1988 15 15 package de.ugoe.cs.autoquest.plugin.http.eventcore; 16 16 17 import java.io.IOException;18 import java.io.ObjectInputStream;19 import java.io.ObjectOutputStream;20 17 import java.io.Serializable; 21 18 import java.util.Collections; … … 38 35 /** */ 39 36 private static final long serialVersionUID = 1L; 40 41 /**42 * Singleton. Handle to only instance of this class43 */44 transient private static EqualSOAPDataMap INSTANCE = new EqualSOAPDataMap();45 37 46 38 /** … … 52 44 * random number generator for picking a random request body 53 45 */ 54 transient private final Random random; 55 56 /** 57 * <p> 58 * return the instance of the class 59 * </p> 60 * 61 * @return 62 */ 63 public static EqualSOAPDataMap getInstance() { 64 return INSTANCE; 65 } 66 67 private EqualSOAPDataMap() { 68 // private constructor to avoid initialization 69 random = new Random(); 70 } 71 72 /** 73 * <p> 74 * Manual serialization of the object. Necessary to guarantee the singleton 75 * property. 76 * </p> 77 * 78 * @param s 79 * output stream for the serialization 80 * @throws IOException 81 * thrown if there is problem writing to the output stream 82 */ 83 private void writeObject(ObjectOutputStream s) throws IOException { 84 s.defaultWriteObject(); 85 s.writeObject(soapRequestBodies); 86 } 46 private final Random random = new Random(); 87 47 88 48 /** 89 49 * <p> 90 * Manual de-serialization of the object. Necessary to guarantee the 91 * singleton property. 92 * 93 * @param s 94 * input stream for the de-serialization 95 * @throws IOException 96 * thrown if there is problem reading from the input stream 97 * @throws ClassNotFoundException 98 * thrown if there is a problem reading from the input stream 50 * Default constructor. 51 * </p> 99 52 */ 100 @SuppressWarnings("unchecked") 101 private void readObject(ObjectInputStream s) throws IOException, 102 ClassNotFoundException { 103 s.defaultReadObject(); 104 if (INSTANCE == null) { 105 INSTANCE = new EqualSOAPDataMap(); 106 } 107 INSTANCE.soapRequestBodies = (Map<SimpleSOAPEventType, ListOrderedSet<String>>) s.readObject(); 53 public EqualSOAPDataMap() { 54 108 55 } 109 110 /** 111 * <p> 112 * Manual de-serialization to guarantee the singleton property. 113 * </p> 114 * 115 * @return instance of the container 116 */ 117 private Object readResolve() { 118 return INSTANCE; 119 } 120 56 121 57 /** 122 58 * <p> … … 175 111 soapRequestBodies = new HashMap<>(); 176 112 } 113 114 /** 115 * <p> 116 * returns is the current data map is empty 117 * </p> 118 * 119 * @return true if empty; false otherwise 120 */ 121 public boolean isEmpty() { 122 return soapRequestBodies.isEmpty(); 123 } 177 124 } -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java
r1987 r1988 42 42 43 43 /** 44 * see {@link RequestBodyMode}45 */46 private static RequestBodyMode requestBodyMode = RequestBodyMode.LOCALEVENT;47 48 /**49 44 * <p> 50 45 * the SOAP method called in this request … … 74 69 */ 75 70 private final String soapRequestBody; 71 72 /** 73 * TODO 74 */ 75 private final EqualSOAPDataMap equalRequestsMap; 76 76 77 77 /** … … 86 86 Element soapRequestBody) 87 87 { 88 this(calledMethod, serviceName, clientName, soapRequestBody, null); 89 } 90 91 /** 92 * <p> 93 * Constructor. Creates a new SimpleSOAPEventType with a EqualSOAPDATAMap. 94 * </p> 95 * 96 */ 97 public SimpleSOAPEventType(String calledMethod, 98 String serviceName, 99 String clientName, 100 Element soapRequestBody, 101 EqualSOAPDataMap equalRequestsMap) 102 { 88 103 if (calledMethod == null) { 89 104 throw new IllegalArgumentException("called method must not be null"); … … 99 114 this.clientName = clientName; 100 115 this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody); 101 EqualSOAPDataMap.getInstance().add(this, this.soapRequestBody); 116 this.equalRequestsMap = equalRequestsMap; 117 if( equalRequestsMap!=null ) { 118 equalRequestsMap.add(this, this.soapRequestBody); 119 } 102 120 } 103 121 … … 144 162 */ 145 163 public Element getSoapRequestBody() { 146 String requestBody; 147 switch (requestBodyMode) 148 { 149 case LOCALEVENT: 150 requestBody = soapRequestBody; 151 break; 152 case RANDOM: 153 requestBody = EqualSOAPDataMap.getInstance().getRandom(this); 154 break; 155 default: 156 throw new RuntimeException("undefined RequestBodyMode"); 157 } 158 if (requestBody == null) { 159 System.err.println("foobar" + this); 160 System.err.println(EqualSOAPDataMap.getInstance().getAll(this)); 161 } 162 try { 163 return DocumentBuilderFactory.newInstance().newDocumentBuilder() 164 .parse(new ByteArrayInputStream(requestBody.getBytes())).getDocumentElement(); 165 } 166 catch (SAXException | IOException | ParserConfigurationException e) { 167 return null; 168 } 164 return createDOMElement(soapRequestBody); 165 } 166 167 /** 168 * <p> 169 * returns a randomly draw request body for the called method using {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)} 170 * </p> 171 * 172 * @return randomly drawn body of the SOAP request 173 */ 174 public Element getRandomSoapRequestBody() { 175 if( equalRequestsMap==null ) { 176 throw new RuntimeException("cannot use random mode is no request map is available; different data missing"); 177 } 178 return createDOMElement(equalRequestsMap.getRandom(this)); 179 } 180 181 public EqualSOAPDataMap getEqualSOAPDataMap() { 182 return equalRequestsMap; 169 183 } 170 184 … … 220 234 } 221 235 222 /** 223 * <p> 224 * returns the current {@link RequestBodyMode} 225 * </p> 226 * 227 * @return the requestBodyMode 228 */ 229 public static RequestBodyMode getRequestBodyMode() { 230 return requestBodyMode; 231 } 232 233 /** 234 * <p> 235 * sets the {@link RequestBodyMode} 236 * </p> 237 * 238 * @param new requestBodyMode 239 */ 240 public static void setRequestBodyMode(RequestBodyMode requestBodyMode) { 241 SimpleSOAPEventType.requestBodyMode = requestBodyMode; 242 } 243 244 /** 245 * <p> 246 * Determines how getSoapRequestBody works. 247 * <ul> 248 * <li>LOCALEVENT: returns the request body of the event type itself</li> 249 * <li>RANDOM: returns a randomly draw request body for the called method using 250 * {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)}. 251 * </ul> 252 * </p> 253 * 254 * @author Steffen Herbold 255 */ 256 public static enum RequestBodyMode { 257 LOCALEVENT, RANDOM 258 } 236 private Element createDOMElement(String requestBody) { 237 try { 238 return DocumentBuilderFactory.newInstance().newDocumentBuilder() 239 .parse(new ByteArrayInputStream(requestBody.getBytes())).getDocumentElement(); 240 } 241 catch (SAXException | IOException | ParserConfigurationException e) { 242 return null; 243 } 244 } 245 // 246 // /** 247 // * <p> 248 // * Determines how getSoapRequestBody works. 249 // * <ul> 250 // * <li>LOCALEVENT: returns the request body of the event type itself</li> 251 // * <li>RANDOM: returns a randomly draw request body for the called method using 252 // * {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)}. 253 // * </ul> 254 // * </p> 255 // * 256 // * @author Steffen Herbold 257 // */ 258 // public static enum RequestBodyMode { 259 // LOCALEVENT, RANDOM 260 // } 259 261 }
Note: See TracChangeset
for help on using the changeset viewer.