-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for the
quarkus-spring-boot-properties
Quarkus extension
Exploratory testing for the `quarkus-spring-boot-properties` Quarkus extension. The application consists of a REST endpoint with some different approaches to inject properties. Current limitations: - Relaxing name convention is not supported and it won't be supported: quarkusio/quarkus#12483 - The annotation `@ConstructorBinding` is not supported yet: quarkusio/quarkus#19364
- Loading branch information
Showing
11 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>spring-properties</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: Spring: Properties</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-spring-boot-properties</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-spring-web</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
49 changes: 49 additions & 0 deletions
49
...pring-properties/src/main/java/io/quarkus/ts/spring/properties/CollectionsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/collections") | ||
public class CollectionsController { | ||
|
||
// Using `@Inject` instead of `@Autowired` to verify we can use both. | ||
@Inject | ||
ListWiringProperties listProperties; | ||
|
||
// Injecting maps is not supported. Reported in https://github.com/quarkusio/quarkus/issues/19366 | ||
// @Autowired | ||
// MapWiringProperties mapProperties; | ||
|
||
@GetMapping("/list/strings") | ||
public String listOfStrings() { | ||
return listProperties.strings.stream().collect(Collectors.joining(", ")); | ||
} | ||
|
||
// Injecting lists with objects is not unsupported. Reported in https://github.com/quarkusio/quarkus/issues/19365 | ||
// @GetMapping("/list/persons") | ||
// public String listOfPersons() { | ||
// return listProperties.persons.stream().map(Object::toString).collect(Collectors.joining(", ")); | ||
// } | ||
// | ||
|
||
// Injecting maps is not supported. Reported in https://github.com/quarkusio/quarkus/issues/19366 | ||
// @GetMapping("/map/integers") | ||
// public String mapOfIntegers() { | ||
// return mapProperties.integers.entrySet().stream() | ||
// .map(e -> e.getKey() + "=" + e.getValue()) | ||
// .collect(Collectors.joining(", ")); | ||
// } | ||
// | ||
// @GetMapping("/map/persons") | ||
// public String mapOfPersons() { | ||
// return mapProperties.persons.entrySet().stream() | ||
// .map(e -> e.getKey() + "=" + e.getValue()) | ||
// .collect(Collectors.joining(", ")); | ||
// } | ||
} |
39 changes: 39 additions & 0 deletions
39
...g/spring-properties/src/main/java/io/quarkus/ts/spring/properties/GreetingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/greeting") | ||
public class GreetingController { | ||
|
||
@Autowired | ||
GreetingProperties properties; | ||
|
||
@GetMapping("/text") | ||
public String text() { | ||
return properties.text; | ||
} | ||
|
||
@GetMapping("/textWithDefault") | ||
public String textWithDefault() { | ||
return properties.textWithDefault; | ||
} | ||
|
||
@GetMapping("/textPrivate") | ||
public String textPrivate() { | ||
return properties.getTextPrivate(); | ||
} | ||
|
||
@GetMapping("/textOptional") | ||
public String textOptional() { | ||
return properties.textOptional.orElse("empty!"); | ||
} | ||
|
||
@GetMapping("/message") | ||
public String message() { | ||
return properties.message.toString(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...g/spring-properties/src/main/java/io/quarkus/ts/spring/properties/GreetingProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("greeting") | ||
public class GreetingProperties { | ||
|
||
// Cover private field using public getter/setter | ||
private String textPrivate; | ||
|
||
// Cover optional fields | ||
public Optional<String> textOptional; | ||
|
||
// Cover direct field binding | ||
public String text; | ||
|
||
// Cover field with defaults | ||
public String textWithDefault = "Hola"; | ||
|
||
// Cover group fields | ||
public NestedMessage message; | ||
|
||
public String getTextPrivate() { | ||
return textPrivate; | ||
} | ||
|
||
public void setTextPrivate(String textPrivate) { | ||
this.textPrivate = textPrivate; | ||
} | ||
|
||
public static class NestedMessage { | ||
public String text; | ||
public String person = "unknown"; | ||
|
||
@Override | ||
public String toString() { | ||
return text + " " + person + "!"; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...spring-properties/src/main/java/io/quarkus/ts/spring/properties/ListWiringProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("lists") | ||
public class ListWiringProperties { | ||
|
||
// Cover injection of lists of strings; | ||
public List<String> strings; | ||
|
||
// Inject of complex objects in lists is not supported: https://github.com/quarkusio/quarkus/issues/19365 | ||
// // Cover injection of classes | ||
// public List<Person> persons; | ||
// | ||
// public static class Person { | ||
// public String name; | ||
// public int age; | ||
// | ||
// @Override | ||
// public String toString() { | ||
// return String.format("person[%s:%s]", name, age); | ||
// } | ||
// } | ||
} |
24 changes: 24 additions & 0 deletions
24
.../spring-properties/src/main/java/io/quarkus/ts/spring/properties/MapWiringProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import java.util.Map; | ||
|
||
// Injecting maps is not supported. Reported in https://github.com/quarkusio/quarkus/issues/19366 | ||
// @ConfigurationProperties("maps") | ||
public class MapWiringProperties { | ||
|
||
// Cover injection of maps of integers and strings; | ||
public Map<Integer, String> integers; | ||
|
||
// Cover injection of maps of string and classes | ||
public Map<String, Person> persons; | ||
|
||
public static class Person { | ||
public String name; | ||
public int age; | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("person[%s:%s]", name, age); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
spring/spring-properties/src/main/java/io/quarkus/ts/spring/properties/ValueController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.ts.spring.properties; | ||
|
||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/values") | ||
public class ValueController { | ||
|
||
@Value("${values.text}") | ||
String fieldUsingValue; | ||
|
||
@Value("${values.list}") | ||
String[] fieldUsingArray; | ||
|
||
// Complex SpEL expresions is not supported: https://github.com/quarkusio/quarkus/issues/19368" | ||
// @Value("#{'${values.list}'.split(',')}") | ||
// List<String> fieldUsingList; | ||
|
||
// Complex SpEL expresions is not supported: https://github.com/quarkusio/quarkus/issues/19368" | ||
// @Value("#{${values.map}}") | ||
// Map<String, String> fieldUsingMap; | ||
|
||
@GetMapping("/fieldUsingValue") | ||
public String fieldUsingValue() { | ||
return fieldUsingValue; | ||
} | ||
|
||
@GetMapping("/fieldUsingArray") | ||
public String fieldUsingArray() { | ||
return Stream.of(fieldUsingArray).collect(Collectors.joining(", ")); | ||
} | ||
|
||
// Complex SpEL expresions is not supported: https://github.com/quarkusio/quarkus/issues/19368" | ||
// @GetMapping("/fieldUsingList") | ||
// public String fieldUsingList() { | ||
// return fieldUsingList.stream().collect(Collectors.joining(", ")); | ||
// } | ||
// | ||
// @GetMapping("/fieldUsingMap") | ||
// public String fieldUsingMap() { | ||
// return fieldUsingMap.entrySet().stream() | ||
// .map(e -> e.getKey() + ": " + e.getValue()) | ||
// .collect(Collectors.joining(", ")); | ||
// } | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
spring/spring-properties/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Basic Fields | ||
greeting.text=hello | ||
greeting.text-private=private hello! | ||
greeting.message.text=Hola | ||
|
||
# List Fields | ||
lists.strings[0]=Value 1 | ||
|
||
lists.persons[0].name=Sarah | ||
lists.persons[0].age=19 | ||
lists.persons[1].name=Terminator | ||
lists.persons[1].age=999 | ||
|
||
# Map Fields | ||
maps.integers.1=Value 1 | ||
maps.integers.2=Value 2 | ||
|
||
maps.persons.character1.name=Sarah | ||
maps.persons.character1.age=19 | ||
maps.persons.character2.name=Terminator | ||
maps.persons.character2.age=999 | ||
|
||
# Values | ||
values.text=hello | ||
values.list=A,B | ||
values.map={key1: '1', key2: '2', key3: '3'} |
Oops, something went wrong.