forked from moditect/deptective
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moditect#27 Adding cycle detection to architecture validation
1 parent
1202103
commit ff74950
Showing
17 changed files
with
441 additions
and
7 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
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
121 changes: 121 additions & 0 deletions
121
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/CycleTest.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,121 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle; | ||
|
||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.tools.JavaFileObject; | ||
import javax.tools.StandardLocation; | ||
|
||
import org.junit.Test; | ||
import org.moditect.deptective.internal.util.Strings; | ||
import org.moditect.deptective.plugintest.PluginTestBase; | ||
import org.moditect.deptective.plugintest.cycle.abc.Abc; | ||
import org.moditect.deptective.plugintest.cycle.bar.Bar; | ||
import org.moditect.deptective.plugintest.cycle.baz.Baz; | ||
import org.moditect.deptective.plugintest.cycle.def.Def; | ||
import org.moditect.deptective.plugintest.cycle.foo.Foo; | ||
import org.moditect.deptective.plugintest.cycle.qux.Qux; | ||
|
||
import com.google.testing.compile.Compilation; | ||
import com.google.testing.compile.Compiler; | ||
|
||
public class CycleTest extends PluginTestBase { | ||
|
||
@Test | ||
public void shouldDetectCyclesInArchitectureModel() { | ||
Compilation compilation = Compiler.javac() | ||
.withOptions( | ||
"-Xplugin:Deptective", | ||
getConfigFileOption() | ||
) | ||
.compile( | ||
forTestClass(Foo.class), | ||
forTestClass(Bar.class), | ||
forTestClass(Baz.class), | ||
forTestClass(Qux.class), | ||
forTestClass(Abc.class), | ||
forTestClass(Def.class) | ||
|
||
); | ||
|
||
assertThat(compilation).failed(); | ||
assertThat(compilation).hadErrorContaining("Architecture model contains cycle(s) between these components:"); | ||
assertThat(compilation).hadErrorContaining(" - bar, baz, foo, qux"); | ||
assertThat(compilation).hadErrorContaining(" - abc, def"); | ||
} | ||
|
||
@Test | ||
public void shouldVisualizeCyclesInArchitectureModel() throws Exception { | ||
Compilation compilation = Compiler.javac() | ||
.withOptions( | ||
"-Xplugin:Deptective", | ||
"-Adeptective.visualize=true", | ||
"-Adeptective.cycle_reporting_policy=WARN", | ||
getConfigFileOption() | ||
) | ||
.compile( | ||
forTestClass(Foo.class), | ||
forTestClass(Bar.class), | ||
forTestClass(Baz.class), | ||
forTestClass(Qux.class), | ||
forTestClass(Abc.class), | ||
forTestClass(Def.class) | ||
); | ||
|
||
assertThat(compilation).succeeded(); | ||
assertThat(compilation).hadWarningContaining("Architecture model contains cycle(s) between these components:"); | ||
assertThat(compilation).hadWarningContaining(" - bar, baz, foo, qux"); | ||
assertThat(compilation).hadWarningContaining(" - abc, def"); | ||
|
||
assertThat(compilation).hadNoteContaining( | ||
"Created DOT file representing the Deptective configuration at mem:///CLASS_OUTPUT/deptective.dot" | ||
); | ||
assertThat(compilation).hadNoteCount(1); | ||
|
||
String expectedConfig = Strings.lines( | ||
"digraph \"package dependencies\"", | ||
"{", | ||
" \"abc\";", | ||
" \"bar\";", | ||
" \"baz\";", | ||
" \"def\";", | ||
" \"foo\";", | ||
" \"qux\";", | ||
" subgraph Cycle {", | ||
" edge [color=purple]", | ||
" \"abc\" -> \"def\";", | ||
" \"bar\" -> \"baz\";", | ||
" \"bar\" -> \"qux\";", | ||
" \"baz\" -> \"foo\";", | ||
" \"def\" -> \"abc\";", | ||
" \"foo\" -> \"bar\";", | ||
" \"qux\" -> \"bar\";", | ||
" }", | ||
"}" | ||
); | ||
|
||
Optional<JavaFileObject> deptectiveFile = compilation | ||
.generatedFile(StandardLocation.CLASS_OUTPUT, "deptective.dot"); | ||
assertThat(deptectiveFile.isPresent()).isTrue(); | ||
String generatedConfig = Strings.readToString(deptectiveFile.get().openInputStream()); | ||
|
||
assertThat(generatedConfig).isEqualTo(expectedConfig); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/abc/Abc.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,23 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.abc; | ||
|
||
import org.moditect.deptective.plugintest.cycle.def.Def; | ||
|
||
public class Abc { | ||
|
||
Def def; | ||
} |
25 changes: 25 additions & 0 deletions
25
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/bar/Bar.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,25 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.bar; | ||
|
||
import org.moditect.deptective.plugintest.cycle.baz.Baz; | ||
import org.moditect.deptective.plugintest.cycle.qux.Qux; | ||
|
||
public class Bar { | ||
|
||
Baz baz; | ||
Qux qux; | ||
} |
23 changes: 23 additions & 0 deletions
23
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/baz/Baz.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,23 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.baz; | ||
|
||
import org.moditect.deptective.plugintest.cycle.foo.Foo; | ||
|
||
public class Baz { | ||
|
||
private Foo foo; | ||
} |
23 changes: 23 additions & 0 deletions
23
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/def/Def.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,23 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.def; | ||
|
||
import org.moditect.deptective.plugintest.cycle.abc.Abc; | ||
|
||
public class Def { | ||
|
||
Abc abc; | ||
} |
23 changes: 23 additions & 0 deletions
23
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/foo/Foo.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,23 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.foo; | ||
|
||
import org.moditect.deptective.plugintest.cycle.bar.Bar; | ||
|
||
public class Foo { | ||
|
||
private final Bar bar = new Bar(); | ||
} |
23 changes: 23 additions & 0 deletions
23
javac-plugin/src/test/java/org/moditect/deptective/plugintest/cycle/qux/Qux.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,23 @@ | ||
/** | ||
* Copyright 2019 The ModiTect authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.moditect.deptective.plugintest.cycle.qux; | ||
|
||
import org.moditect.deptective.plugintest.cycle.bar.Bar; | ||
|
||
public class Qux { | ||
|
||
Bar bar; | ||
} |
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
34 changes: 34 additions & 0 deletions
34
javac-plugin/src/test/resources/org/moditect/deptective/plugintest/cycle/deptective.json
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,34 @@ | ||
{ | ||
"components" : [ | ||
{ | ||
"name" : "foo", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.foo" ], | ||
"reads" : [ "bar" ] | ||
}, | ||
{ | ||
"name" : "bar", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.bar" ], | ||
"reads" : [ "baz", "qux" ] | ||
}, | ||
{ | ||
"name" : "baz", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.baz" ], | ||
"reads" : [ "foo" ] | ||
}, | ||
{ | ||
"name" : "qux", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.qux" ], | ||
"reads" : [ "bar" ] | ||
}, | ||
{ | ||
"name" : "abc", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.abc" ], | ||
"reads" : [ "def" ] | ||
}, | ||
{ | ||
"name" : "def", | ||
"contains" : [ "org.moditect.deptective.plugintest.cycle.def" ], | ||
"reads" : [ "abc" ] | ||
} | ||
] | ||
} |