maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/test/java/org/apache/maven/util/introspection ReflectionValueExtractorTest.java
Date Thu, 24 Feb 2005 04:21:52 GMT
brett       2005/02/23 20:21:52

  Added:       maven-core/src/test/java/org/apache/maven/project/injection
                        DefaultModelDefaultsInjectorTest.java
               maven-core/src/test/java/org/apache/maven/project/interpolation
                        RegexBasedModelInterpolatorTest.java
               maven-core/src/test/java/org/apache/maven/util/introspection
                        ReflectionValueExtractorTest.java
  Removed:     maven-core/src/test/java/org/apache/maven/plugin
                        ReflectionProjectValueExtractorTest.java
               maven-core/src/test/java/org/apache/maven/project/interpolation
                        RegexBasedProjectInterpolatorTest.java
               maven-core/src/test/java/org/apache/maven/project
                        DefaultProjectDefaultsInjectorTest.java
  Log:
  place tests in consistent locations
  
  Revision  Changes    Path
  1.1                  maven-components/maven-core/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java
  
  Index: DefaultModelDefaultsInjectorTest.java
  ===================================================================
  package org.apache.maven.project.injection;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import junit.framework.TestCase;
  import org.apache.maven.model.Dependency;
  import org.apache.maven.model.DependencyManagement;
  import org.apache.maven.model.Model;
  
  import java.util.List;
  import java.util.Properties;
  
  /**
   * @author jdcasey
   */
  public class DefaultModelDefaultsInjectorTest
      extends TestCase
  {
  
      public void testShouldConstructWithNoParams()
      {
          new DefaultModelDefaultsInjector();
      }
  
      public void testShouldSucceedInMergingDependencyWithDependency()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
          def.setVersion( "1.0.1" );
          def.setFile( "file" );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
          assertEquals( def.getVersion(), result.getVersion() );
      }
  
      public void testShouldMergeDefaultUrlAndArtifactWhenDependencyDoesntSupplyVersion()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
          def.setVersion( "1.0.1" );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
          assertEquals( def.getVersion(), result.getVersion() );
      }
  
      public void testShouldNotMergeDefaultUrlOrArtifactWhenDependencySuppliesVersion()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
          dep.setVersion( "1.0.1" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
          assertEquals( dep.getVersion(), result.getVersion() );
      }
  
      public void testShouldMergeDefaultPropertiesWhenDependencyDoesntSupplyProperties()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
          dep.setVersion( "1.0.1" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
  
          Properties props = new Properties();
          props.setProperty( "test", "value" );
  
          def.setProperties( props );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
  
          assertEquals( "value", result.getProperties().getProperty( "test" ) );
      }
  
      public void testShouldNotMergeDefaultPropertiesWhenDependencySuppliesProperties()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
          dep.setVersion( "1.0.1" );
  
          Properties props = new Properties();
          props.setProperty( "test", "value" );
  
          dep.setProperties( props );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
  
          Properties props2 = new Properties();
          props2.setProperty( "test", "value2" );
  
          def.setProperties( props2 );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
          assertEquals( "value", result.getProperties().getProperty( "test" ) );
      }
  
      public void testShouldMergeDefaultFileWhenDependencyDoesntSupplyFile()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
          dep.setVersion( "1.0.1" );
          dep.setFile( "file" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
  
          assertEquals( "file", result.getFile() );
      }
  
      public void testShouldNotMergeDefaultFileWhenDependencySuppliesFile()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
          dep.setVersion( "1.0.1" );
          dep.setFile( "file" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
          def.setFile( "default" );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
          new DefaultModelDefaultsInjector().injectDefaults( model );
  
          List deps = model.getDependencies();
          assertEquals( 1, deps.size() );
  
          Dependency result = (Dependency) deps.get( 0 );
          assertEquals( "file", result.getFile() );
      }
  
      public void testShouldRejectDependencyWhereNoVersionIsFoundAfterDefaultsInjection()
      {
          Model model = new Model();
  
          Dependency dep = new Dependency();
          dep.setGroupId( "myGroup" );
          dep.setArtifactId( "myArtifact" );
  
          model.addDependency( dep );
  
          Dependency def = new Dependency();
          def.setGroupId( dep.getGroupId() );
          def.setArtifactId( dep.getArtifactId() );
  
          DependencyManagement depMgmt = new DependencyManagement();
  
          depMgmt.addDependency( def );
  
          model.setDependencyManagement( depMgmt );
  
  //        try
  //        {
          new DefaultModelDefaultsInjector().injectDefaults( model );
          Dependency dependency = (Dependency) model.getDependencies().get( 0 );
          assertNull( "check version is null", dependency.getVersion() );
  //            fail("Should fail to validate dependency without a version.");
  //        }
  //        catch ( IllegalStateException e )
  //        {
  //            // should throw when it detects a missing version in the test dependency.
  //        }
      }
  
  }
  
  
  
  1.1                  maven-components/maven-core/src/test/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolatorTest.java
  
  Index: RegexBasedModelInterpolatorTest.java
  ===================================================================
  package org.apache.maven.project.interpolation;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import junit.framework.TestCase;
  import org.apache.maven.model.Dependency;
  import org.apache.maven.model.Model;
  
  /**
   * @author jdcasey
   */
  public class RegexBasedModelInterpolatorTest
      extends TestCase
  {
  
      public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
          throws ModelInterpolationException
      {
          Model model = new Model();
          model.setVersion( "3.8.1" );
  
          Dependency dep = new Dependency();
          dep.setVersion( "${version}" );
  
          model.addDependency( dep );
  
          Model out = new RegexBasedModelInterpolator().interpolate( model );
  
          assertEquals( "3.8.1", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion()
);
      }
  
      public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
          throws ModelInterpolationException
      {
          Model model = new Model();
          model.setVersion( "3.8.1" );
  
          Dependency dep = new Dependency();
          dep.setVersion( "${something}" );
  
          model.addDependency( dep );
  
          Model out = new RegexBasedModelInterpolator().interpolate( model );
  
          assertEquals( "${something}", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion()
);
      }
  
      public void testTwoReferences()
          throws ModelInterpolationException
      {
          Model model = new Model();
          model.setVersion( "3.8.1" );
          model.setArtifactId( "foo" );
  
          Dependency dep = new Dependency();
          dep.setVersion( "${artifactId}-${version}" );
  
          model.addDependency( dep );
  
          Model out = new RegexBasedModelInterpolator().interpolate( model );
  
          assertEquals( "foo-3.8.1", ( (Dependency) out.getDependencies().get( 0 ) ).getVersion()
);
      }
  
  }
  
  
  1.1                  maven-components/maven-core/src/test/java/org/apache/maven/util/introspection/ReflectionValueExtractorTest.java
  
  Index: ReflectionValueExtractorTest.java
  ===================================================================
  package org.apache.maven.util.introspection;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.MavenTestCase;
  import org.apache.maven.model.Build;
  import org.apache.maven.project.MavenProject;
  import org.apache.maven.project.MavenProjectBuilder;
  
  import java.io.File;
  import java.util.List;
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: ReflectionValueExtractorTest.java,v 1.1 2005/02/24 04:21:52 brett Exp $
   */
  public class ReflectionValueExtractorTest
      extends MavenTestCase
  {
      private MavenProject project;
  
      private MavenProjectBuilder builder;
  
      protected void setUp()
          throws Exception
      {
          super.setUp();
  
          builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
  
          File f = getTestFile( "src/test/resources/pom.xml" );
  
          project = getProject( f );
      }
  
      public void testValueExtraction()
          throws Exception
      {
          // ----------------------------------------------------------------------
          // Top level values
          // ----------------------------------------------------------------------
  
          assertEquals( "4.0.0", ReflectionValueExtractor.evaluate( "project.modelVersion",
project ) );
  
          assertEquals( "maven", ReflectionValueExtractor.evaluate( "project.groupId", project
) );
  
          assertEquals( "maven-core", ReflectionValueExtractor.evaluate( "project.artifactId",
project ) );
  
          assertEquals( "Maven", ReflectionValueExtractor.evaluate( "project.name", project
) );
  
          assertEquals( "2.0-SNAPSHOT", ReflectionValueExtractor.evaluate( "project.version",
project ) );
  
          // ----------------------------------------------------------------------
          // SCM
          // ----------------------------------------------------------------------
  
          assertEquals( "scm-connection", ReflectionValueExtractor.evaluate( "project.scm.connection",
project ) );
  
          // ----------------------------------------------------------------------
          // Dependencies
          // ----------------------------------------------------------------------
  
          List dependencies = (List) ReflectionValueExtractor.evaluate( "project.dependencies",
project );
  
          assertNotNull( dependencies );
  
          assertEquals( 2, dependencies.size() );
  
          // ----------------------------------------------------------------------
          // Build
          // ----------------------------------------------------------------------
  
          Build build = (Build) ReflectionValueExtractor.evaluate( "project.build", project
);
  
          assertNotNull( build );
      }
  }
  
  
  

Mime
View raw message