Mercurial > stress-tester
changeset 866:9aa23298c908
reverseTransform in progress
author | Devel 1 |
---|---|
date | Wed, 24 Jan 2018 14:52:59 +0100 |
parents | 3f2efeebbb6d |
children | af16052b659b |
files | stress-tester/src/main/java/com/passus/st/config/StringToExecutableStatementValueTransformer.java stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapperValueTransformer.java stress-tester/src/main/java/com/passus/st/emitter/RuleSessionMapperValueTransformer.java stress-tester/src/test/java/com/passus/st/emitter/RuleSessionMapperValueTransformerTest.java |
diffstat | 4 files changed, 25 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/config/StringToExecutableStatementValueTransformer.java Wed Jan 24 13:05:15 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/config/StringToExecutableStatementValueTransformer.java Wed Jan 24 14:52:59 2018 +0100 @@ -27,7 +27,7 @@ @Override public Object reverseTransform(Object obj) throws ConversionException { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("Impossible."); } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapperValueTransformer.java Wed Jan 24 13:05:15 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapperValueTransformer.java Wed Jan 24 14:52:59 2018 +0100 @@ -3,6 +3,7 @@ import com.passus.commons.ConversionException; import com.passus.config.ValueTransformer; import java.util.List; +import java.util.stream.Collectors; /** * @@ -43,7 +44,17 @@ @Override public Object reverseTransform(Object obj) throws ConversionException { - throw new UnsupportedOperationException("Not supported yet."); + if (obj == null) { + return null; + } + if (!(obj instanceof RuleBasedSessionMapper)) { + throw new ConversionException(); + } + + RuleBasedSessionMapper mapper = (RuleBasedSessionMapper) obj; + List<RuleBasedSessionMapper.Rule> rules = mapper.getRules(); + List<String> collected = rules.stream().map(Object::toString).collect(Collectors.toList()); + return collected; } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/RuleSessionMapperValueTransformer.java Wed Jan 24 13:05:15 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/emitter/RuleSessionMapperValueTransformer.java Wed Jan 24 14:52:59 2018 +0100 @@ -27,7 +27,14 @@ @Override public Object reverseTransform(Object obj) throws ConversionException { - throw new UnsupportedOperationException("Not supported yet."); + if (obj == null) { + return null; + } + if (!(obj instanceof RuleBasedSessionMapper.Rule)) { + throw new ConversionException(); + } + + return obj.toString(); } }
--- a/stress-tester/src/test/java/com/passus/st/emitter/RuleSessionMapperValueTransformerTest.java Wed Jan 24 13:05:15 2018 +0100 +++ b/stress-tester/src/test/java/com/passus/st/emitter/RuleSessionMapperValueTransformerTest.java Wed Jan 24 14:52:59 2018 +0100 @@ -14,11 +14,15 @@ public void testTransform() throws Exception { RuleSessionMapperValueTransformer trans = new RuleSessionMapperValueTransformer(); String value = "1.1.1.1:* -> 2.2.2.2:90"; + Object res = trans.transform(value); assertTrue(res instanceof RuleBasedSessionMapper.Rule); RuleBasedSessionMapper.Rule rule = (RuleBasedSessionMapper.Rule) res; assertEquals(new SocketAddress("2.2.2.2:90"), rule.getRemoteAddress()); assertEquals(SessionMapper.ANY_SOCKET, rule.getBindAddress()); + + Object rev = trans.reverseTransform(rule); + assertEquals(value, rev); } }