From 48e61cf00f405c762631673b3b003f51cc0358fc Mon Sep 17 00:00:00 2001 From: mchrominski Date: Fri, 29 Jun 2018 16:10:02 +0200 Subject: [PATCH 1/4] Added possibility to override parameter name from the aet client --- .../aet/plugins/maven/RunTestSuiteMojo.java | 5 ++++- .../com/cognifide/aet/common/TestSuiteRunner.java | 10 +++++++++- .../com/cognifide/aet/executor/SuiteExecutor.java | 15 ++++++++++----- .../com/cognifide/aet/executor/SuiteServlet.java | 4 +++- .../aet/executor/model/TestSuiteRun.java | 12 +++++++----- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/client/aet-maven-plugin/src/main/java/com/cognifide/aet/plugins/maven/RunTestSuiteMojo.java b/client/aet-maven-plugin/src/main/java/com/cognifide/aet/plugins/maven/RunTestSuiteMojo.java index cf65d93ba..6a6f4e134 100644 --- a/client/aet-maven-plugin/src/main/java/com/cognifide/aet/plugins/maven/RunTestSuiteMojo.java +++ b/client/aet-maven-plugin/src/main/java/com/cognifide/aet/plugins/maven/RunTestSuiteMojo.java @@ -38,6 +38,9 @@ public class RunTestSuiteMojo extends AbstractMojo { @Parameter(property = "endpointDomain", defaultValue = "http://localhost:8181") private String endpointDomain; + @Parameter(property = "name") + private String name; + @Parameter(property = "domain") private String domain; @@ -58,7 +61,7 @@ public void execute() throws MojoExecutionException { validateConfiguration(); try { TestSuiteRunner testSuiteRunner = new TestSuiteRunner(endpointDomain, - mavenProject.getBuild().getDirectory(), timeout, domain, pattern, xUnit); + mavenProject.getBuild().getDirectory(), timeout, name, domain, pattern, xUnit); testSuiteRunner.runTestSuite(testSuite); } catch (AETException e) { diff --git a/client/client-core/src/main/java/com/cognifide/aet/common/TestSuiteRunner.java b/client/client-core/src/main/java/com/cognifide/aet/common/TestSuiteRunner.java index 5b5042084..7b239ae8f 100644 --- a/client/client-core/src/main/java/com/cognifide/aet/common/TestSuiteRunner.java +++ b/client/client-core/src/main/java/com/cognifide/aet/common/TestSuiteRunner.java @@ -58,18 +58,23 @@ protected DateFormat initialValue() { private final String endpointDomain; + private final String name; + private final String domain; private final String patternCorrelationId; private final boolean xUnit; - public TestSuiteRunner(String endpointDomain, String buildDirectory, int timeout, String domain, + + public TestSuiteRunner(String endpointDomain, String buildDirectory, int timeout, + String name, String domain, String patternCorrelationId, boolean xUnit) { this.redirectWriter = new RedirectWriter(buildDirectory); this.buildDirectory = buildDirectory; this.timeout = timeout; this.endpointDomain = endpointDomain; + this.name = name; this.domain = domain; this.patternCorrelationId = patternCorrelationId; this.xUnit = xUnit; @@ -126,6 +131,9 @@ private boolean hasErrors(SuiteExecutionResult suiteExecutionResult) { private SuiteExecutionResult startSuiteExecution(File testSuite) { MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create() .addBinaryBody("suite", testSuite, ContentType.APPLICATION_XML, testSuite.getName()); + if (name != null) { + entityBuilder.addTextBody("name", name); + } if (domain != null) { entityBuilder.addTextBody("domain", domain); } diff --git a/test-executor/src/main/java/com/cognifide/aet/executor/SuiteExecutor.java b/test-executor/src/main/java/com/cognifide/aet/executor/SuiteExecutor.java index 1ff057803..f292664c4 100644 --- a/test-executor/src/main/java/com/cognifide/aet/executor/SuiteExecutor.java +++ b/test-executor/src/main/java/com/cognifide/aet/executor/SuiteExecutor.java @@ -130,14 +130,15 @@ public void activate(Map properties) { * patterns source * @return status of the suite execution */ - HttpSuiteExecutionResultWrapper execute(String suiteString, String domain, String pattern) { + HttpSuiteExecutionResultWrapper execute(String suiteString, String name, String domain, + String pattern) { SuiteRunner suiteRunner = null; HttpSuiteExecutionResultWrapper result; TestSuiteParser xmlFileParser = new XmlTestSuiteParser(); try { TestSuiteRun testSuiteRun = xmlFileParser.parse(suiteString); - testSuiteRun = overrideDomainIfDefined(testSuiteRun, domain); + testSuiteRun = overrideDomainOrNameIfDefined(testSuiteRun, name, domain); testSuiteRun.setPatternCorrelationId(pattern); String validationError = suiteValidator.validateTestSuiteRun(testSuiteRun); @@ -204,11 +205,15 @@ public SuiteStatusResult getExecutionStatus(String correlationId) { return result; } - private TestSuiteRun overrideDomainIfDefined(TestSuiteRun testSuiteRun, String domain) { + private TestSuiteRun overrideDomainOrNameIfDefined(TestSuiteRun testSuiteRun, String name, + String domain) { TestSuiteRun localTestSuiteRun = testSuiteRun; - if (StringUtils.isNotBlank(domain)) { + if (StringUtils.isNotBlank(name) || StringUtils.isNotBlank(domain)) { List tests = Lists.newArrayList(localTestSuiteRun.getTestRunMap().values()); - localTestSuiteRun = new TestSuiteRun(localTestSuiteRun, domain, tests); + String overriddenName = StringUtils.defaultString(name, localTestSuiteRun.getName()); + String overridenDomain = StringUtils.defaultString(domain, localTestSuiteRun.getDomain()); + localTestSuiteRun = new TestSuiteRun(localTestSuiteRun, overriddenName, overridenDomain, + tests); } return localTestSuiteRun; } diff --git a/test-executor/src/main/java/com/cognifide/aet/executor/SuiteServlet.java b/test-executor/src/main/java/com/cognifide/aet/executor/SuiteServlet.java index db61d1d65..f644d4ae2 100644 --- a/test-executor/src/main/java/com/cognifide/aet/executor/SuiteServlet.java +++ b/test-executor/src/main/java/com/cognifide/aet/executor/SuiteServlet.java @@ -53,6 +53,7 @@ public class SuiteServlet extends HttpServlet { private static final Logger LOGGER = LoggerFactory.getLogger(SuiteServlet.class); private static final String SERVLET_PATH = "/suite"; private static final String SUITE_PARAM = "suite"; + private static final String NAME_PARAM = "name"; private static final String DOMAIN_PARAM = "domain"; private static final String PATTERN_PARAM = "pattern"; @@ -74,12 +75,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) if (ServletFileUpload.isMultipartContent(request)) { Map requestData = getRequestData(request); final String suite = requestData.get(SUITE_PARAM); + final String name = requestData.get(NAME_PARAM); final String domain = requestData.get(DOMAIN_PARAM); final String pattern = requestData.get(PATTERN_PARAM); if (StringUtils.isNotBlank(suite)) { HttpSuiteExecutionResultWrapper resultWrapper = suiteExecutor - .execute(suite, domain, pattern); + .execute(suite, name, domain, pattern); final SuiteExecutionResult suiteExecutionResult = resultWrapper.getExecutionResult(); Gson gson = new Gson(); diff --git a/test-executor/src/main/java/com/cognifide/aet/executor/model/TestSuiteRun.java b/test-executor/src/main/java/com/cognifide/aet/executor/model/TestSuiteRun.java index 2aef07abe..a2d38fd5a 100644 --- a/test-executor/src/main/java/com/cognifide/aet/executor/model/TestSuiteRun.java +++ b/test-executor/src/main/java/com/cognifide/aet/executor/model/TestSuiteRun.java @@ -64,8 +64,8 @@ public TestSuiteRun(String name, String company, String project, String domain, this.testRunMap = getMap(testRunList); } - public TestSuiteRun(TestSuiteRun testSuiteRun, String domain, List tests) { - this.name = testSuiteRun.getName(); + public TestSuiteRun(TestSuiteRun testSuiteRun, String name, String domain, List tests) { + this.name = name; this.company = testSuiteRun.getCompany(); this.project = testSuiteRun.getProject(); this.domain = domain; @@ -142,9 +142,11 @@ public void setVersion(Long version) { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("name", name).add("company", company) - .add("project", project) - .add("domain", domain).add("correlationId", correlationId) + return MoreObjects.toStringHelper(this) + .add("name", name) // + .add("company", company) // + .add("project", project) // + .add("domain", domain).add("correlationId", correlationId) // .add("version", version).toString(); } From 686e9402b4a1bd1a1b13ef034769197beea74e6a Mon Sep 17 00:00:00 2001 From: mchrominski Date: Fri, 29 Jun 2018 16:31:34 +0200 Subject: [PATCH 2/4] Updated documentation to reflect the possibility to override name parameter --- documentation/src/main/wiki/ClientApplication.md | 8 ++++++++ documentation/src/main/wiki/DefiningSuite.md | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/wiki/ClientApplication.md b/documentation/src/main/wiki/ClientApplication.md index 6522dadfa..76a06a91e 100644 --- a/documentation/src/main/wiki/ClientApplication.md +++ b/documentation/src/main/wiki/ClientApplication.md @@ -31,6 +31,7 @@ mvn aet:run -DtestSuite=FULL_PATH_TO_TEST_SUITE | --------- | ----------- | ------------- | --------- | | `testSuite` | The full path to the suite definition file (at least a file name with an extension, e.g. `testSuite.xml`).| suite.xml | no | | `endpointDomain` | the URL to the main AET domain | http://localhost:8181 | no | +| `name` | Overrides the *name* parameter value from the test suite definition. | - | no | | `domain` | Overrides the *domain* parameter value from the test suite definition. | - | no | | `timeout` | Milliseconds to detect the timeout since the last status received from AET. This is useful to abort the test run if there is no activity for a long time. | 300000 (5 minutes) | no | | `pattern` | Id of suite that will be used as patterns source. Identical structure of pattern and current suites is assumed. | - | no | @@ -54,6 +55,13 @@ If all URLs in your test suite point to a single domain, you can specify it so i mvn aet:run -DtestSuite=suite.xml -Ddomain=https://en.wikipedia.org ``` + +If the same suite is being used to test multiple environments, you can specify the name correlated with the execution output. When the patterns *are not being shared* across multiple environments but the suite definition is the same, you may override the name, that is typically placed in the suite XML. For example: +``` +mvn aet:run -DtestSuite=suite.xml -Dname=env-integration-suite +``` + + If you want the test run to fail if its run takes too much time, you can specify the timeout (in milliseconds) in the following way: ``` mvn aet:run -DtestSuite=suite.xml -Dtimeout=2000 diff --git a/documentation/src/main/wiki/DefiningSuite.md b/documentation/src/main/wiki/DefiningSuite.md index 107566140..83aa983c2 100644 --- a/documentation/src/main/wiki/DefiningSuite.md +++ b/documentation/src/main/wiki/DefiningSuite.md @@ -56,6 +56,6 @@ The Root element for the xml definition, each test suite definition consists of | `name` | Name of the test suite. It should contain lowercase letters, digits and/or characters: `-`, `_` only. | yes | | `company` | Name of the company. It should contain lowercase letters, digits and/or characters: `-` only.| yes | | `project` | Name of the project. It should contain lowercase letters, digits and/or characters: `-` only.| yes | -| `domain` | General domain name consistent for all urls considered. Every url link is built as a concatenation of the *domain* name and the *href* attribute of it. If the `domain` property is not set, then the `href` value in the `url` definition should contain a full valid url. See more in the [[Urls|Urls]] section. | no | +| `domain` | General domain name consistent for all urls considered. Every url link is built as a concatenation of the *domain* name and the *href* attribute of it. If the `domain` property is not set, then the `href` value in the `url` definition should contain a full valid url. See more in the [Urls](../Urls) section. | no | The `suite` element contains one or more **[[test|SuiteStructure#test]]** elements. From 5920dd5fd4ba647eb59d65d51d1cc54d7c6f80b0 Mon Sep 17 00:00:00 2001 From: mchrominski Date: Sat, 30 Jun 2018 20:10:49 +0200 Subject: [PATCH 3/4] Changelog updated to include PR-271 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8879113ab..da17c108e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to AET will be documented in this file. - [PR-260](https://github.com/Cognifide/aet/pull/260) Upgrade to Karaf 4.2.0 - [PR-261](https://github.com/Cognifide/aet/pull/261) AET artifacts folders watched for new files - [PR-265](https://github.com/Cognifide/aet/pull/265) Runner simplification refactor +- [PR-271](https://github.com/Cognifide/aet/pull/271) Added possibility to override name parameter from the aet client ## Version 2.1.5 From e50763610fa30a38afee1b916939b5e98c0d9edb Mon Sep 17 00:00:00 2001 From: Maciej Laskowski Date: Mon, 2 Jul 2018 14:12:45 +0200 Subject: [PATCH 4/4] Update DefiningSuite.md --- documentation/src/main/wiki/DefiningSuite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/wiki/DefiningSuite.md b/documentation/src/main/wiki/DefiningSuite.md index 83aa983c2..43b0e1353 100644 --- a/documentation/src/main/wiki/DefiningSuite.md +++ b/documentation/src/main/wiki/DefiningSuite.md @@ -56,6 +56,6 @@ The Root element for the xml definition, each test suite definition consists of | `name` | Name of the test suite. It should contain lowercase letters, digits and/or characters: `-`, `_` only. | yes | | `company` | Name of the company. It should contain lowercase letters, digits and/or characters: `-` only.| yes | | `project` | Name of the project. It should contain lowercase letters, digits and/or characters: `-` only.| yes | -| `domain` | General domain name consistent for all urls considered. Every url link is built as a concatenation of the *domain* name and the *href* attribute of it. If the `domain` property is not set, then the `href` value in the `url` definition should contain a full valid url. See more in the [Urls](../Urls) section. | no | +| `domain` | General domain name consistent for all urls considered. Every url link is built as a concatenation of the *domain* name and the *href* attribute of it. If the `domain` property is not set, then the `href` value in the `url` definition should contain a full valid url. See more in the [[Urls]] section. | no | The `suite` element contains one or more **[[test|SuiteStructure#test]]** elements.