Uploaded image for project: 'Maven Archetype Bundles'
  1. Maven Archetype Bundles
  2. MARCHETYPES-67

Fix maven-archetype-plugin test case

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4
    • 1.5
    • Maven Plugin Archetype
    • None

    Description

      I've just started implementing (and testing) Maven plugins, but the test case (MyMojoTest) and, most of all, the corresponding project-to-test look wrong.

      The POM in project-to-test (for a project created with artifactId example-plugin1 and groupId com.example) is as follows

       

      ...
      
        <groupId>com.example</groupId>
        <artifactId>example-plugin1</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>Test MyMojo</name>
      
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-my-plugin</artifactId>
              <configuration>
                <!-- Specify the MyMojo parameter -->
                <outputDirectory>target/test-harness/project-to-test</outputDirectory>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </project>
      

      The artifactId refers to the actual plugin's artifactId example-plugin1 and groupId com.example (from what I understand that's not too important since it won't be deployed); what looks really wrong is the plugin configuration which refers to an unknown `maven-my-plugin`, which does not exist (even without any groupId).

      The test case MyMojoTest actually succeeds:

          @Test
          public void testSomething()
                  throws Exception
          {
              File pom = new File( "target/test-classes/project-to-test/" );
              assertNotNull( pom );
              assertTrue( pom.exists() );
      
              MyMojo myMojo = ( MyMojo ) rule.lookupConfiguredMojo( pom, "touch" );
              assertNotNull( myMojo );
              myMojo.execute();
      
              File outputDirectory = ( File ) rule.getVariableValueFromObject( myMojo, "outputDirectory" );
              assertNotNull( outputDirectory );
              assertTrue( outputDirectory.exists() );
      
              File touch = new File( outputDirectory, "touch.txt" );
              assertTrue( touch.exists() );
      
          }
      

      but it does not actually check that the outputDirectory is the one specified in the configuration section: `target/test-harness/project-to-test`.

      In fact, if you add the additional check:

      ...
              File expectedOutputDirectory = new File
              (pom.getAbsoluteFile(), "target/test-harness/project-to-test");
              assertEquals(expectedOutputDirectory, outputDirectory);
      ...
      

       
      This will fail (the outputDirectory is the default one, `target`, not the one specified in the configuration). By the way, I think this additional check should be part of the test case.

      The project-to-test POM should actually refer to the real plugin under test, with proper groupId (that's required as well) and artifactId, and the project's artifactId should be something else.

      This project-to-test POM makes the richer test case succeeds:

       

      ...
        <groupId>com.example</groupId>
        <artifactId>project-to-test</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>Test MyMojo</name>
      
        <build>
          <plugins>
            <plugin>
              <groupId>com.example</groupId>
              <artifactId>example-plugin1</artifactId>
              <configuration>
                <!-- Specify the MyMojo parameter -->
                <outputDirectory>target/test-harness/project-to-test</outputDirectory>
              </configuration>
            </plugin>
          </plugins>
        </build>
      ...
      

      Am I right or am I missing something?
      I can provide a PR in case 

      Attachments

        Issue Links

          Activity

            People

              slachiewicz Sylwester Lachiewicz
              lorebett Lorenzo Bettini
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: