ReactorModuleConvergence extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); } catch ( ExpressionEvaluationException eee ) { throw new EnforcerRuleException( "Unable to retrieve the MavenSession: ", eee ); } List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); if ( sortedProjects != null && !sortedProjects.isEmpty() ) { checkReactor( sortedProjects ); checkParentsInReactor( sortedProjects ); checkMissingParentsInReactor( sortedProjects ); checkParentsPartOfTheReactor( sortedProjects ); if ( !isIgnoreModuleDependencies() ) { checkDependenciesWithinReactor( sortedProjects ); } } }  @Override void execute( EnforcerRuleHelper helper ); boolean isIgnoreModuleDependencies(); void setIgnoreModuleDependencies( boolean ignoreModuleDependencies );  }
@Test public void shouldNotFailWithNoProject() throws EnforcerRuleException { setupSortedProjects( Collections.<MavenProject>emptyList() ); rule.execute( helper ); assertTrue( true ); }
@Test public void shouldNotFailWithAValidProject() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject mp2 = createProjectChild1( mp1 ); MavenProject mp3 = createProjectChild2( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); assertTrue( true ); }
@Test( expected = EnforcerRuleException.class ) public void shouldFailWithWrongVersionInOneChild() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject mp2 = createProjectChild1( mp1 ); MavenProject mp3 = createProjectChild2WithWrongVersion( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); }
@Test( expected = EnforcerRuleException.class ) public void shouldFailWithWrongParent() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject wrongParentVerison = mock( MavenProject.class ); when( wrongParentVerison.getGroupId() ).thenReturn( "org.apache.enforcer" ); when( wrongParentVerison.getArtifactId() ).thenReturn( "m1" ); when( wrongParentVerison.getVersion() ).thenReturn( "1.1-SNAPSHOT" ); when( wrongParentVerison.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.1-SNAPSHOT" ); when( wrongParentVerison.getDependencies() ).thenReturn( Collections.<Dependency>emptyList() ); MavenProject mp2 = createProjectChild2( wrongParentVerison ); MavenProject mp3 = createProjectChild2( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); }
@Test public void shouldNotFailWithACompanyParent() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject companyParent = createCompanyParent(); MavenProject mp1 = createProjectParent( companyParent ); MavenProject mp2 = createProjectChild1( mp1 ); MavenProject mp3 = createProjectChild2( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); assertTrue( true ); }
@Test( expected = EnforcerRuleException.class ) public void shouldFailWithMissingParentsInReactory() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject mp2 = createProjectChild1( mp1 ); MavenProject mp3 = createProjectChild2( null ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); assertTrue( true ); }
@Test( expected = EnforcerRuleException.class ) public void shouldFailWithAParentWhichIsNotPartOfTheReactory() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject wrongParentVerison = mock( MavenProject.class ); when( wrongParentVerison.getGroupId() ).thenReturn( "org.apache" ); when( wrongParentVerison.getArtifactId() ).thenReturn( "m1" ); when( wrongParentVerison.getVersion() ).thenReturn( "1.0-SNAPSHOT" ); when( wrongParentVerison.getId() ).thenReturn( "org.apache.enforcer:m1:jar:1.0-SNAPSHOT" ); when( wrongParentVerison.getDependencies() ).thenReturn( Collections.<Dependency>emptyList() ); MavenProject mp2 = createProjectChild2( wrongParentVerison ); MavenProject mp3 = createProjectChild2( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); }
@Test public void shouldNotFailWithDependencyInReactory() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject mp2 = createProjectChild1( mp1 ); Dependency goodDependency = createDependency( "org.junit", "junit", "2.0" ); List<Dependency> depListMP2 = Arrays.asList( goodDependency ); when( mp2.getDependencies() ).thenReturn( depListMP2 ); MavenProject mp3 = createProjectChild2( mp1 ); Dependency dep1_MP3 = createDependency( "org.apache.commons", "commons-io", "1.0.4" ); List<Dependency> depListMP3 = Arrays.asList( dep1_MP3 ); when( mp3.getDependencies() ).thenReturn( depListMP3 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); assertTrue( true ); }
@Test( expected = EnforcerRuleException.class ) public void shouldFailWithWrongDependencyInReactor() throws EnforcerRuleException, ExpressionEvaluationException { MavenProject mp1 = createProjectParent(); MavenProject mp2 = createProjectChild1( mp1 ); Dependency goodDependency = createDependency( "org.junit", "junit", "2.0" ); Dependency wrongDepFromReactor = createDependency( "org.apache.enforcer", "m2", "1.1-SNAPSHOT" ); List<Dependency> depList = Arrays.asList( goodDependency, wrongDepFromReactor ); when( mp2.getDependencies() ).thenReturn( depList ); MavenProject mp3 = createProjectChild2( mp1 ); List<MavenProject> theList = Arrays.asList( mp1, mp2, mp3 ); setupSortedProjects( theList ); rule.execute( helper ); }