Mercurial > stress-tester
changeset 931:5ce6fbe6a4e7
refactoring
author | Devel 1 |
---|---|
date | Fri, 27 Apr 2018 16:09:10 +0200 |
parents | b65a8ddf4f12 |
children | 60057c161d4d |
files | stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java |
diffstat | 1 files changed, 52 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Mon May 07 13:01:36 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Fri Apr 27 16:09:10 2018 +0200 @@ -42,7 +42,6 @@ return null; } - private AbstractNameValueOperation createNameValueOperation(CTupleNode nodeTuple, Class<? extends AbstractNameValueOperation> clazz, Errors errors, ConfigurationContext context) { @@ -132,6 +131,57 @@ return op; } + private ContentOperation createContentOperation(CTupleNode tuple, Errors errors, ConfigurationContext context) { + ContentOperation op = null; + + if (validateType(tuple.getNode(), NodeType.MAP, errors)) { + CTupleNode valTupleNode = ((CMapNode) tuple.getNode()).getFirstChild(); + if (valTupleNode != null) { + String rule = valTupleNode.getName(); + ContentReplacer replacer; + try { + replacer = ContentExtractorUtils.createReplacer(rule); + } catch (Exception e) { + errors.reject(valTupleNode, "Invalid rule."); + return null; + } + + CNode newValueSpecNode = valTupleNode.getNode(); + String newValue = null; + if (newValueSpecNode.getType() == NodeType.VALUE) { + newValue = ConfigurationUtils.extractString(newValueSpecNode, errors); + } else if (newValueSpecNode.getType() == NodeType.MAP) { + CMapNode valAndParamNode = (CMapNode) newValueSpecNode; + List<CTupleNode> valAndParam = valAndParamNode.getChildren(); + for (CTupleNode t : valAndParam) { + String name = t.getName(); + switch (name) { + case "value": + newValue = ConfigurationUtils.extractString(t.getNode(), errors); + break; + case "*escape": + Boolean escape = ConfigurationUtils.extractBoolean(t.getNode(), errors); + replacer.setOption("escape", escape); + break; + default: + errors.reject(newValueSpecNode, "Invalid param: " + name); + break; + } + } + } else { + return null; + } + if (errors.hasError() || newValue == null) { + return null; + } + + op = new ContentOperation(replacer, newValue); + } + } + + return op; + } + @SuppressWarnings("unchecked") @Override public CValueNode transform(CNode node, Errors errors, ConfigurationContext context) { @@ -191,50 +241,7 @@ op = createNameValueOperation(tuple, SetQueryParameterOperation.class, errors, context); break; case "setcontent": - if (validateType(tuple.getNode(), NodeType.MAP, errors)) { - CTupleNode valTupleNode = ((CMapNode) tuple.getNode()).getFirstChild(); - if (valTupleNode != null) { - String rule = valTupleNode.getName(); - ContentReplacer replacer; - try { - replacer = ContentExtractorUtils.createReplacer(rule); - } catch (Exception e) { - errors.reject(valTupleNode, "Invalid rule."); - break; - } - - CNode newValueSpecNode = valTupleNode.getNode(); - String newValue = null; - if (newValueSpecNode.getType() == NodeType.VALUE) { - newValue = ConfigurationUtils.extractString(newValueSpecNode, errors); - } else if (newValueSpecNode.getType() == NodeType.MAP) { - CMapNode valAndParamNode = (CMapNode) newValueSpecNode; - List<CTupleNode> valAndParam = valAndParamNode.getChildren(); - for (CTupleNode t : valAndParam) { - String name = t.getName(); - switch (name) { - case "value": - newValue = ConfigurationUtils.extractString(t.getNode(), errors); - break; - case "*escape": - Boolean escape = ConfigurationUtils.extractBoolean(t.getNode(), errors); - replacer.setOption("escape", escape); - break; - default: - errors.reject(newValueSpecNode, "Invalid param: " + name); - break; - } - } - } else { - break; - } - if (errors.hasError() || newValue == null) { - break; - } - - op = new ContentOperation(replacer, newValue); - } - } + op = createContentOperation(tuple, errors, context); break; default: throw new IllegalStateException("Not supported operation '" + opName + "'.");