Skip to content

Commit

Permalink
Support custom test classes dir under 'target'
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Apr 14, 2022
1 parent ae4d9e4 commit 3b6071f
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
Expand All @@ -30,6 +31,15 @@ class BuildIT extends MojoTestBase {
private RunningInvoker running;
private File testDir;

@Test
void testCustomTestSourceSets()
throws MavenInvocationException, IOException, InterruptedException {
testDir = initProject("projects/test-source-sets");
running = new RunningInvoker(testDir, false);
MavenProcessInvocationResult result = running.execute(List.of("clean", "verify"), Map.of());
assertThat(result.getProcess().waitFor()).isZero();
}

@Test
void testConditionalDependencies()
throws MavenInvocationException, IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.turing85</groupId>
<artifactId>quarkus-source-sets</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<!-- Maven plugin -->
<build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<dependency-plugin.version>3.2.0</dependency-plugin.version>
<failsafe.useModulePath>false</failsafe.useModulePath>
<maven.compiler.release>11</maven.compiler.release>

<!-- General project setup -->
<failsafe.it-phase>verify</failsafe.it-phase>
<failsafe.bt-phase>none</failsafe.bt-phase>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<project.build.integrationtestRoot>
\${project.basedir}/src/integrationtest
</project.build.integrationtestRoot>
<project.build.integrationtestSourceDirectory>
\${project.build.integrationtestRoot}/java
</project.build.integrationtestSourceDirectory>
<project.build.integerationtestResoruceDirectory>
\${project.build.integrationtestRoot}/resources
</project.build.integerationtestResoruceDirectory>
<project.build.integrationtestOutputDirectory>
\${project.build.directory}/integrationtest-classes
</project.build.integrationtestOutputDirectory>
<project.build.integrationtestGeneratedSourceDirectory>
\${project.build.directory}/generated-integrationtest-sources/test-annotations
</project.build.integrationtestGeneratedSourceDirectory>

<!-- Quarkus setup -->
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>@project.version@</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${dependency-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build-classpath</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputProperty>classpath</outputProperty>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-integration-test</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
<goal>add-test-resource</goal>
</goals>
<configuration>
<sources>
<source>\${project.build.integrationtestSourceDirectory}</source>
</sources>
<resources>
<resource>
<directory>\${project.build.integerationtestResoruceDirectory}</directory>
<targetPath>\${project.build.integrationtestOutputDirectory}</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<compilerArgs>
<compilerArg>-cp</compilerArg>
<compilerArg>
\${classpath}\${path.separator}\${project.build.outputDirectory}
</compilerArg>
</compilerArgs>
<compileSourceRoots>
<compileSourceRoot>\${project.build.testSourceDirectory}</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>\${project.build.testOutputDirectory}</outputDirectory>
</configuration>
</execution>
<execution>
<id>compile-integrationtests</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<compilerArgs>
<compilerArg>-cp</compilerArg>
<compilerArg>
\${classpath}\${path.separator}\${project.build.outputDirectory}\${path.separator}\${project.build.testOutputDirectory}
</compilerArg>
</compilerArgs>
<compileSourceRoots>
<compileSourceRoot>
\${project.build.integrationtestSourceDirectory}
</compileSourceRoot>
</compileSourceRoots>
<generatedTestSourcesDirectory>
\${project.build.integrationtestGeneratedSourceDirectory}
</generatedTestSourcesDirectory>
<outputDirectory>\${project.build.integrationtestOutputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
</systemPropertyVariables>
<testClassesDirectory>\${project.build.outputDirectory}</testClassesDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<phase>none</phase>
</execution>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>\${failsafe.it-phase}</phase>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>
\${project.build.testOutputDirectory}
</additionalClasspathElement>
</additionalClasspathElements>
<includes>
<include>**/*.java</include>
</includes>
<trimStackTrace>false</trimStackTrace>
<systemPropertyVariables>
<native.image.path>\${project.build.directory}/\${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>\${maven.home}</maven.home>
<testClassesDirectory>\${project.build.integrationtestOutputDirectory}</testClassesDirectory>
</systemPropertyVariables>
<classesDirectory>\${project.build.outputDirectory}</classesDirectory>
<testClassesDirectory>\${project.build.integrationtestOutputDirectory}</testClassesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.acme;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class GreetingResourceIntegrationTest {

@Test
public void testHelloEndpoint() {
// @formatter: off
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is(GreetingResource.HELLO));
// @formatter: on
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.acme;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

static final String HELLO = "Hello";

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return HELLO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.acme;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class GreetingResourceTest {
@Test
void shouldReturnExpectedValue() {
String actual = new GreetingResource().hello();
Assertions.assertEquals(actual, GreetingResource.HELLO);
}
}
Loading

0 comments on commit 3b6071f

Please sign in to comment.