Skip to content

Commit 327e535

Browse files
committed
Gradle: test case making sure beans from other module's test configuration can be injected into the current module's tests
Gradle: take into account component's classifier creating AppArtifact for it
1 parent 2784cb3 commit 327e535

File tree

18 files changed

+229
-6
lines changed

18 files changed

+229
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.quarkus.gradle;
2+
3+
4+
import java.io.File;
5+
import org.gradle.testkit.runner.GradleRunner;
6+
import org.junit.jupiter.api.Test;
7+
8+
9+
public class InjectBeanFromTestConfigTest extends QuarkusGradleTestBase {
10+
11+
@Test
12+
public void testBasicMultiModuleBuild() throws Exception {
13+
14+
final File projectDir = getProjectDir("inject-bean-from-test-config");
15+
16+
GradleRunner.create()
17+
.forwardOutput()
18+
.withPluginClasspath()
19+
.withArguments(arguments("clean", ":application:test"))
20+
.withProjectDir(projectDir)
21+
.build();
22+
}
23+
}

devtools/gradle/src/functionalTest/resources/basic-java-library-module/library/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@ compileJava {
2020
options.compilerArgs << '-parameters'
2121
}
2222

23-
java {
24-
sourceCompatibility = JavaVersion.VERSION_1_8
25-
targetCompatibility = JavaVersion.VERSION_1_8
26-
}
27-
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
id 'java'
3+
id 'io.quarkus'
4+
}
5+
6+
repositories {
7+
mavenLocal()
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
13+
implementation 'io.quarkus:quarkus-resteasy'
14+
15+
implementation project(':library')
16+
17+
testImplementation 'io.quarkus:quarkus-junit5'
18+
testImplementation 'io.rest-assured:rest-assured'
19+
testImplementation project(path: ':library', configuration: 'tests')
20+
}
21+
22+
compileJava {
23+
options.compilerArgs << '-parameters'
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.acme;
2+
3+
import javax.inject.Inject;
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
9+
@Path("/hello")
10+
public class ExampleResource {
11+
12+
@Inject
13+
LibraryBean libraryBean;
14+
15+
@GET
16+
@Produces(MediaType.TEXT_PLAIN)
17+
public String hello() {
18+
return "hello";
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Configuration file
2+
# key = value
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.acme;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import javax.inject.Inject;
6+
7+
import io.quarkus.test.junit.QuarkusTest;
8+
import io.quarkus.test.common.QuarkusTestResource;
9+
import org.junit.jupiter.api.Test;
10+
11+
import static io.restassured.RestAssured.given;
12+
import static org.hamcrest.CoreMatchers.is;
13+
14+
@QuarkusTest
15+
@QuarkusTestResource(LibraryTestResource.class)
16+
public class ExampleResourceTest {
17+
18+
@Inject
19+
LibraryTestBean libraryBean;
20+
21+
@Test
22+
public void testHelloEndpoint() {
23+
given()
24+
.when().get("/hello")
25+
.then()
26+
.statusCode(200)
27+
.body(is("hello"));
28+
29+
assertEquals("test", libraryBean.getValue());
30+
}
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
}
6+
}
7+
8+
allprojects {
9+
group 'org.acme'
10+
version '1.0.0-SNAPSHOT'
11+
}
12+
13+
subprojects{
14+
repositories {
15+
mavenLocal()
16+
mavenCentral()
17+
}
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quarkusPlatformArtifactId=quarkus-bom
2+
quarkusPlatformGroupId=io.quarkus
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
repositories {
6+
mavenLocal()
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
api enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
12+
api 'io.quarkus:quarkus-resteasy'
13+
14+
testImplementation 'io.quarkus:quarkus-junit5'
15+
testImplementation 'io.rest-assured:rest-assured'
16+
}
17+
18+
compileJava {
19+
options.compilerArgs << '-parameters'
20+
}
21+
22+
configurations {
23+
tests.extendsFrom testRuntime
24+
}
25+
26+
task testJar (type: Jar) {
27+
classifier = 'test'
28+
from sourceSets.test.output
29+
}
30+
31+
artifacts {
32+
tests testJar
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.acme;
2+
3+
import javax.enterprise.context.ApplicationScoped;
4+
5+
@ApplicationScoped
6+
public class LibraryBean implements LibraryBeanInterface {
7+
8+
@Override
9+
public String getValue() {
10+
return "main";
11+
}
12+
}

0 commit comments

Comments
 (0)