Skip to content

Commit

Permalink
Add gradle integration test leveraging annotation processor
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Oct 18, 2021
1 parent 2764b1f commit f4b376b
Show file tree
Hide file tree
Showing 23 changed files with 475 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id 'io.quarkus'
}

dependencies {
implementation project(":common")
implementation 'io.quarkus:quarkus-resteasy-jackson'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.quarkus.sample;

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

import org.acme.common.CarMapper;
import org.acme.common.domain.Car;
import org.acme.common.domain.CarDTO;

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

private final CarMapper carMapper;

public HelloResource(CarMapper carMapper) {
this.carMapper = carMapper;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public CarDTO hello() {
Car car = new Car("foo", 4);
return carMapper.carToCarDTO(car);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.acme.quarkus.sample;

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

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

@QuarkusTest
public class HelloResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(containsString("seatNumber"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
buildscript {
repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
gradlePluginPortal()
}
}

apply plugin: 'java'

group = 'com.quarkus.demo'
version = '1.0'


subprojects {

apply plugin: 'java'

test {
dependsOn 'cleanTest'
useJUnitPlatform()
forkEvery 1
}

repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
}

dependencies {

implementation 'io.quarkus:quarkus-resteasy'

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

implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'java-library'
}

dependencies {
implementation "org.mapstruct:mapstruct:${mapstructVersion}"

annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme.common;

import org.acme.common.domain.Car;
import org.acme.common.domain.CarDTO;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "cdi", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface CarMapper {

@Mapping(source = "numberOfSeats", target = "seatNumber")
CarDTO carToCarDTO(Car car);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.common.domain;

public class Car {
private String type;
private Integer numberOfSeats;

public Car() {
}

public Car(String type, Integer numberOfSeats) {
this.type = type;
this.numberOfSeats = numberOfSeats;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Integer getNumberOfSeats() {
return numberOfSeats;
}

public void setNumberOfSeats(Integer numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.common.domain;

public class CarDTO {
private String type;
private Integer seatNumber;

public CarDTO() {
}

public CarDTO(String type, Integer seatNumber) {
this.type = type;
this.seatNumber = seatNumber;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Integer getSeatNumber() {
return seatNumber;
}

public void setSeatNumber(Integer seatNumber) {
this.seatNumber = seatNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus

mapstructVersion=1.4.2.Final
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pluginManagement {
repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'quarkus-annotation-processor-multi-module-build'

include ':common'
include ':application'

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

group = 'com.quarkus.demo'
version = '1.0'

test {
dependsOn 'cleanTest'
useJUnitPlatform()
forkEvery 1
}

repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
}

dependencies {

implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-resteasy-jackson'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'

annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"

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

implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus

mapstructVersion=1.4.2.Final
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pluginManagement {
repositories {
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'quarkus-annotation-processor-multi-module-build'

include ':common'
include ':application'

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.acme.quarkus;

import org.acme.quarkus.domain.Car;
import org.acme.quarkus.domain.CarDTO;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "cdi", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface CarMapper {

@Mapping(source = "numberOfSeats", target = "seatNumber")
CarDTO carToCarDTO(Car car);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.quarkus.domain;

public class Car {
private String type;
private Integer numberOfSeats;

public Car() {
}

public Car(String type, Integer numberOfSeats) {
this.type = type;
this.numberOfSeats = numberOfSeats;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Integer getNumberOfSeats() {
return numberOfSeats;
}

public void setNumberOfSeats(Integer numberOfSeats) {
this.numberOfSeats = numberOfSeats;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.quarkus.domain;

public class CarDTO {
private String type;
private Integer seatNumber;

public CarDTO() {
}

public CarDTO(String type, Integer seatNumber) {
this.type = type;
this.seatNumber = seatNumber;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Integer getSeatNumber() {
return seatNumber;
}

public void setSeatNumber(Integer seatNumber) {
this.seatNumber = seatNumber;
}
}
Loading

0 comments on commit f4b376b

Please sign in to comment.