MavenInputReader { public Node readPom(String dirname) { LOGGER.debug("Read pom file in directory: {}", dirname); FileSystemUtil.assertFileOrResourceExists(dirname); MavenProject bean = readFile(dirname); Node node = mapInput(bean); node.setProperty(Constants.SCOPE, "input"); bean.getModules().forEach(module -> { Node child = readPom(dirname + "/" + module); dependencyGraph.addDependency(node, child, DependencyType.CONTAINS); } MavenInputReader(DependencyGraph dependencyGraph); Node readPom(String dirname);  }
@Test public void testRead() { reader.readPom(ROOT_DIR); assertThat(dependencyGraph.getAllNodes()).hasSize(10); Node pki = assertNode("com.mycompany.pki:pki"); Node pkiApi = assertNode("com.mycompany.pki:pki-api"); Node pkiServer = assertNode("com.mycompany.pki:pki-server"); Node commonUtil = assertNode("com.mycompany.common:common-util"); Node parent = assertNode("com.mycompany:mycompany-parent"); Node tester = assertNode("org.testtools:tester"); assertNode("joda-time:joda-time"); assertThat(dependencyGraph.getNode("joda-time")).isNull(); assertThat(dependencyGraph.getAllEdges()).hasSize(13); assertEdge(pki, parent, DependencyType.INHERIT); assertEdge(pki, pkiApi, DependencyType.CONTAINS); assertEdge(pkiApi, commonUtil, DependencyType.COMPILE); assertEdge(pkiServer, tester, DependencyType.TEST); GraphExporter.export(dependencyGraph, OUTPUT_DIR + "/mavenTest", new Architecture(), new ArrayList<>(), false); }
@Test public void testSimple() { reader.readPom(ROOT_DIR_SIMPLE); assertThat(dependencyGraph.getAllNodes()).hasSize(5); Node abc = assertNode("com.mycompany.abc:abc"); Node abcApi = assertNode("com.mycompany.abc:abc-api"); Node common = assertNode("com.mycompany.common:common-util"); Node guava = assertNode("com.google.guava:guava"); Node tester = assertNode("org.testtools:tester"); assertThat(dependencyGraph.getAllEdges()).hasSize(4); assertEdge(abc, abcApi, DependencyType.COMPILE); assertEdge(abc, common, DependencyType.COMPILE); assertEdge(abc, guava, DependencyType.COMPILE); assertEdge(abc, tester, DependencyType.TEST); }
@Test public void testWrongInput() { try { reader.readPom(ROOT_WRONG_INPUT); fail("IllegalArgumentException expected"); } catch(IllegalArgumentException e) { assertThat(e).hasMessageStartingWith("com.fasterxml.jackson.core.JsonParseException: Unexpected character 'T'"); } }
@Test public void testNotExistingInput() { try { reader.readPom(ROOT_NOT_EXISTING_INPUT); fail("IllegalArgumentException expected"); } catch(IllegalArgumentException e) { assertThat(e).hasMessageStartingWith("java.io.FileNotFoundException:"); } }