Skip to content

Commit

Permalink
write a test for a multi module
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Stoll authored and ltearno committed Jan 26, 2018
1 parent b6cf689 commit 2419e85
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class AnalyzerTest
private static final String PROJECT_B = "fr.lteconsulting:b:1.0-SNAPSHOT";
private static final String PROJECT_C = "fr.lteconsulting:c:1.0-SNAPSHOT";
private static final String PROJECT_D = "fr.lteconsulting:d:1.0-SNAPSHOT";
private static final String PROJECT_E = "fr.lteconsulting:e:1.0-SNAPSHOT";
private static final String PROJECT_E = "fr.lteconsulting:e:2.0-SNAPSHOT";
private static final String PROJECT_F = "fr.lteconsulting:f:1.5";

@Test
public void test01()
Expand Down Expand Up @@ -55,7 +56,7 @@ public void test02()
assertDependencies(session, PROJECT_C, 2);
assertDependencies(session, PROJECT_D, 0);
assertDependencies(session, PROJECT_E, 0);
assertNullGavs(session, 0);
assertNoNullGavs(session);
}

@Test
Expand All @@ -71,7 +72,7 @@ public void test03()
assertDependencies(session, PROJECT_B, 0);
assertDependencies(session, PROJECT_C, 1);
assertDependencies(session, PROJECT_D, 0);
assertNullGavs(session, 0);
assertNoNullGavs(session);
}

@Test
Expand All @@ -87,7 +88,7 @@ public void test04()
assertDependencies(session, PROJECT_B, 0);
assertDependencies(session, PROJECT_C, 1);
assertDependencies(session, PROJECT_D, 0);
assertNullGavs(session, 0);
assertNoNullGavs(session);
}

@Test
Expand All @@ -100,6 +101,7 @@ public void test05()
//assert
assertProjects(session, 2);
assertDependencies(session, PROJECT_A, 1);
assertParentDependency(session, PROJECT_A, PROJECT_B);
assertDependencies(session, PROJECT_B, 1);

List<String> shouldBeMissing = new ArrayList<>();
Expand All @@ -113,9 +115,7 @@ public void test05()
System.out.println("DEPENDENCIES");
session.graph().read().dependencies(project.getGav()).forEach(System.out::println);

