-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filled out usage documentation (#198)
* Filled out usage documentation * tweak * format * simplify! * killed mutant
- Loading branch information
1 parent
2790eca
commit 7e7f278
Showing
14 changed files
with
319 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
doc/src/test/java/com/mastercard/test/flow/doc/DependencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.mastercard.test.flow.doc; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.util.stream.Collectors.joining; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.DynamicTest.dynamicTest; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.DynamicNode; | ||
import org.junit.jupiter.api.TestFactory; | ||
|
||
import com.mastercard.test.flow.report.QuietFiles; | ||
|
||
/** | ||
* Checks that the documented maven dependency declarations are accurate | ||
*/ | ||
@SuppressWarnings("static-method") | ||
class DependencyTest { | ||
|
||
private static Pattern DEP = Pattern.compile( "<dependency>(.*)</dependency>", Pattern.DOTALL ); | ||
private static Pattern GRP = Pattern.compile( "<groupId>(.*)</groupId>" ); | ||
private static Pattern RTF = Pattern.compile( "<artifactId>(.*)</artifactId>" ); | ||
private static Pattern VRS = Pattern.compile( "<version>(.*)</version>" ); | ||
|
||
/** | ||
* Checks that all of the suggested dependency declarations in the readmes | ||
* accurately target an artifact from this project | ||
* | ||
* @return per-markdown-file tests | ||
*/ | ||
@TestFactory | ||
Stream<DynamicNode> markdown() { | ||
PomData root = new PomData( null, Paths.get( "../pom.xml" ) ); | ||
Set<String> allowed = new TreeSet<>(); | ||
Map<Path, PomData> dirPoms = new TreeMap<>(); | ||
root.visit( pd -> { | ||
allowed.add( pd.groupId() + ":" + pd.artifactId() ); | ||
dirPoms.put( pd.dirPath(), pd ); | ||
} ); | ||
String allowedString = allowed.stream().collect( joining( "\n " ) ); | ||
|
||
Set<String> used = new TreeSet<>(); | ||
|
||
return Stream.concat( | ||
Util.markdownFiles() | ||
.map( path -> dynamicTest( path.toString(), () -> { | ||
String content = new String( QuietFiles.readAllBytes( path ), UTF_8 ); | ||
Matcher depM = DEP.matcher( content ); | ||
while( depM.find() ) { | ||
Matcher grpM = GRP.matcher( depM.group( 1 ) ); | ||
assertTrue( grpM.find(), "groupId found in " + depM.group( 0 ) ); | ||
|
||
Matcher rtfM = RTF.matcher( depM.group( 1 ) ); | ||
assertTrue( rtfM.find(), "artifactId found in " + depM.group( 0 ) ); | ||
|
||
Matcher vrsM = VRS.matcher( depM.group( 1 ) ); | ||
assertTrue( vrsM.find(), "version found in " + depM.group( 0 ) ); | ||
assertEquals( "${flow.version}", vrsM.group( 1 ), | ||
"Version element in\n" + depM.group( 0 ) ); | ||
|
||
String dep = grpM.group( 1 ) + ":" + rtfM.group( 1 ); | ||
used.add( dep ); | ||
|
||
if( "README.md".equals( path.getFileName().toString() ) ) { | ||
PomData pom = dirPoms.get( path.getParent() ); | ||
assertNotNull( pom, "pom associated with readme" ); | ||
assertEquals( | ||
pom.groupId() + ":" + pom.artifactId(), | ||
dep, | ||
String.format( | ||
"Documented dependency%n%s%nmatches associated pom", | ||
depM.group() ) ); | ||
} | ||
|
||
assertTrue( allowed.contains( dep ), | ||
String.format( | ||
"Dependency '%s' taken from dependency%n%s%nfound in allowed set:%n%s", | ||
dep, depM.group(), allowedString ) ); | ||
} | ||
} ) ), | ||
Stream.of( dynamicTest( "Documented dependencies", () -> { | ||
assertEquals( "" | ||
+ "com.mastercard.test.flow:assert-junit4\n" | ||
+ "com.mastercard.test.flow:assert-junit5\n" | ||
+ "com.mastercard.test.flow:builder\n" | ||
+ "com.mastercard.test.flow:message-core\n" | ||
+ "com.mastercard.test.flow:message-http\n" | ||
+ "com.mastercard.test.flow:message-json\n" | ||
+ "com.mastercard.test.flow:message-sql\n" | ||
+ "com.mastercard.test.flow:message-text\n" | ||
+ "com.mastercard.test.flow:message-web\n" | ||
+ "com.mastercard.test.flow:message-xml\n" | ||
+ "com.mastercard.test.flow:model\n" | ||
+ "com.mastercard.test.flow:validation-junit4\n" | ||
+ "com.mastercard.test.flow:validation-junit5", | ||
used.stream().collect( joining( "\n" ) ) ); | ||
} ) ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.