From bfeb1ee48316f11c00583283d2b6244dd5cc6fc9 Mon Sep 17 00:00:00 2001 From: Gytis Trikleris Date: Wed, 18 Dec 2019 17:07:44 +0200 Subject: [PATCH] Spring Boot properties extension --- bom/deployment/pom.xml | 5 + bom/runtime/pom.xml | 23 ++++ ci-templates/stages.yml | 1 + .../builditem/FeatureBuildItem.java | 1 + .../ConfigPropertiesBuildStep.java | 67 +++-------- .../ConfigPropertiesMetadataBuildItem.java | 68 +++++++++++ extensions/pom.xml | 1 + .../spring-boot-properties/deployment/pom.xml | 42 +++++++ .../ConfigurationPropertiesProcessor.java | 64 ++++++++++ extensions/spring-boot-properties/pom.xml | 21 ++++ .../spring-boot-properties/runtime/pom.xml | 31 +++++ .../resources/META-INF/quarkus-extension.yaml | 9 ++ integration-tests/pom.xml | 1 + .../spring-boot-properties/pom.xml | 113 ++++++++++++++++++ .../quarkus/it/spring/boot/AnotherClass.java | 14 +++ .../it/spring/boot/BeanProperties.java | 37 ++++++ .../spring/boot/BeanPropertiesResource.java | 24 ++++ .../it/spring/boot/ClassProperties.java | 27 +++++ .../spring/boot/ClassPropertiesResource.java | 24 ++++ .../it/spring/boot/DefaultProperties.java | 17 +++ .../boot/DefaultPropertiesResource.java | 18 +++ .../it/spring/boot/InterfaceProperties.java | 9 ++ .../boot/InterfacePropertiesResource.java | 18 +++ .../it/spring/boot/SampleApplication.java | 11 ++ .../src/main/resources/application.properties | 5 + .../it/spring/boot/BeanPropertiesIT.java | 7 ++ .../it/spring/boot/BeanPropertiesTest.java | 27 +++++ .../it/spring/boot/ClassPropertiesIT.java | 7 ++ .../it/spring/boot/ClassPropertiesTest.java | 27 +++++ .../it/spring/boot/DefaultPropertiesIT.java | 7 ++ .../it/spring/boot/DefaultPropertiesTest.java | 20 ++++ .../it/spring/boot/InterfacePropertiesIT.java | 7 ++ .../spring/boot/InterfacePropertiesTest.java | 20 ++++ 33 files changed, 723 insertions(+), 50 deletions(-) create mode 100644 extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesMetadataBuildItem.java create mode 100644 extensions/spring-boot-properties/deployment/pom.xml create mode 100644 extensions/spring-boot-properties/deployment/src/main/java/io/quarkus/spring/boot/properties/deployment/ConfigurationPropertiesProcessor.java create mode 100644 extensions/spring-boot-properties/pom.xml create mode 100644 extensions/spring-boot-properties/runtime/pom.xml create mode 100644 extensions/spring-boot-properties/runtime/src/main/resources/META-INF/quarkus-extension.yaml create mode 100644 integration-tests/spring-boot-properties/pom.xml create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/AnotherClass.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanProperties.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanPropertiesResource.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassProperties.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassPropertiesResource.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultProperties.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultPropertiesResource.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfaceProperties.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfacePropertiesResource.java create mode 100644 integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/SampleApplication.java create mode 100644 integration-tests/spring-boot-properties/src/main/resources/application.properties create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesIT.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesTest.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesIT.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesTest.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesIT.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesTest.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesIT.java create mode 100644 integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesTest.java diff --git a/bom/deployment/pom.xml b/bom/deployment/pom.xml index 756c5db10..19e8672df 100644 --- a/bom/deployment/pom.xml +++ b/bom/deployment/pom.xml @@ -501,6 +501,11 @@ quarkus-spring-data-deployment ${project.version} + + io.quarkus + quarkus-spring-boot-properties-deployment + ${project.version} + io.quarkus quarkus-jgit-deployment diff --git a/bom/runtime/pom.xml b/bom/runtime/pom.xml index 66e3c1875..57d45db05 100644 --- a/bom/runtime/pom.xml +++ b/bom/runtime/pom.xml @@ -167,6 +167,7 @@ 5.1.8.RELEASE 2.1.9.RELEASE 5.2.0.RELEASE + 2.1.10.RELEASE 2.4.4.Final 3.0.0 5.3.1 @@ -640,6 +641,11 @@ quarkus-spring-data-jpa ${project.version} + + io.quarkus + quarkus-spring-boot-properties + ${project.version} + io.quarkus quarkus-swagger-ui @@ -2556,6 +2562,23 @@ + + + org.springframework.boot + spring-boot + ${spring-boot.version} + + + org.springframework + spring-core + + + org.springframework + spring-context + + + + org.keycloak diff --git a/ci-templates/stages.yml b/ci-templates/stages.yml index 035df977c..1b26fbf7b 100644 --- a/ci-templates/stages.yml +++ b/ci-templates/stages.yml @@ -363,6 +363,7 @@ stages: - spring-di - spring-web - spring-data-jpa + - spring-boot-properties name: spring - template: native-build-steps.yaml diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java index 602826188..c4c02efad 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/FeatureBuildItem.java @@ -79,6 +79,7 @@ public final class FeatureBuildItem extends MultiBuildItem { public static final String SPRING_WEB = "spring-web"; public static final String SPRING_DATA_JPA = "spring-data-jpa"; public static final String SPRING_SECURITY = "spring-security"; + public static final String SPRING_BOOT_PROPERTIES = "spring-boot-properties"; public static final String SWAGGER_UI = "swagger-ui"; public static final String TIKA = "tika"; public static final String UNDERTOW_WEBSOCKETS = "undertow-websockets"; diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java index 547f39fe2..174183df3 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java @@ -1,24 +1,16 @@ package io.quarkus.arc.deployment.configproperties; -import static io.quarkus.runtime.util.StringUtil.camelHumpsIterator; -import static io.quarkus.runtime.util.StringUtil.join; -import static io.quarkus.runtime.util.StringUtil.lowerCase; -import static io.quarkus.runtime.util.StringUtil.withoutSuffix; - import java.lang.reflect.Modifier; -import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.inject.Singleton; import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.jboss.jandex.IndexView; -import io.quarkus.arc.config.ConfigProperties; import io.quarkus.arc.deployment.ConfigPropertyBuildItem; import io.quarkus.arc.deployment.GeneratedBeanBuildItem; import io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor; @@ -35,17 +27,24 @@ import io.quarkus.gizmo.ClassOutput; public class ConfigPropertiesBuildStep { + @BuildStep + void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex, + BuildProducer configPropertiesMetadataProducer) { + for (AnnotationInstance annotation : combinedIndex.getIndex().getAnnotations(DotNames.CONFIG_PROPERTIES)) { + configPropertiesMetadataProducer.produce(new ConfigPropertiesMetadataBuildItem(annotation)); + } + } + @BuildStep void setup(CombinedIndexBuildItem combinedIndex, ApplicationIndexBuildItem applicationIndex, + List configPropertiesMetadataList, BuildProducer generatedClasses, BuildProducer generatedBeans, BuildProducer defaultConfigValues, BuildProducer configProperties, DeploymentClassLoaderBuildItem deploymentClassLoader) { - IndexView index = combinedIndex.getIndex(); - Collection instances = index.getAnnotations(DotNames.CONFIG_PROPERTIES); - if (instances.isEmpty()) { + if (configPropertiesMetadataList.isEmpty()) { return; } @@ -62,11 +61,10 @@ public class ConfigPropertiesBuildStep { .build(); producerClassCreator.addAnnotation(Singleton.class); - Set configClassesThatNeedValidation = new HashSet<>(instances.size()); - for (AnnotationInstance configPropertiesInstance : instances) { - ClassInfo classInfo = configPropertiesInstance.target().asClass(); + Set configClassesThatNeedValidation = new HashSet<>(configPropertiesMetadataList.size()); + for (ConfigPropertiesMetadataBuildItem configPropertiesMetadata : configPropertiesMetadataList) { + ClassInfo classInfo = configPropertiesMetadata.getClassInfo(); - String prefixStr = determinePrefix(configPropertiesInstance); if (Modifier.isInterface(classInfo.flags())) { /* * In this case we need to generate an implementation of the interface that for each interface method @@ -75,7 +73,7 @@ public class ConfigPropertiesBuildStep { */ String generatedClassName = InterfaceConfigPropertiesUtil.generateImplementationForInterfaceConfigProperties( - classInfo, nonBeansClassOutput, index, prefixStr, + classInfo, nonBeansClassOutput, combinedIndex.getIndex(), configPropertiesMetadata.getPrefix(), defaultConfigValues, configProperties); InterfaceConfigPropertiesUtil.addProducerMethodForInterfaceConfigProperties(producerClassCreator, classInfo.name(), generatedClassName); @@ -86,8 +84,8 @@ public class ConfigPropertiesBuildStep { * and call setters for value obtained from MP Config */ boolean needsValidation = ClassConfigPropertiesUtil.addProducerMethodForClassConfigProperties( - deploymentClassLoader.getClassLoader(), classInfo, producerClassCreator, prefixStr, - applicationIndex.getIndex(), configProperties); + deploymentClassLoader.getClassLoader(), classInfo, producerClassCreator, + configPropertiesMetadata.getPrefix(), applicationIndex.getIndex(), configProperties); if (needsValidation) { configClassesThatNeedValidation.add(classInfo.name()); } @@ -101,35 +99,4 @@ public class ConfigPropertiesBuildStep { configClassesThatNeedValidation); } } - - /** - * Use the annotation value - */ - private String determinePrefix(AnnotationInstance configPropertiesInstance) { - String fromAnnotation = getPrefixFromAnnotation(configPropertiesInstance); - if (fromAnnotation != null) { - return fromAnnotation; - } - return getPrefixFromClassName(configPropertiesInstance.target().asClass().name()); - } - - private String getPrefixFromAnnotation(AnnotationInstance configPropertiesInstance) { - AnnotationValue annotationValue = configPropertiesInstance.value("prefix"); - if (annotationValue == null) { - return null; - } - String value = annotationValue.asString(); - if (ConfigProperties.UNSET_PREFIX.equals(value) || value.isEmpty()) { - return null; - } - return value; - } - - private String getPrefixFromClassName(DotName className) { - String simpleName = className.isInner() ? className.local() : className.withoutPackagePrefix(); - return join("-", - withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration", - "properties", "props")); - } - } diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesMetadataBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesMetadataBuildItem.java new file mode 100644 index 000000000..cb7b84979 --- /dev/null +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesMetadataBuildItem.java @@ -0,0 +1,68 @@ +package io.quarkus.arc.deployment.configproperties; + +import static io.quarkus.runtime.util.StringUtil.camelHumpsIterator; +import static io.quarkus.runtime.util.StringUtil.join; +import static io.quarkus.runtime.util.StringUtil.lowerCase; +import static io.quarkus.runtime.util.StringUtil.withoutSuffix; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; + +import io.quarkus.arc.config.ConfigProperties; +import io.quarkus.builder.item.MultiBuildItem; + +public final class ConfigPropertiesMetadataBuildItem extends MultiBuildItem { + + private static final DotName CONFIG_PROPERTIES_ANNOTATION = DotName.createSimple(ConfigProperties.class.getName()); + + private final ClassInfo classInfo; + + private final String prefix; + + public ConfigPropertiesMetadataBuildItem(AnnotationInstance annotation) { + if (!CONFIG_PROPERTIES_ANNOTATION.equals(annotation.name())) { + throw new IllegalArgumentException(annotation + " is not an instance of " + ConfigProperties.class.getSimpleName()); + } + + this.classInfo = annotation.target().asClass(); + this.prefix = extractPrefix(annotation); + } + + public ConfigPropertiesMetadataBuildItem(ClassInfo classInfo, String prefix) { + this.classInfo = classInfo; + this.prefix = sanitisePrefix(prefix); + } + + public ClassInfo getClassInfo() { + return classInfo; + } + + public String getPrefix() { + return prefix; + } + + private String extractPrefix(AnnotationInstance annotationInstance) { + AnnotationValue value = annotationInstance.value("prefix"); + return sanitisePrefix(value == null ? null : value.asString()); + } + + private String sanitisePrefix(String prefix) { + if (isPrefixUnset(prefix)) { + return getPrefixFromClassName(classInfo.name()); + } + return prefix; + } + + private boolean isPrefixUnset(String prefix) { + return prefix == null || "".equals(prefix.trim()) || ConfigProperties.UNSET_PREFIX.equals(prefix.trim()); + } + + private String getPrefixFromClassName(DotName className) { + String simpleName = className.isInner() ? className.local() : className.withoutPackagePrefix(); + return join("-", + withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration", + "properties", "props")); + } +} diff --git a/extensions/pom.xml b/extensions/pom.xml index 02e982ef7..3d6ec81c0 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -93,6 +93,7 @@ spring-web spring-data-jpa spring-security + spring-boot-properties security diff --git a/extensions/spring-boot-properties/deployment/pom.xml b/extensions/spring-boot-properties/deployment/pom.xml new file mode 100644 index 000000000..60e3b3c0d --- /dev/null +++ b/extensions/spring-boot-properties/deployment/pom.xml @@ -0,0 +1,42 @@ + + + + quarkus-spring-boot-properties-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-spring-boot-properties-deployment + Quarkus - Spring Boot - Properties - Deployment + + + + io.quarkus + quarkus-spring-boot-properties + + + io.quarkus + quarkus-arc-deployment + + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${project.version} + + + + + + + \ No newline at end of file diff --git a/extensions/spring-boot-properties/deployment/src/main/java/io/quarkus/spring/boot/properties/deployment/ConfigurationPropertiesProcessor.java b/extensions/spring-boot-properties/deployment/src/main/java/io/quarkus/spring/boot/properties/deployment/ConfigurationPropertiesProcessor.java new file mode 100644 index 000000000..c638db20b --- /dev/null +++ b/extensions/spring-boot-properties/deployment/src/main/java/io/quarkus/spring/boot/properties/deployment/ConfigurationPropertiesProcessor.java @@ -0,0 +1,64 @@ +package io.quarkus.spring.boot.properties.deployment; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import io.quarkus.arc.deployment.configproperties.ConfigPropertiesMetadataBuildItem; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +public class ConfigurationPropertiesProcessor { + + private static final DotName CONFIGURATION_PROPERTIES_ANNOTATION = DotName + .createSimple(ConfigurationProperties.class.getName()); + + @BuildStep + public FeatureBuildItem registerFeature() { + return new FeatureBuildItem(FeatureBuildItem.SPRING_BOOT_PROPERTIES); + } + + @BuildStep + public void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex, + BuildProducer configPropertiesMetadataProducer) { + combinedIndex.getIndex() + .getAnnotations(CONFIGURATION_PROPERTIES_ANNOTATION) + .stream() + .map(annotation -> createConfigPropertiesMetadata(annotation, combinedIndex.getIndex())) + .forEach(configPropertiesMetadataProducer::produce); + } + + private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadata(AnnotationInstance annotation, IndexView index) { + switch (annotation.target().kind()) { + case CLASS: + return createConfigPropertiesMetadataFromClass(annotation); + case METHOD: + return createConfigPropertiesMetadataFromMethod(annotation, index); + default: + throw new IllegalArgumentException("Unsupported annotation target kind " + annotation.target().kind().name()); + } + } + + private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromClass(AnnotationInstance annotation) { + return new ConfigPropertiesMetadataBuildItem(annotation.target().asClass(), getPrefix(annotation)); + } + + private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromMethod(AnnotationInstance annotation, + IndexView index) { + return new ConfigPropertiesMetadataBuildItem(index.getClassByName(annotation.target().asMethod().returnType().name()), + getPrefix(annotation)); + } + + private String getPrefix(AnnotationInstance annotation) { + if (annotation.value() != null) { + return annotation.value().asString(); + } else if (annotation.value("prefix") != null) { + return annotation.value("prefix").asString(); + } + + return null; + } +} diff --git a/extensions/spring-boot-properties/pom.xml b/extensions/spring-boot-properties/pom.xml new file mode 100644 index 000000000..474cea7cf --- /dev/null +++ b/extensions/spring-boot-properties/pom.xml @@ -0,0 +1,21 @@ + + + + quarkus-build-parent + io.quarkus + 999-SNAPSHOT + ../../build-parent/pom.xml + + 4.0.0 + + quarkus-spring-boot-properties-parent + Quarkus - Spring Boot - Properties + pom + + + deployment + runtime + + \ No newline at end of file diff --git a/extensions/spring-boot-properties/runtime/pom.xml b/extensions/spring-boot-properties/runtime/pom.xml new file mode 100644 index 000000000..77fc15755 --- /dev/null +++ b/extensions/spring-boot-properties/runtime/pom.xml @@ -0,0 +1,31 @@ + + + + quarkus-spring-boot-properties-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-spring-boot-properties + Quarkus - Spring Boot - Properties - Runtime + Use Spring Boot properties annotations to configure your application + + + + org.springframework.boot + spring-boot + + + + + + + io.quarkus + quarkus-bootstrap-maven-plugin + + + + \ No newline at end of file diff --git a/extensions/spring-boot-properties/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/spring-boot-properties/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 000000000..71f0d04dd --- /dev/null +++ b/extensions/spring-boot-properties/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,9 @@ +--- +name: "Quarkus Extension for Spring Boot properties" +metadata: + keywords: + - "spring-boot" + - "properties" + categories: + - "compatibility" + status: "preview" diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 07a44e624..1584b414c 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -47,6 +47,7 @@ spring-di spring-web spring-data-jpa + spring-boot-properties infinispan-cache-jpa elytron-security elytron-security-oauth2 diff --git a/integration-tests/spring-boot-properties/pom.xml b/integration-tests/spring-boot-properties/pom.xml new file mode 100644 index 000000000..a90bcbac9 --- /dev/null +++ b/integration-tests/spring-boot-properties/pom.xml @@ -0,0 +1,113 @@ + + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-integration-test-spring-boot-properties + Quarkus - Integration Tests - Spring Boot properties + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-spring-boot-properties + + + io.quarkus + quarkus-junit5 + test + + + org.assertj + assertj-core + test + + + io.rest-assured + rest-assured + test + + + + + + + io.quarkus + quarkus-maven-plugin + ${project.version} + + + + build + + + + + + maven-compiler-plugin + + true + + + + + + + + native-image + + + native + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + io.quarkus + quarkus-maven-plugin + ${project.version} + + + native-image + + native-image + + + true + true + ${graalvmHome} + + + + + + + + + \ No newline at end of file diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/AnotherClass.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/AnotherClass.java new file mode 100644 index 000000000..fa865138d --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/AnotherClass.java @@ -0,0 +1,14 @@ +package io.quarkus.it.spring.boot; + +public final class AnotherClass { + + private boolean value; + + public boolean isValue() { + return value; + } + + public void setValue(boolean value) { + this.value = value; + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanProperties.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanProperties.java new file mode 100644 index 000000000..b74f7fe05 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanProperties.java @@ -0,0 +1,37 @@ +package io.quarkus.it.spring.boot; + +public final class BeanProperties { + + private int value; + + private InnerClass innerClass; + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public InnerClass getInnerClass() { + return innerClass; + } + + public void setInnerClass(InnerClass innerClass) { + this.innerClass = innerClass; + } + + public static class InnerClass { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanPropertiesResource.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanPropertiesResource.java new file mode 100644 index 000000000..2a07e6a7b --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/BeanPropertiesResource.java @@ -0,0 +1,24 @@ +package io.quarkus.it.spring.boot; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/bean") +public class BeanPropertiesResource { + + @Inject + BeanProperties properties; + + @Path("/value") + @GET + public int getValue() { + return properties.getValue(); + } + + @Path("/innerClass/value") + @GET + public String getInnerClassValue() { + return properties.getInnerClass().getValue(); + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassProperties.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassProperties.java new file mode 100644 index 000000000..2ebf71240 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassProperties.java @@ -0,0 +1,27 @@ +package io.quarkus.it.spring.boot; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("cl") +public final class ClassProperties { + + private String value; + + private AnotherClass anotherClass; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public AnotherClass getAnotherClass() { + return anotherClass; + } + + public void setAnotherClass(AnotherClass anotherClass) { + this.anotherClass = anotherClass; + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassPropertiesResource.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassPropertiesResource.java new file mode 100644 index 000000000..2cf1a0b14 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/ClassPropertiesResource.java @@ -0,0 +1,24 @@ +package io.quarkus.it.spring.boot; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/class") +public class ClassPropertiesResource { + + @Inject + ClassProperties properties; + + @Path("/value") + @GET + public String getValue() { + return properties.getValue(); + } + + @Path("/anotherClass/value") + @GET + public boolean isAnotherClassValue() { + return properties.getAnotherClass().isValue(); + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultProperties.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultProperties.java new file mode 100644 index 000000000..10e93421b --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultProperties.java @@ -0,0 +1,17 @@ +package io.quarkus.it.spring.boot; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties +public class DefaultProperties { + + private String value = "default-value"; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultPropertiesResource.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultPropertiesResource.java new file mode 100644 index 000000000..8e53fab28 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/DefaultPropertiesResource.java @@ -0,0 +1,18 @@ +package io.quarkus.it.spring.boot; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/default") +public class DefaultPropertiesResource { + + @Inject + DefaultProperties properties; + + @Path("/value") + @GET + public String getDefaultValue() { + return properties.getValue(); + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfaceProperties.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfaceProperties.java new file mode 100644 index 000000000..507d1df8a --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfaceProperties.java @@ -0,0 +1,9 @@ +package io.quarkus.it.spring.boot; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties +public interface InterfaceProperties { + + String getValue(); +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfacePropertiesResource.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfacePropertiesResource.java new file mode 100644 index 000000000..5f577c55a --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/InterfacePropertiesResource.java @@ -0,0 +1,18 @@ +package io.quarkus.it.spring.boot; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/interface") +public class InterfacePropertiesResource { + + @Inject + InterfaceProperties properties; + + @Path("/value") + @GET + public String getValue() { + return properties.getValue(); + } +} diff --git a/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/SampleApplication.java b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/SampleApplication.java new file mode 100644 index 000000000..f9c782ef9 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/java/io/quarkus/it/spring/boot/SampleApplication.java @@ -0,0 +1,11 @@ +package io.quarkus.it.spring.boot; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +public class SampleApplication { + + @ConfigurationProperties + public BeanProperties beanProperties() { + return new BeanProperties(); + } +} diff --git a/integration-tests/spring-boot-properties/src/main/resources/application.properties b/integration-tests/spring-boot-properties/src/main/resources/application.properties new file mode 100644 index 000000000..dd2729e5c --- /dev/null +++ b/integration-tests/spring-boot-properties/src/main/resources/application.properties @@ -0,0 +1,5 @@ +cl.value=class-value +cl.anotherClass.value=true +bean.value=1 +bean.innerClass.value=inner-class-value +interface.value=interface-value \ No newline at end of file diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesIT.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesIT.java new file mode 100644 index 000000000..460058bd1 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.spring.boot; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class BeanPropertiesIT extends BeanPropertiesTest { +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesTest.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesTest.java new file mode 100644 index 000000000..d5c8cab27 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/BeanPropertiesTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.spring.boot; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class BeanPropertiesTest { + + @Test + void shouldHaveValue() { + when().get("/bean/value") + .then() + .body(is(equalTo("1"))); + } + + @Test + void shouldHaveInnerClassValue() { + when().get("/bean/innerClass/value") + .then() + .body(is(equalTo("inner-class-value"))); + } +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesIT.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesIT.java new file mode 100644 index 000000000..ba0840c3b --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.spring.boot; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class ClassPropertiesIT extends ClassPropertiesTest { +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesTest.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesTest.java new file mode 100644 index 000000000..b3418599c --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/ClassPropertiesTest.java @@ -0,0 +1,27 @@ +package io.quarkus.it.spring.boot; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class ClassPropertiesTest { + + @Test + void shouldHaveValue() { + when().get("/class/value") + .then() + .body(is(equalTo("class-value"))); + } + + @Test + void shouldHaveAnotherClassValue() { + when().get("/class/anotherClass/value") + .then() + .body(is(equalTo("true"))); + } +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesIT.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesIT.java new file mode 100644 index 000000000..33f3de294 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.spring.boot; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class DefaultPropertiesIT extends DefaultPropertiesTest { +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesTest.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesTest.java new file mode 100644 index 000000000..65b9b5173 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/DefaultPropertiesTest.java @@ -0,0 +1,20 @@ +package io.quarkus.it.spring.boot; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class DefaultPropertiesTest { + + @Test + void shouldGetDefaultValue() { + when().get("/default/value") + .then() + .body(is(equalTo("default-value"))); + } +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesIT.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesIT.java new file mode 100644 index 000000000..9929d8e7d --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.spring.boot; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class InterfacePropertiesIT extends InterfacePropertiesTest { +} diff --git a/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesTest.java b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesTest.java new file mode 100644 index 000000000..3eb26bf14 --- /dev/null +++ b/integration-tests/spring-boot-properties/src/test/java/io/quarkus/it/spring/boot/InterfacePropertiesTest.java @@ -0,0 +1,20 @@ +package io.quarkus.it.spring.boot; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class InterfacePropertiesTest { + + @Test + void shouldHaveInt() { + when().get("/interface/value") + .then() + .body(is(equalTo("interface-value"))); + } +}