Skip to content

Commit

Permalink
Config loading tweaks (#57)
Browse files Browse the repository at this point in the history
tweaked the hierarchy of config loading, environment overrides the base config
  • Loading branch information
iantmoore committed Aug 15, 2017
1 parent 044a40b commit 714181e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
41 changes: 41 additions & 0 deletions 1.1.0_upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Upgrading to 1.1.0
------------------

As of the 1.1.0 release, *all* Substeps config is moving to use [Typesafe config](https://github.com/typesafehub/config) files, existing config that was previously locatated in the pom.xml files is to be migrated.

How to Upgrade ?
----------------
* Upgrade the version of substeps-core to 1.1.0 and run `mvn verify`, a new `generated-application.conf` file will be generated, hopefully migrating over any existing settings, I can't guarantee that of course, but send a message via [gitter](https://badges.gitter.im/Substeps/substeps-framework.svg) if you have any specific issues.

* Greater use is made of default values for various settings, so if you've not modified the ExecutionListeners or report builder paths, this config will disappear. You can still override, but there's no need to specify all of the defaults.

* Once the new file has been checked, remove all of the existing config in the pom.xml - the whole `<configuration/>` block of the plugin! Ahh, that's better! Existing environment override properties files, eg. localhost.conf are still used and remain unchanged*

* rename `generated-application.conf` to `application.conf`

* Run your tests again, all should be as it was

Why ?
-----
- There were a number of motivations for this change, primarily concerned with a desire for multi (variant) browser testing and potentially in parallel.
- The output from such an execution would need to be combined into a single report
- Maven pom configuration was starting to become cumbersome with many defaults being expressed, tidying this up in a consistent manner for Maven and other potential execution environments was desireable
- Moving away from maven based config makes propagating changes to existing and new runners easier.

Additional requirements as a result of the change
- moving exisitng substeps config under a single org.substeps hierarchy
- maintain the existing environment overloads
- backwards compatibility or at least the ability to generate a suitable configuration file
- move as many default values into the reference.conf to be overriden as required
- minimising the repetition of config across multiple execution configurations, eg the step implementation classes, features etc would probably stay the same, so DRY, but with the ability to override if required
- As a result of the above, configuration can no longer be accessed via an enum - as it would require re-initialising and there could be multiple configs in existence at a time in different threads.
- Support for .properties files via the System property `substeps.use.dot.properties` has also been removed - sorry if you were using this, the HOCON formatted .conf files offer significantly more functionality
- ability to inject in maven like variables `project.build.directory`, `basedir`, `project.build.testOutputDirectory`, `project.build.outputDirectory` that are expanded at runtime


How does it work ?
------------------
- Typesafe config uses a number of config files, reference.conf(s) in the provided libraries and an application.conf in the project classpath.
- Substeps also uses an additional config file for environment overrides. These config files are combined and expressions resolved into a 'master' config.
- The master config is written to file in the data directory for future reference by the report.
- within the master config is an array of executionConfigs, plus a baseExecutionConfig section. At runtime, the master config is split into an individual executionConfigs, based on the whole config, plus one of the executionConfig elements (merged with the baseExecutionConfig block) then finally variables are expanded and resolved using environment overrides.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testScenarioStepWithParameters() {

final List<SubstepExecutionFailure> failures = new ArrayList<>();

final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures);
final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures, false);

Assert.assertThat(rootNode.getResult().getResult(), is(ExecutionResult.PASSED));

Expand All @@ -105,7 +105,7 @@ public void testParseErrorResultsInFailedTest() {

final List<SubstepExecutionFailure> failures = new ArrayList<>();

final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures);
final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures, true);

// check the rootNode tree is in the state we expect
Assert.assertThat(rootNode.getResult().getResult(), is(ExecutionResult.FAILED));
Expand Down Expand Up @@ -141,7 +141,7 @@ public void testSubStepDefinitionMatchesStepImplFailure() {

final List<SubstepExecutionFailure> failures = new ArrayList<>();

final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures);
final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures, false);

// check the rootNode tree is in the state we expect
Assert.assertThat(rootNode.getResult().getResult(), is(ExecutionResult.FAILED));
Expand Down Expand Up @@ -182,7 +182,7 @@ public void testParseError2ResultsInFailedTest() {

// TODO - checkfailures - test currently ignored anyway..
final List<SubstepExecutionFailure> failures = new ArrayList<>();
final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures);
final RootNode rootNode = runExecutionTest(feature, tags, substeps, notifier, failures, false);

System.out.println("\n\n\n\n\n*************\n\n" + rootNode.toDebugString());

Expand Down Expand Up @@ -230,7 +230,7 @@ public void regExTest() {
*/
private RootNode runExecutionTest(final String feature, final String tags, final String substeps,
final IExecutionListener notifier, final Class<?>[] initialisationClasses,
final List<SubstepExecutionFailure> failures, final List<Class<?>> stepImplementationClasses) {
final List<SubstepExecutionFailure> failures, final List<Class<?>> stepImplementationClasses, boolean fastFailParseErrors) {
final SubstepsExecutionConfig executionConfig = new SubstepsExecutionConfig();

Assert.assertTrue(failures.isEmpty());
Expand Down Expand Up @@ -308,12 +308,12 @@ private RootNode runExecutionTest(final IExecutionListener notifier,
}

private RootNode runExecutionTest(final String feature, final String tags, final String substeps,
final IExecutionListener notifier, final List<SubstepExecutionFailure> failures) {
final IExecutionListener notifier, final List<SubstepExecutionFailure> failures, boolean fastFailParseErrors) {

final List<Class<?>> stepImplementationClasses = new ArrayList<>();
stepImplementationClasses.add(TestStepImplementations.class);

return runExecutionTest(feature, tags, substeps, notifier, null, failures, stepImplementationClasses);
return runExecutionTest(feature, tags, substeps, notifier, null, failures, stepImplementationClasses, fastFailParseErrors);
}

private void setPrivateField(final Object target, final String fieldName, final Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ReportBuilderTest extends FlatSpec with Matchers{
Option(uri) shouldBe defined

println("uri get file: " + uri.getFile)

val rawUncalledStepDefs = Files.toString(new File( uri.getFile), Charset.forName("UTF-8"))

val uncalledStepDefs: List[UncalledStepDef] = parse(rawUncalledStepDefs).extract[List[UncalledStepDef]]
Expand Down

0 comments on commit 714181e

Please sign in to comment.