Changeset 1988 for trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java
- Timestamp:
- 07/07/15 08:36:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.