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

Model tag validation fix #89

Merged
merged 3 commits into from
Sep 1, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ class ModuleDiagramTest {
"com.mastercard.test.flow:aggregator",
"com.mastercard.test.flow:doc" ).collect( toSet() );

/**
* Maps from the groupID to the scope of links that we're interested in within
* that group.
*/
private static final Map<String, Set<String>> SCOPES;
static {
Map<String, Set<String>> m = new HashMap<>();
// For the framework we want to show *what* will be included transitively if you
// consume an artifact. We've got some test-scope dependencies in here to
// avoid excessive mocking, but they just cloud the diagram.
m.put( "com.mastercard.test.flow", Stream.of( "compile" ).collect( toSet() ) );
// For the example service it's important to show *how* the framework
// dependencies are consumed - e.g. assert and validation are always test scope,
// the model doesn't make it into the distributable artifacts, etc
m.put( "com.mastercard.test.flow.example", Stream.of( "compile", "test" ).collect( toSet() ) );
SCOPES = Collections.unmodifiableMap( m );
}
Expand Down Expand Up @@ -133,8 +143,6 @@ protected Link( String fromGroup, String fromArtifact, String type, String toGro
this.type = type;
this.toGroup = toGroup;
this.toArtifact = toArtifact;

System.out.println( this + " " + intraGroup() );
}

public boolean intraGroup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ private List<Check> buildChecks( Model model, List<Check> checks ) {
.collect( Collectors.toCollection( TreeSet::new ) );
modelUnionTags.removeAll( modelIntersectionTags );

String expected = formatCopypasta( modelUnionTags, modelIntersectionTags );
String actual = formatCopypasta( flowUnionTags, flowIntersectionTags );
String expected = formatCopypasta( flowUnionTags, flowIntersectionTags );
String actual = formatCopypasta( modelUnionTags, modelIntersectionTags );

if( !expected.equals( actual ) ) {
return new Violation( this, "Inaccurate tagging", expected, actual );
Expand All @@ -97,9 +97,8 @@ private static String formatCopypasta( Set<String> union, Set<String> intersecti
sb.append( ")\n .union(" );
sb.append( union.stream()
.collect( joining( QUOTE_COMMA_QUOTE, QUOTE, QUOTE ) ) );
sb.append( ")" );
}
sb.append( ";" );
sb.append( ");" );
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,30 @@ void accurate() {
*/
@Test
void violation() {
test( leaf( "leaf",
test( leaf( "empty model tags",
new TaggedGroup(),
"a,b,c" ),
" details: Inaccurate tagging\n"
+ " expected: new TaggedGroup(\"a\", \"b\", \"c\");\n"
+ " actual: new TaggedGroup();\n"
+ "offenders: " );

test( leaf( "empty flow tags",
new TaggedGroup( "a", "b", "c" ).union( "d" ) ),
" details: Inaccurate tagging\n"
+ " expected: new TaggedGroup();\n"
+ " actual: new TaggedGroup(\"a\", \"b\", \"c\")\n"
+ " .union(\"d\");\n"
+ "offenders: " );

test( leaf( "mismatch",
new TaggedGroup( "a", "b", "c" ).union( "d" ),
"a,b,c", "b,c,d" ),
" details: Inaccurate tagging\n"
+ " expected: new TaggedGroup(\"a\", \"b\", \"c\")\n"
+ " .union(\"d\");\n"
+ " actual: new TaggedGroup(\"b\", \"c\")\n"
+ " expected: new TaggedGroup(\"b\", \"c\")\n"
+ " .union(\"a\", \"d\");\n"
+ " actual: new TaggedGroup(\"a\", \"b\", \"c\")\n"
+ " .union(\"d\");\n"
+ "offenders: " );
}

Expand All @@ -83,14 +99,14 @@ void recursiveViolation() {
leaf( "right", new TaggedGroup( "b", "c" ), "b,c,d" ) ),
"left : pass",
" details: Inaccurate tagging\n"
+ " expected: new TaggedGroup(\"b\", \"c\";\n"
+ " actual: new TaggedGroup(\"b\", \"c\", \"d\";\n"
+ " expected: new TaggedGroup(\"b\", \"c\", \"d\");\n"
+ " actual: new TaggedGroup(\"b\", \"c\");\n"
+ "offenders: ",
" details: Inaccurate tagging\n"
+ " expected: new TaggedGroup(\"b\")\n"
+ " .union(\"a\", \"c\", \"x\");\n"
+ " actual: new TaggedGroup(\"b\")\n"
+ " .union(\"a\", \"c\", \"d\");\n"
+ " actual: new TaggedGroup(\"b\")\n"
+ " .union(\"a\", \"c\", \"x\");\n"
+ "offenders: " );
}

Expand Down