Skip to content

Commit 8264333

Browse files
authored
Duct (#595)
Added duct module - a utility for serving execution reports on your local system
1 parent a016456 commit 8264333

File tree

112 files changed

+4118
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4118
-255
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ graph TB
6565
message-core --> message-web
6666
message-core --> message-xml
6767
report-core --> assert-filter
68+
report-core --> duct
6869
report-ng --> report-core
6970
validation-core --> validation-junit4
7071
validation-core --> validation-junit5

aggregator/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.mastercard.test.flow</groupId>
66
<artifactId>parent</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.1.0-SNAPSHOT</version>
88
</parent>
99
<artifactId>aggregator</artifactId>
1010
<packaging>jar</packaging>
@@ -125,6 +125,12 @@
125125
<version>${project.version}</version>
126126
</dependency>
127127

128+
<dependency>
129+
<groupId>${project.groupId}</groupId>
130+
<artifactId>duct</artifactId>
131+
<version>${project.version}</version>
132+
</dependency>
133+
128134
<dependency>
129135
<!-- testing -->
130136
<groupId>org.junit.jupiter</groupId>

aggregator/src/test/java/com/mastercard/test/flow/aggregator/SharedConstantTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package com.mastercard.test.flow.aggregator;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
35
import org.junit.jupiter.api.Assertions;
46
import org.junit.jupiter.api.Test;
57

8+
import com.mastercard.test.flow.assrt.AssertionOptions;
69
import com.mastercard.test.flow.assrt.Order;
710
import com.mastercard.test.flow.builder.Chain;
811
import com.mastercard.test.flow.model.LazyModel;
912
import com.mastercard.test.flow.report.Writer;
13+
import com.mastercard.test.flow.report.duct.Duct;
14+
import com.mastercard.test.flow.util.Option;
1015
import com.mastercard.test.flow.validation.check.ChainOverlapCheck;
1116
import com.mastercard.test.flow.validation.check.ReflectiveModelTaggingCheck;
1217
import com.mastercard.test.flow.validation.check.ResultTagCheck;
@@ -54,4 +59,20 @@ void lazyModelStrings() {
5459
Assertions.assertEquals( LazyModel.MODEL_TAGS_FIELD_NAME,
5560
ReflectiveModelTaggingCheck.MODEL_TAGS_FIELD_NAME );
5661
}
62+
63+
/**
64+
* The <code>duct</code> module offers {@link Duct#GUI_SUPPRESS}, and we've got
65+
* an alias for that in {@link AssertionOptions#DUCT_GUI_SUPPRESS} so that it
66+
* gets picked up by the documentation automation. However, <code>duct</code> is
67+
* an <i>optional</i> dependency of <code>assert-core</code>, so we can depend
68+
* on it being available when {@link AssertionOptions} is initialised. Hence we
69+
* have to maintain a static copy of the {@link Option} values.
70+
*/
71+
@Test
72+
void ductSuppressionOption() {
73+
assertEquals( Duct.GUI_SUPPRESS.property(), AssertionOptions.DUCT_GUI_SUPPRESS.property(),
74+
"property name" );
75+
assertEquals( Duct.GUI_SUPPRESS.description(), AssertionOptions.DUCT_GUI_SUPPRESS.description(),
76+
"property description" );
77+
}
5778
}

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.mastercard.test.flow</groupId>
66
<artifactId>parent</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.1.0-SNAPSHOT</version>
88
</parent>
99
<artifactId>api</artifactId>
1010
<packaging>jar</packaging>

api/src/main/java/com/mastercard/test/flow/util/Option.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ default Stream<String> asList() {
128128
return asList( "," );
129129
}
130130

131+
/**
132+
* Builds the commandline argument that would set this {@link Option}'s current
133+
* value in a new JVM
134+
*
135+
* @return The commandline argument, or <code>null</code> if this {@link Option}
136+
* has no value
137+
*/
138+
default String commandLineArgument() {
139+
return Optional.ofNullable( value() )
140+
.map( v -> String.format( "-D%s=%s", property(), v ) )
141+
.orElse( null );
142+
}
143+
131144
/**
132145
* Use in try-with-resources blocks where you want an {@link Option} to have a
133146
* specific value and then revert to the previous value when the block ends

api/src/test/java/com/mastercard/test/flow/util/OptionTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,19 @@ void builder() {
196196
Assertions.assertEquals( "property", b.property() );
197197
Assertions.assertEquals( "default", b.defaultValue() );
198198
}
199+
200+
/**
201+
* Exercises {@link Option#commandLineArgument()}
202+
*/
203+
@Test
204+
void commandLineArgument() {
205+
try( Temporary t = TSTOPT.temporarily( "abc" ) ) {
206+
assertEquals( "-Dtstopt=abc", TSTOPT.commandLineArgument() );
207+
}
208+
209+
try( Temporary t = TSTOPT.temporarily( null ) ) {
210+
assertEquals( null, TSTOPT.commandLineArgument() );
211+
}
212+
}
213+
199214
}

assert/assert-core/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Some aspects of assertion behaviour can be controlled by system properties:
3737

