Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.gradle;


import java.io.File;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;


public class InjectBeanFromTestConfigTest extends QuarkusGradleTestBase {

@Test
public void testBasicMultiModuleBuild() throws Exception {

final File projectDir = getProjectDir("inject-bean-from-test-config");

GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments(arguments("clean", ":application:test"))
.withProjectDir(projectDir)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ compileJava {
options.compilerArgs << '-parameters'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id 'java'
id 'io.quarkus'
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy'

implementation project(':library')

testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
testImplementation project(path: ':library', configuration: 'tests')
}

compileJava {
options.compilerArgs << '-parameters'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.acme;

import javax.inject.Inject;
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 ExampleResource {

@Inject
LibraryBean libraryBean;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Configuration file
# key = value
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.acme;

import static org.junit.jupiter.api.Assertions.assertEquals;

import javax.inject.Inject;

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

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

@QuarkusTest
@QuarkusTestResource(LibraryTestResource.class)
public class ExampleResourceTest {

@Inject
LibraryTestBean libraryBean;

@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("hello"));

assertEquals("test", libraryBean.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}

allprojects {
group 'org.acme'
version '1.0.0-SNAPSHOT'
}

subprojects{
repositories {
mavenLocal()
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'java-library'
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
api enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
api 'io.quarkus:quarkus-resteasy'

testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}

compileJava {
options.compilerArgs << '-parameters'
}

configurations {
tests.extendsFrom testRuntime
}

task testJar (type: Jar) {
classifier = 'test'
from sourceSets.test.output
}

artifacts {
tests testJar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.acme;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class LibraryBean implements LibraryBeanInterface {

@Override
public String getValue() {
return "main";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.acme;

public interface LibraryBeanInterface {

String getValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class LibraryTestBean implements LibraryBeanInterface {

@Inject LibraryTestDepBean depBean;

@Override
public String getValue() {
return depBean.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.acme;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class LibraryTestDepBean {

public String getValue() {
return "test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import java.util.Collections;
import java.util.Map;

public class LibraryTestResource implements QuarkusTestResourceLifecycleManager {

@Override
public Map<String, String> start() {
return Collections.emptyMap();
}

@Override
public void stop() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}
rootProject.name='code-with-quarkus'
include 'library'
include 'application'

Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ static AppDependency toAppDependency(ResolvedArtifact a) {

public static AppArtifact toAppArtifact(ResolvedArtifact a) {
final String[] split = a.getModuleVersion().toString().split(":");
final AppArtifact appArtifact = new AppArtifact(split[0], split[1], split.length > 2 ? split[2] : null);
final AppArtifact appArtifact = new AppArtifact(split[0], split[1], a.getClassifier(), a.getType(),
split.length > 2 ? split[2] : null);
if (a.getFile().exists()) {
appArtifact.setPath(a.getFile().toPath());
}
Expand Down