Lorenzo Bettini created MARCHETYPES-67: ------------------------------------------
Summary: Fix maven-archetype-plugin test case Key: MARCHETYPES-67 URL: https://issues.apache.org/jira/browse/MARCHETYPES-67 Project: Maven Archetype Bundles Issue Type: Bug Components: Maven Plugin Archetype Affects Versions: 1.4 Reporter: Lorenzo Bettini 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 {code:xml} ... <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> {code} 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: {code:java} @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() ); } {code} 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: {code:java} ... File expectedOutputDirectory = new File (pom.getAbsoluteFile(), "target/test-harness/project-to-test"); assertEquals(expectedOutputDirectory, outputDirectory); ... {code} 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: {code:xml} ... <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> ... {code} Am I right or am I missing something? I can provide a PR in case -- This message was sent by Atlassian Jira (v8.3.4#803005)