Skip to content

Commit

Permalink
re-enable creation of the test structure (unit and devmode test) when…
Browse files Browse the repository at this point in the history
… using create-extension Maven Mojo.

This reverts commit 3495f91.

Follows up quarkusio#12687 and quarkusio#5438
  • Loading branch information
machi1990 committed Oct 13, 2020
1 parent 20e6bdb commit 32d035e
Show file tree
Hide file tree
Showing 23 changed files with 400 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ public class CreateExtensionMojo extends AbstractMojo {
@Parameter(defaultValue = COMPILER_PLUGIN_DEFAULT_VERSION, required = true, property = "quarkus.mavenCompilerPluginVersion")
String compilerPluginVersion;

/**
* Indicates whether to generate a unit test class for the extension
*
* @since 1.3.0
*/
@Parameter(property = "quarkus.generateUnitTest", defaultValue = "true")
boolean generateUnitTest;

/**
* Indicates whether to generate a dev mode unit test class for the extension
*
* @since 1.3.0
*/
@Parameter(property = "quarkus.generateDevModeTest", defaultValue = "true")
boolean generateDevModeTest;

boolean currentProjectIsBaseDir;

Charset charset;
Expand Down Expand Up @@ -825,6 +841,14 @@ private void generateExtensionProjects(Configuration cfg, TemplateParams templat
.resolve("deployment")
.resolve(templateParams.artifactIdBaseCamelCase + "Processor.java");
evalTemplate(cfg, "Processor.java", processorPath, templateParams);

if (generateUnitTest) {
generateUnitTestClass(cfg, templateParams);
}

if (generateDevModeTest) {
generateDevModeTestClass(cfg, templateParams);
}
}

private PomTransformer pomTransformer(Path basePomXml) {
Expand Down Expand Up @@ -905,6 +929,24 @@ private Configuration getTemplateConfig() throws IOException {
return templateCfg;
}

private void generateUnitTestClass(Configuration cfg, TemplateParams model) throws IOException, TemplateException {
final Path unitTest = basedir.toPath()
.resolve(model.artifactIdBase + "/deployment/src/test/java/" + model.javaPackageBase.replace('.', '/')
+ "/test/" + model.artifactIdBaseCamelCase + "Test.java");

evalTemplate(cfg, "UnitTest.java", unitTest, model);
}

private void generateDevModeTestClass(Configuration cfg, TemplateParams model) throws IOException, TemplateException {
final Path devModeTest = basedir
.toPath()
.resolve(model.artifactIdBase + "/deployment/src/test/java/" + model.javaPackageBase.replace('.', '/')
+ "/test/" + model.artifactIdBaseCamelCase + "DevModeTest.java");

evalTemplate(cfg, "DevModeTest.java", devModeTest, model);

}

void generateItest(Configuration cfg, TemplateParams model)
throws MojoFailureException, MojoExecutionException, TemplateException, IOException {
final Path itestParentAbsPath = basedir.toPath().resolve(itestParentPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package [=javaPackageBase].test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

class [=artifactIdBaseCamelCase]DevModeTest {
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.fail("Add dev mode assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package [=javaPackageBase].test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class [=artifactIdBaseCamelCase]Test {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() // Start unit test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
Assertions.fail("Add some assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
[#if !assumeManaged ] <version>[=r"$"]{project.version}</version>
[/#if]
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private static CreateExtensionMojo initMojo(final Path projectDir) throws IOExce
final CreateExtensionMojo mojo = new CreateExtensionMojo();
mojo.project = new MavenProject();
mojo.basedir = projectDir.toFile();
mojo.generateDevModeTest = true;
mojo.generateUnitTest = true;

final File pom = new File(projectDir.toFile(), "pom.xml");
if (pom.exists()) {
Expand Down Expand Up @@ -125,7 +127,7 @@ private static Path newProjectDir(String testProjectName) throws IOException {

@Test
void createExtensionUnderExistingPomMinimal() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
IllegalArgumentException, SecurityException, IOException {
final CreateExtensionMojo mojo = initMojo(createProjectFromTemplate("create-extension-pom"));
mojo.artifactId = "my-project-(minimal-extension)";
mojo.assumeManaged = false;
Expand All @@ -137,7 +139,7 @@ void createExtensionUnderExistingPomMinimal() throws MojoExecutionException, Moj

@Test
void createExtensionUnderExistingPomWithAdditionalRuntimeDependencies() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
IllegalArgumentException, SecurityException, IOException {
final CreateExtensionMojo mojo = initMojo(createProjectFromTemplate("create-extension-pom"));
mojo.artifactId = "my-project-(add-to-bom)";
mojo.assumeManaged = false;
Expand All @@ -152,7 +154,7 @@ void createExtensionUnderExistingPomWithAdditionalRuntimeDependencies() throws M

@Test
void createExtensionUnderExistingPomWithItest() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
IllegalArgumentException, SecurityException, IOException {
final CreateExtensionMojo mojo = initMojo(createProjectFromTemplate("create-extension-pom"));
mojo.artifactId = "my-project-(itest)";
mojo.assumeManaged = false;
Expand All @@ -165,7 +167,7 @@ void createExtensionUnderExistingPomWithItest() throws MojoExecutionException, M

@Test
void createExtensionUnderExistingPomCustomGrandParent() throws MojoExecutionException, MojoFailureException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, IOException {
IllegalArgumentException, SecurityException, IOException {
final CreateExtensionMojo mojo = initMojo(createProjectFromTemplate("create-extension-pom"));
mojo.artifactId = "myproject-(with-grand-parent)";
mojo.parentArtifactId = "grand-parent";
Expand Down Expand Up @@ -241,15 +243,15 @@ static void assertTreesMatch(Path expected, Path actual) throws IOException {
}

@Test
void getPackage() throws IOException {
void getPackage() {
assertEquals("org.apache.camel.quarkus.aws.sns.deployment", CreateExtensionMojo
.getJavaPackage("org.apache.camel.quarkus", null, "camel-quarkus-aws-sns-deployment"));
assertEquals("org.apache.camel.quarkus.component.aws.sns.deployment", CreateExtensionMojo
.getJavaPackage("org.apache.camel.quarkus", "component", "camel-quarkus-aws-sns-deployment"));
}

@Test
void toCapCamelCase() throws IOException {
void toCapCamelCase() {
assertEquals("FooBarBaz", CreateExtensionMojo.toCapCamelCase("foo-bar-baz"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>my-project-add-to-bom</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme.my.project.add.to.bom.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

class AddToBomDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.fail("Add dev mode assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.acme.my.project.add.to.bom.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class AddToBomTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() // Start unit test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
Assertions.fail("Add some assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>my-project-itest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme.my.project.itest.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

class ItestDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.fail("Add dev mode assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.acme.my.project.itest.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class ItestTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() // Start unit test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
Assertions.fail("Add some assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>my-project-minimal-extension</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme.my.project.minimal.extension.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

class MinimalExtensionDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.fail("Add dev mode assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.acme.my.project.minimal.extension.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

class MinimalExtensionTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() // Start unit test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
Assertions.fail("Add some assertions to " + getClass().getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<groupId>org.acme</groupId>
<artifactId>myproject-with-grand-parent</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme.myproject.with.grand.parent.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

class WithGrandParentDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest() // Start hot reload (DevMode) test with your extension loaded
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

@Test
public void test() {
// Write your tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.fail("Add dev mode assertions to " + getClass().getName());
}

}
Loading

0 comments on commit 32d035e

Please sign in to comment.