Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to override name parameter from the aet client #271

Merged
merged 7 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ All notable changes to AET will be documented in this file.
## Unreleased
**List of changes that are finished but not yet released in any final version.**

## Version 2.1.6
- [PR-271](https://github.com/Cognifide/aet/pull/271) Added possibility to override name parameter from the aet client

## Version 2.1.6

- [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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions documentation/src/main/wiki/ClientApplication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/main/wiki/DefiningSuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ public void activate(Map<String, Object> 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);
Expand Down Expand Up @@ -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<TestRun> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -74,12 +75,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
if (ServletFileUpload.isMultipartContent(request)) {
Map<String, String> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestRun> tests) {
this.name = testSuiteRun.getName();
public TestSuiteRun(TestSuiteRun testSuiteRun, String name, String domain, List<TestRun> tests) {
this.name = name;
this.company = testSuiteRun.getCompany();
this.project = testSuiteRun.getProject();
this.domain = domain;
Expand Down Expand Up @@ -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();
}

Expand Down