Mercurial > stress-tester
changeset 842:48681d1fd832
merge fixed
author | Devel 1 |
---|---|
date | Tue, 23 Jan 2018 11:08:35 +0100 |
parents | 6ea37bd18996 |
children | 393e5b6f9f7b |
files | stress-tester/src/main/java/com/passus/st/client/http/ReporterRemoteDestination.java stress-tester/src/test/java/com/passus/st/client/http/ReporterConfiguratorTest.java |
diffstat | 2 files changed, 94 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/ReporterRemoteDestination.java Tue Jan 23 11:05:19 2018 +0100 +++ b/stress-tester/src/main/java/com/passus/st/client/http/ReporterRemoteDestination.java Tue Jan 23 11:08:35 2018 +0100 @@ -38,7 +38,7 @@ * @author Mirosław Hawrot */ @NodeDefinitionCreate(ReporterRemoteDestination.ReporterRemoteDestinationNodeDefCreator.class) -@Plugin(name = ReporterFileDestination.TYPE, category = PluginConstants.CATEGORY_REPORTER_DESTINATION) +@Plugin(name = ReporterRemoteDestination.TYPE, category = PluginConstants.CATEGORY_REPORTER_DESTINATION) public class ReporterRemoteDestination implements ReporterDestination { public static final String TYPE = "remote";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/http/ReporterConfiguratorTest.java Tue Jan 23 11:08:35 2018 +0100 @@ -0,0 +1,93 @@ +package com.passus.st.client.http; + +import com.passus.config.Configuration; +import com.passus.config.ConfigurationContext; +import com.passus.config.ConfigurationContextImpl; +import com.passus.config.YamlConfigurationReader; +import com.passus.config.validation.Errors; +import com.passus.st.reporter.trx.SocketReporterClient; +import static com.passus.st.utils.ConfigurationContextConsts.REPORTER_DEFAULT_DESTINATION; +import static com.passus.st.utils.ConfigurationContextConsts.REPORTER_DESTINATIONS; +import java.util.List; +import static org.testng.AssertJUnit.*; +import org.testng.annotations.Test; + +/** + * + * @author mikolaj.podbielski + */ +public class ReporterConfiguratorTest { + + @Test + public void testValidate() { + } + + private static void configure(String cfgString, ConfigurationContext context) throws Exception { + Configuration config = YamlConfigurationReader.readFromString(cfgString); + ReporterConfigurator configurator = new ReporterConfigurator(); + Errors errors = new Errors(); + + configurator.configure(config, errors, context); + errors.getAllErrors().forEach(System.out::println); + assertEquals(0, errors.getErrorCount()); + + } + + private static void checkRemote(ReporterRemoteDestination remote, String host, int port, int threads) { + assertNotNull(remote); + assertEquals(host, remote.getHost()); + assertEquals(port, remote.getPort()); + assertEquals(threads, remote.getThreads()); + } + + @Test + public void testConfigure_default_noParams() throws Exception { + String cfgString + = " active: true\n"; + ConfigurationContext context = new ConfigurationContextImpl(); + + configure(cfgString, context); + + ReporterRemoteDestination remote = (ReporterRemoteDestination) context.get(REPORTER_DEFAULT_DESTINATION); + checkRemote(remote, SocketReporterClient.DEFAULT_HOST, SocketReporterClient.DEFAULT_PORT, SocketReporterClient.DEFAULT_THREADS); + + List<ReporterDestination> destinations = (List<ReporterDestination>) context.get(REPORTER_DESTINATIONS); + assertNotNull(destinations); + assertEquals(0, destinations.size()); + } + + @Test + public void testConfigure_default() throws Exception { + String cfgString + = " active: true\n" + + " host: 1.1.1.1\n" + + " port: 2222\n" + + " threads: 3\n" + + " destinations:\n" + + " - type: file\n" + + " directory: 'c:\\reporter'\n" + + " - type: remote\n" + + " - type: remote\n" + + " host: 1.1.1.2\n" + + " port: 1112\n" + + ""; + ConfigurationContext context = new ConfigurationContextImpl(); + + configure(cfgString, context); + + ReporterRemoteDestination remote = (ReporterRemoteDestination) context.get(REPORTER_DEFAULT_DESTINATION); + checkRemote(remote, "1.1.1.1", 2222, 3); + + List<ReporterDestination> destinations = (List<ReporterDestination>) context.get(REPORTER_DESTINATIONS); + assertNotNull(destinations); + assertEquals(3, destinations.size()); + + ReporterFileDestination d0 = (ReporterFileDestination) destinations.get(0); + assertEquals("c:\\reporter", d0.getDirectory().getAbsolutePath()); + + checkRemote((ReporterRemoteDestination) destinations.get(1), + SocketReporterClient.DEFAULT_HOST, SocketReporterClient.DEFAULT_PORT, SocketReporterClient.DEFAULT_THREADS); + checkRemote((ReporterRemoteDestination) destinations.get(2), "1.1.1.2", 1112, SocketReporterClient.DEFAULT_THREADS); + } + +}