/**
* Checks that transitive dependencies cannot be resolved
*/
// Checks that transitive dependencies cannot be resolved
TransitivityResolver resolver = new TransitivityResolver();
resolver.getTransitiveDependencyTree(session, project, true, true, null, new PomFileLoader()
{
Expand Down Expand Up @@ -154,9 +154,8 @@ public void test06()
System.out.println("DEPENDENCIES");
session.graph().read().dependencies(project.getGav()).forEach(System.out::println);

/**
* Checks that transitive dependencies can be resolved
*/

// Checks that transitive dependencies can be resolved
TransitivityResolver resolver = new TransitivityResolver();
resolver.getTransitiveDependencyTree(session, project, true, true, null, new PomFileLoader()
{
Expand Down Expand Up @@ -216,6 +215,28 @@ public void test08()
assertNotNull(project);
}


@Test
public void test09_multiModule()
{
//arrange
Session session = new Session();
//act
runFullRecursiveAnalysis(session, "testSets/set09");
//assert
assertProjects(session, 6);
assertDependencies(session, PROJECT_A, 0);
assertDependencies(session, PROJECT_B, 2);
assertParentDependency(session, PROJECT_B, PROJECT_A);
assertDependencies(session, PROJECT_C, 4);
assertParentDependency(session, PROJECT_C, PROJECT_A);
assertDependencies(session, PROJECT_D, 3);
assertParentDependency(session, PROJECT_D, PROJECT_A);
assertDependencies(session, PROJECT_E, 1);
assertDependencies(session, PROJECT_F, 0);
assertNoNullGavs(session);
}

@Test
public void localTest1()
{
Expand Down Expand Up @@ -277,6 +298,7 @@ public void localTest2()
.forEach(System.out::println);
}


private void runFullRecursiveAnalysis(Session session, String testSet)
{
PomAnalysis.runFullRecursiveAnalysis(testSet, session, null, null, true, System.out::println);
Expand All @@ -295,13 +317,6 @@ private void assertDependenciesAndBuildDependencies(Session session, String gavS
assertBuildDependencies(session, gavString, numberOfBuildDependencies);
}

private void assertDependenciesWithUnresolved(Session session, String gavString, int numberOfDependencies, String... unresolvedGavs)
{
assertDependencies(session, gavString, numberOfDependencies, "DEPENDENCIES RESULT FOR " + gavString + "\ndependencies:");
System.out.println("missing dependencies:");
//TODO find out how to retrieve unresolved dependencies from graph/session
}

private void assertDependencies(Session session, String gavString, int numberOfDependencies)
{
assertDependencies(session, gavString, numberOfDependencies, "DEPENDENCIES OF " + gavString);
Expand Down Expand Up @@ -329,6 +344,11 @@ private void assertParentDependency(Session session, String gavString, String pa
assertEquals("parent dependency of " + gavString, parent, Gav.parse(parentGav));
}

private void assertNoNullGavs(Session session)
{
assertNullGavs(session, 0);
}

private void assertNullGavs(Session session, int numberOfNullGavs)
{
System.out.println("NULL VERSION GAVS");
Expand All @@ -337,6 +357,6 @@ private void assertNullGavs(Session session, int numberOfNullGavs)
.sorted(Comparator.comparing(Gav::toString))
.collect(Collectors.toList());
nullGavs.forEach(System.out::println);
assertEquals("null gavs", numberOfNullGavs, nullGavs.size());
assertEquals("number of null gavs", numberOfNullGavs, nullGavs.size());
}
}
2 changes: 1 addition & 1 deletion pom-explorer-core/testSets/set02/e.pom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
<version>1.0-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>

<packaging>jar</packaging>

Expand Down
79 changes: 79 additions & 0 deletions pom-explorer-core/testSets/set09/a.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>fr.lteconsulting</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>

<packaging>jar</packaging>

<description>test with submodules</description>

<dependencyManagement>
<dependencies>

<!-- module dependencies -->
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<!-- other dependencies -->
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
<version>2.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>f</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>b</module>
</modules>

<profiles>
<profile>
<id>default-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>c</module>
</modules>
</profile>
<profile>
<id>additional</id>
<modules>
<module>d</module>
</modules>
</profile>
</profiles>
</project>
26 changes: 26 additions & 0 deletions pom-explorer-core/testSets/set09/b.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fr.lteconsulting</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>b</artifactId>
<description>submodule of a</description>

<dependencies>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>f</artifactId>
</dependency>
</dependencies>
</project>
38 changes: 38 additions & 0 deletions pom-explorer-core/testSets/set09/c.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fr.lteconsulting</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>c</artifactId>
<description>submodule of a</description>

<dependencies>
<!-- inter module dependencies -->
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
<classifier>tests</classifier>
</dependency>

<!-- other dependencies -->
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>f</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</project>
32 changes: 32 additions & 0 deletions pom-explorer-core/testSets/set09/d.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>fr.lteconsulting</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>d</artifactId>
<description>submodule of a</description>

<dependencies>
<!-- inter module dependencies -->
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>b</artifactId>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>c</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions pom-explorer-core/testSets/set09/e.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>fr.lteconsulting</groupId>
<artifactId>e</artifactId>
<version>2.0-SNAPSHOT</version>

<packaging>jar</packaging>

<description>test project e</description>

<dependencies>
<dependency>
<groupId>fr.lteconsulting</groupId>
<artifactId>f</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</project>
13 changes: 13 additions & 0 deletions pom-explorer-core/testSets/set09/f.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<project>
<modelVersion>4.0.0</modelVersion>

<groupId>fr.lteconsulting</groupId>
<artifactId>f</artifactId>
<version>1.5</version>

<packaging>jar</packaging>

<description>test project e</description>
</project>

0 comments on commit 2419e85

Please sign in to comment.