mirror of https://github.com/apache/maven.git
o Moved tests for model validator into proper module
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@779307 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
421e6ca656
commit
0e34f1958a
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven.project.validation;
|
package org.apache.maven.model.validation;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@ -19,24 +19,55 @@ package org.apache.maven.project.validation;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.project.AbstractMavenProjectTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class DefaultModelValidatorTest
|
public class DefaultModelValidatorTest
|
||||||
extends AbstractMavenProjectTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
private Model model;
|
|
||||||
|
|
||||||
private ModelValidator validator;
|
private DefaultModelValidator validator;
|
||||||
|
|
||||||
|
private Model read( String pom )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String resource = "/poms/validation/" + pom;
|
||||||
|
InputStream is = getClass().getResourceAsStream( resource );
|
||||||
|
assertNotNull( "missing resource: " + resource, is );
|
||||||
|
return new MavenXpp3Reader().read( is );
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModelValidationResult validate( String pom )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
return validator.validateEffectiveModel( read( pom ), false );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
validator = (DefaultModelValidator) lookup( ModelValidator.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
this.validator = null;
|
||||||
|
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
public void testMissingModelVersion()
|
public void testMissingModelVersion()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -169,7 +200,7 @@ public class DefaultModelValidatorTest
|
||||||
|
|
||||||
assertEquals( 4, result.getMessageCount() );
|
assertEquals( 4, result.getMessageCount() );
|
||||||
|
|
||||||
List messages = result.getMessages();
|
List<String> messages = result.getMessages();
|
||||||
|
|
||||||
assertTrue( messages.contains( "\'modelVersion\' is missing." ) );
|
assertTrue( messages.contains( "\'modelVersion\' is missing." ) );
|
||||||
assertTrue( messages.contains( "\'groupId\' is missing." ) );
|
assertTrue( messages.contains( "\'groupId\' is missing." ) );
|
||||||
|
@ -209,10 +240,6 @@ public class DefaultModelValidatorTest
|
||||||
assertEquals( "'repositories.repository.id' is missing.", result.getMessage( 0 ) );
|
assertEquals( "'repositories.repository.id' is missing.", result.getMessage( 0 ) );
|
||||||
|
|
||||||
assertEquals( "'repositories.repository.url' is missing.", result.getMessage( 1 ) );
|
assertEquals( "'repositories.repository.url' is missing.", result.getMessage( 1 ) );
|
||||||
//
|
|
||||||
// assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getMessage( 2 ) );
|
|
||||||
//
|
|
||||||
// assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMissingResourceDirectory()
|
public void testMissingResourceDirectory()
|
||||||
|
@ -227,23 +254,4 @@ public class DefaultModelValidatorTest
|
||||||
assertEquals( "'build.testResources.testResource.directory' is missing.", result.getMessage( 1 ) );
|
assertEquals( "'build.testResources.testResource.directory' is missing.", result.getMessage( 1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelValidationResult validate( String testName )
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Reader input = ReaderFactory.newXmlReader( getFileForClasspathResource( "validation/" + testName ) );
|
|
||||||
|
|
||||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
|
||||||
|
|
||||||
validator = lookup( ModelValidator.class );
|
|
||||||
|
|
||||||
model = reader.read( input );
|
|
||||||
|
|
||||||
ModelValidationResult result = validator.validate( model );
|
|
||||||
|
|
||||||
assertNotNull( result );
|
|
||||||
|
|
||||||
input.close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue