ValidateApplicationMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File completeAppDirectory = new File( this.project.getBuild().getOutputDirectory()); if( ! completeAppDirectory.isDirectory()) throw new MojoExecutionException( "The target model directory could not be found. " + completeAppDirectory ); Collection<RoboconfError> reusableRecipeErrors = Collections.emptyList(); ProjectValidationResult pvr = ProjectValidator.validateProject( completeAppDirectory, this.recipe ); if( this.recipe ) { reusableRecipeErrors = validateRecipesSpecifics( this.project, pvr.getRawParsingResult().getApplicationTemplate(), this.official ); pvr.getErrors().addAll( reusableRecipeErrors ); } try { if( pvr.getErrors().size() > 0 ) { reportErrors( pvr.getErrors()); if( RoboconfErrorHelpers.containsCriticalErrors( pvr.getErrors())) throw new MojoFailureException( "Errors were found in the application." ); if( this.official && ! reusableRecipeErrors.isEmpty()) throw new MojoFailureException( "Warnings were found in official recipes. Please, fix them." ); } } catch( IOException e ) { throw new MojoExecutionException( "A problem occurred during the validation.", e ); } }  @Override void execute();  }
@Test( expected = MojoExecutionException.class ) public void testValidAppButNotInTarget() throws Exception { ValidateApplicationMojo mojo = (ValidateApplicationMojo) super.findMojo( "project--valid", "validate-application" ); mojo.execute(); }
@Test public void testRecipe_nonOfficial_withWarnings_1() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); mojo.execute(); File resultsFile = new File( project.getBasedir(), MavenPluginConstants.VALIDATION_RESULT_PATH ); Assert.assertTrue( resultsFile.exists()); }
@Test public void testRecipe_nonOfficial_withWarnings_2() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe-with-instances" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); mojo.execute(); File resultsFile = new File( project.getBasedir(), MavenPluginConstants.VALIDATION_RESULT_PATH ); Assert.assertTrue( resultsFile.exists()); }
@Test public void testRecipe_official_exactGroupId() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); this.rule.setVariableValueToObject( mojo, "official", true ); project.setGroupId( Constants.OFFICIAL_RECIPES_GROUP_ID ); project.setArtifactId( project.getName()); Assert.assertTrue( new File( project.getBasedir(), "readme" ).createNewFile()); mojo.execute(); File resultsFile = new File( project.getBasedir(), MavenPluginConstants.VALIDATION_RESULT_PATH ); Assert.assertFalse( resultsFile.exists()); }
@Test public void testRecipe_official_anotherGroupId() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); this.rule.setVariableValueToObject( mojo, "official", true ); project.setGroupId( Constants.OFFICIAL_RECIPES_GROUP_ID + ".database" ); project.setArtifactId( project.getName()); Assert.assertTrue( new File( project.getBasedir(), "readme" ).createNewFile()); mojo.execute(); File resultsFile = new File( project.getBasedir(), MavenPluginConstants.VALIDATION_RESULT_PATH ); Assert.assertFalse( resultsFile.exists()); }
@Test( expected = MojoFailureException.class ) public void testRecipe_official_fail_1() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); this.rule.setVariableValueToObject( mojo, "official", true ); project.setName( "ReCipe" ); mojo.execute(); }
@Test( expected = MojoFailureException.class ) public void testRecipe_official_fail_2() throws Exception { ValidateApplicationMojo mojo = retriveAndPrepareMojo( "recipe-with-instances" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); this.rule.setVariableValueToObject( mojo, "recipe", true ); this.rule.setVariableValueToObject( mojo, "official", true ); project.setName( "ReCipe" ); mojo.execute(); }