Skip to content

Commit 65deb8e

Browse files
committed
Gradle: test case making sure beans from other module's test configuration can be injected into the current module's tests
1 parent 5cddc7f commit 65deb8e

File tree

17 files changed

+359
-5
lines changed

17 files changed

+359
-5
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,155 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>code-with-quarkus - 1.0.0-SNAPSHOT</title>
6+
<style>
7+
h1, h2, h3, h4, h5, h6 {
8+
margin-bottom: 0.5rem;
9+
font-weight: 400;
10+
line-height: 1.5;
11+
}
12+
13+
h1 {
14+
font-size: 2.5rem;
15+
}
16+
17+
h2 {
18+
font-size: 2rem
19+
}
20+
21+
h3 {
22+
font-size: 1.75rem
23+
}
24+
25+
h4 {
26+
font-size: 1.5rem
27+
}
28+
29+
h5 {
30+
font-size: 1.25rem
31+
}
32+
33+
h6 {
34+
font-size: 1rem
35+
}
36+
37+
.lead {
38+
font-weight: 300;
39+
font-size: 2rem;
40+
}
41+
42+
.banner {
43+
font-size: 2.7rem;
44+
margin: 0;
45+
padding: 2rem 1rem;
46+
background-color: #00A1E2;
47+
color: white;
48+
}
49+
50+
body {
51+
margin: 0;
52+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
53+
}
54+
55+
code {
56+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
57+
font-size: 87.5%;
58+
color: #e83e8c;
59+
word-break: break-word;
60+
}
61+
62+
.left-column {
63+
padding: .75rem;
64+
max-width: 75%;
65+
min-width: 55%;
66+
}
67+
68+
.right-column {
69+
padding: .75rem;
70+
max-width: 25%;
71+
}
72+
73+
.container {
74+
display: flex;
75+
width: 100%;
76+
}
77+
78+
li {
79+
margin: 0.75rem;
80+
}
81+
82+
.right-section {
83+
margin-left: 1rem;
84+
padding-left: 0.5rem;
85+
}
86+
87+
.right-section h3 {
88+
padding-top: 0;
89+
font-weight: 200;
90+
}
91+
92+
.right-section ul {
93+
border-left: 0.3rem solid #00A1E2;
94+
list-style-type: none;
95+
padding-left: 0;
96+
}
97+
98+
</style>
99+
</head>
100+
<body>
101+
102+
<div class="banner lead">
103+
Your new Cloud-Native application is ready!
104+
</div>
105+
106+
<div class="container">
107+
<div class="left-column">
108+
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>
109+
110+
<h2>Why do you see this?</h2>
111+
112+
<p>This page is served by Quarkus. The source is in
113+
<code>src/main/resources/META-INF/resources/index.html</code>.</p>
114+
115+
<h2>What can I do from here?</h2>
116+
117+
<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
118+
</p>
119+
<ul>
120+
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
121+
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
122+
<li>Configure your application in <code>src/main/resources/application.properties</code>.
123+
</li>
124+
</ul>
125+
126+
<h2>Do you like Quarkus?</h2>
127+
<p>Go give it a star on <a href="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/quarkusio/quarkus">GitHub</a>.</p>
128+
129+
<h2>How do I get rid of this page?</h2>
130+
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
131+
</div>
132+
<div class="right-column">
133+
<div class="right-section">
134+
<h3>Application</h3>
135+
<ul>
136+
<li>GroupId: org.acme</li>
137+
<li>ArtifactId: code-with-quarkus</li>
138+
<li>Version: 1.0.0-SNAPSHOT</li>
139+
<li>Quarkus Version: 1.2.1.Final</li>
140+
</ul>
141+
</div>
142+
<div class="right-section">
143+
<h3>Next steps</h3>
144+
<ul>
145+
<li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li>
146+
<li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li>
147+
<li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li>
148+
</ul>
149+
</div>
150+
</div>
151+
</div>
152+
153+
154+
</body>
155+
</html>
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,9 @@
1+
package org.acme;
2+
3+
import io.quarkus.test.junit.NativeImageTest;
4+
5+
@NativeImageTest
6+
public class NativeExampleResourceIT extends ExampleResourceTest {
7+
8+
// Execute the same tests but in native mode.
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 org.junit.jupiter.api.Test;
9+
10+
import static io.restassured.RestAssured.given;
11+
import static org.hamcrest.CoreMatchers.is;
12+
13+
@QuarkusTest
14+
public class ExampleResourceTest {
15+
16+
@Inject
17+
LibraryTestBean libraryBean;
18+
19+
@Test
20+
public void testHelloEndpoint() {
21+
given()
22+
.when().get("/hello")
23+
.then()
24+
.statusCode(200)
25+
.body(is("hello"));
26+
27+
assertEquals("test", libraryBean.getValue());
28+
}
29+
}
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

0 commit comments

Comments
 (0)