3838
| property | description |
3939
| -------- | ----------- |
40+
| `mctf.browse.xdg_open` | Supply true to try and fall back to `xdg-open` when java's desktop integration fails |
4041
| `mctf.dir` | The path to the dir where assertion artifacts are saved |
4142
| `mctf.filter.cli.min_width` | The minimum width of the command-line interface |
4243
| `mctf.filter.exclude` | A comma-separated list of tags values that flows must not have |
@@ -47,9 +48,12 @@ Some aspects of assertion behaviour can be controlled by system properties:
4748
| `mctf.filter.update` | Supply `true` to update filter values at runtime in the most appropriate interface.Supply `cli` to force use of the command-line interface or `gui` to force use of the graphical interface |
4849
| `mctf.replay` | The location of a report to replay, or `latest` to replay the most recent local report |
4950
| `mctf.report.dir` | The path from the artifact directory to the report destination |
51+
| `mctf.report.serve` | Set to `true` to browse reports on a local web server rather than the filesystem. You must have the optional `duct` module on your classpath. |
5052
| `mctf.suppress.assertion` | Set to `true` to continue processing a flow in the face of assertion failure |
5153
| `mctf.suppress.basis` | Set to `true` to process flows whose basis flows have suffered assertion failure |
54+
| `mctf.suppress.browse` | Supply 'true' to suppress attempts to open browsers |
5255
| `mctf.suppress.dependency` | Set to `true` to process flows whose dependency flows have suffered errors |
56+
| `mctf.suppress.duct.gui` | Supply 'true' to suppress the duct gui |
5357
| `mctf.suppress.filter` | Set to `true` to process all flows regardless of filter configuration |
5458
| `mctf.suppress.system` | Set to `true` to process when the system under test lacks declared dependencies |
5559

assert/assert-core/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.mastercard.test.flow</groupId>
66
<artifactId>assert</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.1.0-SNAPSHOT</version>
88
</parent>
99
<artifactId>assert-core</artifactId>
1010
<packaging>jar</packaging>
@@ -18,6 +18,16 @@
1818
<version>${project.version}</version>
1919
</dependency>
2020

21+
<dependency>
22+
<!-- report serving -->
23+
<groupId>${project.groupId}</groupId>
24+
<artifactId>duct</artifactId>
25+
<version>${project.version}</version>
26+
<!-- duct is a convenience feature that brings in a load of dependencies, so
27+
we're leaving it up to client projects if they want it or not -->
28+
<optional>true</optional>
29+
</dependency>
30+
2131
<dependency>
2232
<groupId>org.junit.jupiter</groupId>
2333
<artifactId>junit-jupiter</artifactId>
@@ -57,4 +67,4 @@
5767
</plugins>
5868
</build>
5969

60-
</project>
70+
</project>

assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AbstractFlocessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.mastercard.test.flow.report.data.LogEvent;
5353
import com.mastercard.test.flow.report.data.ResidueData;
5454
import com.mastercard.test.flow.report.data.TransmissionData;
55+
import com.mastercard.test.flow.report.duct.Duct;
5556
import com.mastercard.test.flow.util.Dependencies;
5657
import com.mastercard.test.flow.util.Flows;
5758

@@ -1013,7 +1014,14 @@ private void report( Consumer<Writer> data, boolean error ) {
10131014

10141015
// also, if appropriate, open a browser to it
10151016
if( reporting.shouldOpen( error ) ) {
1016-
report.browse();
1017+
if( AssertionOptions.DUCT.isTrue() ) {
1018+
// if you've traced a ClassNotFoundException or NoClassDefFoundError to here,
1019+
// then you've forgotten to add the duct module to your dependencies.
1020+
Duct.serve( report.path() );
1021+
}
1022+
else {
1023+
report.browse();
1024+
}
10171025
}
10181026
}
10191027
}

assert/assert-core/src/main/java/com/mastercard/test/flow/assrt/AssertionOptions.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import com.mastercard.test.flow.Flow;
66
import com.mastercard.test.flow.assrt.filter.FilterOptions;
7+
import com.mastercard.test.flow.report.LocalBrowse;
8+
import com.mastercard.test.flow.report.duct.Duct;
79
import com.mastercard.test.flow.util.Option;
810

911
/**
@@ -24,6 +26,34 @@ public enum AssertionOptions implements Option {
2426
*/
2527
ARTIFACT_DIR(FilterOptions.ARTIFACT_DIR),
2628

29+
/**
30+
* Allows browser launches to be avoided. An alias for
31+
* {@link LocalBrowse#SUPPRESS}
32+
*/
33+
BROWSE_SUPPRESS(LocalBrowse.SUPPRESS),
34+
35+
/**
36+
* Allows the option of a browse-opening fallback. An alias for
37+
* {@link LocalBrowse#XDG_OPEN_FALLBACK}
38+
*/
39+
BROWSE_XDG_OPEN_FALLBACK(LocalBrowse.XDG_OPEN_FALLBACK),
40+
41+
/**
42+
* Controls whether we use {@link Duct} or not
43+
*/
44+
DUCT(b -> b.property( "mctf.report.serve" )
45+
.description( "Set to `true` to browse reports on a local web"
46+
+ " server rather than the filesystem. You must have the"
47+
+ " optional `duct` module on your classpath." )),
48+
49+
/**
50+
* Allows the {@link Duct} gui to be avoided. An alias for
51+
* {@link Duct#GUI_SUPPRESS}
52+
*/
53+
DUCT_GUI_SUPPRESS(b -> b
54+
.property( "mctf.suppress.duct.gui" )
55+
.description( "Supply 'true' to suppress the duct gui" )),
56+
2757
/**
2858
* Controls {@link Replay} parameters
2959
*/

0 commit comments

Comments
 (0)