├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── 00-use-case.md │ ├── 01-compatible-certification-request.md │ ├── 10-clarification.md │ ├── 20-bug-report.md │ ├── 30-impl-proposal.md │ └── 40-process-change.md ├── dependabot.yml └── workflows │ └── build.yml ├── .gitignore ├── CONTRIBUTING.adoc ├── LICENSE ├── NOTICE ├── README.adoc ├── api ├── bnd.bnd ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── eclipse │ │ └── microprofile │ │ └── config │ │ ├── Config.java │ │ ├── ConfigProvider.java │ │ ├── ConfigValue.java │ │ ├── inject │ │ ├── ConfigProperties.java │ │ ├── ConfigProperty.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── spi │ │ ├── ConfigBuilder.java │ │ ├── ConfigProviderResolver.java │ │ ├── ConfigSource.java │ │ ├── ConfigSourceProvider.java │ │ ├── Converter.java │ │ └── package-info.java │ └── resources │ └── META-INF │ ├── LICENSE │ └── NOTICE ├── pom.xml ├── site.yaml ├── spec ├── pom.xml └── src │ └── main │ ├── asciidoc │ ├── architecture.asciidoc │ ├── configexamples.asciidoc │ ├── configprofile.asciidoc │ ├── configprovider.asciidoc │ ├── configsources.asciidoc │ ├── converters.asciidoc │ ├── license-alv2.asciidoc │ ├── license-efsl.adoc │ ├── microprofile-config-spec.asciidoc │ ├── property-expressions.asciidoc │ └── release_notes.asciidoc │ └── resources │ └── META-INF │ ├── LICENSE │ └── NOTICE └── tck ├── README.adoc ├── pom.xml └── src └── main ├── java └── org │ └── eclipse │ └── microprofile │ └── config │ └── tck │ ├── ArrayConverterBean.java │ ├── ArrayConverterTest.java │ ├── AutoDiscoveredConfigSourceTest.java │ ├── CDIPlainInjectionTest.java │ ├── CDIPropertyExpressionsTest.java │ ├── CDIPropertyNameMatchingTest.java │ ├── CdiOptionalInjectionTest.java │ ├── ClassConverterBean.java │ ├── ClassConverterTest.java │ ├── ConfigPropertiesTest.java │ ├── ConfigProviderTest.java │ ├── ConfigValueTest.java │ ├── ConverterTest.java │ ├── CustomConfigSourceTest.java │ ├── CustomConverterTest.java │ ├── ImplicitConverterTest.java │ ├── Location.java │ ├── OptionalValuesBean.java │ ├── ParseConverterInjection.java │ ├── PropertyExpressionsTest.java │ ├── SimpleValuesBean.java │ ├── WarPropertiesLocationTest.java │ ├── base │ └── AbstractTest.java │ ├── broken │ ├── ConfigObserver.java │ ├── ConfigOwner.java │ ├── ConfigPropertiesBeanMissingProperty.java │ ├── ConfigPropertiesMissingPropertyInjectionTest.java │ ├── CustomConverterBean.java │ ├── MissingConverterOnInstanceInjectionTest.java │ ├── MissingValueOnInstanceInjectionTest.java │ ├── MissingValueOnObserverMethodInjectionTest.java │ └── WrongConverterOnInstanceInjectionTest.java │ ├── configsources │ ├── CustomConfigProfileConfigSource.java │ ├── CustomConfigSourceProvider.java │ ├── CustomDbConfigSource.java │ ├── DefaultConfigSourceOrdinalTest.java │ └── SampleYamlConfigSource.java │ ├── converters │ ├── Donald.java │ ├── Duck.java │ ├── DuckConverter.java │ ├── NullConvertersTest.java │ ├── Pizza.java │ ├── PizzaConverter.java │ ├── UpperCaseDuckConverter.java │ ├── convertToNull │ │ ├── ConvertedNullValueBrokenInjectionBean.java │ │ ├── ConvertedNullValueBrokenInjectionTest.java │ │ └── ConvertedNullValueTest.java │ ├── custom │ │ ├── BooleanConverter.java │ │ ├── CharacterConverter.java │ │ ├── DoubleConverter.java │ │ ├── IntegerConverter.java │ │ └── LongConverter.java │ └── implicit │ │ ├── ConvTestSequenceOfBeforeValueOf.java │ │ ├── ConvTestSequenceParseBeforeConstructor.java │ │ ├── ConvTestSequenceValueOfBeforeParse.java │ │ ├── ConvTestTypeWCharSequenceParse.java │ │ ├── ConvTestTypeWStringCt.java │ │ ├── ConvTestTypeWStringOf.java │ │ ├── ConvTestTypeWStringValueOf.java │ │ └── SomeEnumToConvert.java │ ├── emptyvalue │ ├── EmptyValuesBean.java │ ├── EmptyValuesTest.java │ └── EmptyValuesTestProgrammaticLookup.java │ ├── profile │ ├── ConfigPropertyFileProfileTest.java │ ├── DevConfigProfileTest.java │ ├── InvalidConfigProfileTest.java │ ├── OverrideConfigProfileTest.java │ ├── ProdProfileTest.java │ ├── TestConfigProfileTest.java │ └── TestCustomConfigProfile.java │ └── util │ ├── AdditionalAssertions.java │ └── AdditionalMatchers.java └── resources ├── META-INF ├── LICENSE ├── NOTICE └── tck └── internal ├── META-INF ├── microprofile-config.properties └── services │ └── org.eclipse.microprofile.config.spi.ConfigSource └── sampleconfig.yaml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # http://editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | indent_style = space 9 | indent_size = 4 10 | end_of_line = lf 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | 15 | [*.md] 16 | trim_trailing_whitespace = false 17 | 18 | [*.adoc] 19 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Handle line endings automatically for files detected as text 2 | # and leave all files detected as binary untouched. 3 | * text=auto 4 | 5 | # 6 | # The above will handle all files NOT found below 7 | # 8 | # These files are text and should be normalized (Convert crlf => lf) 9 | *.adoc text 10 | *.conf text 11 | *.config text 12 | *.css text 13 | *.df text 14 | *.extension text 15 | *.groovy text 16 | *.htm text 17 | *.html text 18 | *.java text 19 | *.js text 20 | *.json text 21 | *.jsp text 22 | *.jspf text 23 | *.md text 24 | *.properties text 25 | *.sbt text 26 | *.scala text 27 | *.sh text 28 | *.sql text 29 | *.svg text 30 | *.template text 31 | *.tld text 32 | *.txt text 33 | *.vm text 34 | *.wadl text 35 | *.wsdl text 36 | *.xhtml text 37 | *.xml text 38 | *.xsd text 39 | *.yml text 40 | 41 | cipher text 42 | jaas text 43 | LICENSE text 44 | NOTICE text 45 | 46 | # These files are binary and should be left untouched 47 | # (binary is a macro for -text -diff) 48 | *.class binary 49 | *.dll binary 50 | *.ear binary 51 | *.gif binary 52 | *.ico binary 53 | *.jar binary 54 | *.jpg binary 55 | *.jpeg binary 56 | *.png binary 57 | *.ser binary 58 | *.so binary 59 | *.war binary 60 | *.zip binary 61 | *.exe binary 62 | *.gz binary 63 | 64 | #Windows 65 | *.bat text eol=crlf 66 | *.cmd text eol=crlf 67 | 68 | #Unix/Linux 69 | *.sh text eol=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/00-use-case.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Use case 3 | about: Describe a new use case for the specification. 4 | title: '' 5 | labels: 'use case :bulb:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | 12 | As a: 13 | 14 | - [ ] Application user/user of the configuration itself 15 | - [ ] API user (application developer) 16 | - [ ] SPI user (container or runtime developer) 17 | - [ ] Specification implementer 18 | 19 | ...I need to be able to: 20 | 21 | 22 | 23 | ...which enables me to: 24 | 25 | 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/01-compatible-certification-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Compatible Certification Request 3 | about: Start a request for a compatible certification 4 | title: 'MicroProfile Config [Version] Compatible Certification Request' 5 | labels: 'Certification :trophy:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | - [ ] Organization Name ("Organization") and, if applicable, URL:
11 | // Add here 12 | - [ ] Product Name, Version and download URL (if applicable):
13 | // Add here 14 | - [ ] Specification Name, Version and download URL:
15 | // Add here 16 | - [ ] (Optional) TCK Version, digital SHA-256 fingerprint and download URL:
17 | // Add here 18 | - [ ] Public URL of TCK Results Summary:
19 | // Add here 20 | - [ ] Any Additional Specification Certification Requirements:
21 | // Add here 22 | - [ ] Java runtime used to run the implementation:
23 | // Add here 24 | - [ ] Summary of the information for the certification environment, operating system, cloud, ...:
25 | // Add here 26 | - [ ] By checking this box I acknowledge that the Organization I represent accepts the terms of the [EFTL](https://www.eclipse.org/legal/tck.php). 27 | - [ ] By checking this box I attest that all TCK requirements have been met, including any compatibility rules. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/10-clarification.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Clarification request 3 | about: Request that some aspect of the specification be clarified. 4 | title: '' 5 | labels: 'clarification :mag_right:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/20-bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a mistake or inconsistency in the specification code or documentation text. 4 | title: '' 5 | labels: 'bug :beetle:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | **Describe the bug** 13 | 14 | (Describe the problem as concisely as possible.) 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/30-impl-proposal.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Implementation proposal 3 | about: Request or propose an implementation that solves one or more use cases. 4 | title: '' 5 | labels: 'impl. proposal :gear:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | 12 | 13 | 14 | 15 | **Use cases** 16 | 17 | 18 | 19 | * Fixes #xxxx 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/40-process-change.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Process change proposal 3 | about: Describe a change in the process of managing the specification project. 4 | title: '' 5 | labels: 'process change :busts_in_silhouette:' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | 12 | 13 | 14 | ***Footnote*** 15 | 16 | Please indicate your support for this issue by choosing the :+1: reaction, rather than adding a "+1" or similar comment. 17 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "github-actions" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: MicroProfile Config Build 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - 'editorconfig' 7 | - '.gitattributes' 8 | - '.gitignore' 9 | - 'CONTRIBUTING*' 10 | - 'CODEOWNERS' 11 | - 'KEYS' 12 | - 'LICENSE' 13 | - 'NOTICE' 14 | - 'README*' 15 | - 'site.yaml' 16 | pull_request: 17 | paths-ignore: 18 | - 'editorconfig' 19 | - '.gitattributes' 20 | - '.gitignore' 21 | - 'CONTRIBUTING*' 22 | - 'CODEOWNERS' 23 | - 'KEYS' 24 | - 'LICENSE' 25 | - 'NOTICE' 26 | - 'README*' 27 | - 'site.yaml' 28 | 29 | jobs: 30 | build: 31 | runs-on: ubuntu-latest 32 | strategy: 33 | matrix: 34 | java: [11,17] 35 | name: build with jdk ${{matrix.java}} 36 | 37 | steps: 38 | - uses: actions/checkout@v4 39 | name: checkout 40 | with: 41 | ref: ${{ github.event.pull_request.merge_commit_sha }} 42 | 43 | - uses: actions/setup-java@v4 44 | name: set up jdk ${{matrix.java}} 45 | with: 46 | distribution: temurin 47 | java-version: ${{matrix.java}} 48 | 49 | - name: build with maven 50 | run: | 51 | mvn -q -N io.takari:maven:0.7.7:wrapper -Dmaven=3.9.0 && ./mvnw -v 52 | ./mvnw -ntp formatter:validate install 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .settings/ 3 | .checkstyle 4 | target/ 5 | tck/bin/ 6 | .project 7 | build/ 8 | .classpath 9 | .factorypath 10 | test-output 11 | /*.log 12 | .idea 13 | *.iml 14 | *.iwl 15 | *.ipr 16 | .vscode/ 17 | # Ignore a release.conf for perform_release/* script usage 18 | release.conf 19 | **.DS_Store 20 | *.cache/ 21 | -------------------------------------------------------------------------------- /CONTRIBUTING.adoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Contributors to the Eclipse Foundation 3 | // 4 | // See the NOTICE file(s) distributed with this work for additional 5 | // information regarding copyright ownership. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // You may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | 20 | == How to contribute 21 | 22 | Do you want to contribute to this project? Here is what you can do: 23 | 24 | * Fork the repository, make changes, then do a pull request. 25 | ** Remember to https://help.github.com/articles/signing-commits/[sign your commits] 26 | ** If you contribute significant changes please make sure you have signed the https://www.eclipse.org/legal/ECA.php[Eclipse Contributor Agreement] 27 | * https://github.com/eclipse/microprofile-config/issues[Create or fix an issue]. 28 | * https://gitter.im/eclipse/microprofile-config[Join us on Gitter to discuss this project]. 29 | * Join our https://calendar.google.com/calendar/embed?src=gbnbc373ga40n0tvbl88nkc3r4%40group.calendar.google.com[weekly meeting] on Mondays at https://www.timeanddate.com/time/map/[14h00 GMT]. 30 | ** https://docs.google.com/document/d/1X6Q9K28VNHhVRkVBFlbNa-ZMusxjCfmoA7--uJFHWx0[Minutes and Agenda]. 31 | ** https://eclipse.zoom.us/j/949859967[Meeting room]. 32 | * Join the discussions on the https://groups.google.com/forum/#!forum/microprofile[MicroProfile Google Group] 33 | * https://microprofile.io/blog/[Contribute a blog post]. 34 | 35 | Also see the https://wiki.eclipse.org/MicroProfile/ContributingGuidelines[MicroProfile Contributing Guidelines] on the https://wiki.eclipse.org/MicroProfile[Eclipse MicroProfile wiki page] 36 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to section 4(d) of the Apache License, == 3 | == Version 2.0, in this case for Microprofile Config == 4 | ========================================================================= 5 | 6 | This product includes software developed at 7 | The Apache Software Foundation (http://www.apache.org/). 8 | 9 | Portions of this software were originally based on the following: 10 | * Apache DeltaSpike Config 11 | https://deltaspike.apache.org 12 | under Apache License, v2.0 13 | 14 | SPDXVersion: SPDX-2.1 15 | PackageName: Eclipse Microprofile 16 | PackageHomePage: http://www.eclipse.org/microprofile 17 | PackageLicenseDeclared: Apache-2.0 18 | 19 | PackageCopyrightText: 20 | Mark Struberg struberg@apache.org, 21 | Gerhard Petracek gpetracek@apache.org, 22 | Romain Manni-Bucau rmannibucau@apache.org, 23 | Ron Smeral rsmeral@apache.org, 24 | Emily Jiang emijiang@uk.ibm.com, 25 | Ondrej Mihalyi ondrej.mihalyi@gmail.com, 26 | Gunnar Morling gunnar@hibernate.org 27 | 28 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | // 4 | // See the NOTICE file(s) distributed with this work for additional 5 | // information regarding copyright ownership. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | image:https://badges.gitter.im/eclipse/microprofile-config.svg[link="https://gitter.im/eclipse/microprofile-config"] 20 | image:https://img.shields.io/maven-central/v/org.eclipse.microprofile.config/microprofile-config-api.svg[link="http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.eclipse.microprofile.config%22%20AND%20a%3A%22microprofile-config-api%22"] 21 | image:https://javadoc.io/badge/org.eclipse.microprofile.config/microprofile-config-api.svg[ link="https://javadoc.io/doc/org.eclipse.microprofile.config/microprofile-config-api"] 22 | 23 | # Configuration for MicroProfile (MicroProfile Config) 24 | 25 | MicroProfile Config Feature 26 | 27 | == Rationale 28 | 29 | The majority of applications need to be configured based on a running environment. 30 | It must be possible to modify configuration data from outside an application so that the application itself does not need to be repackaged. 31 | 32 | The configuration data can come from different locations and in different formats (e.g. system properties, system environment variables, .properties, .xml, datasource). 33 | We call these config locations ConfigSources. 34 | If the same property is defined in multiple ConfigSources, we apply a policy to specify which one of the values will effectively be used. 35 | 36 | Under some circumstances, some data sources may change dynamically. 37 | The changed values should be fed into the client without the need for restarting the application. 38 | This requirement is particularly important for microservices running in a cloud environment. 39 | The MicroProfile Config approach allows to pick up configured values immediately after they got changed. 40 | 41 | == Influences and History 42 | 43 | There are a number of Config projects which directly influenced this proposal and acted as basis for this API, such as: 44 | 45 | * DeltaSpike Config (http://deltaspike.apache.org/documentation/configuration.html) 46 | * Extracted parts of DeltaSpike Config (https://github.com/struberg/javaConfig/) 47 | * Apache Tamaya (http://tamaya.incubator.apache.org/) 48 | 49 | == Implementations 50 | 51 | Microprofile Config does not contain an implementation itself but only provides the specified API, a TCK and documentation. 52 | 53 | The following Implementations are available 54 | 55 | * Apache Geronimo Config (https://svn.apache.org/repos/asf/geronimo/components/config/trunk) 56 | * WebSphere Liberty 2017 March-June Beta so far (https://developer.ibm.com/wasdev/) 57 | * Payara Server 173 and Payara Micro 173 (https://docs.payara.fish/documentation/microprofile/config.html) 58 | * WildFly & Thorntail (https://github.com/smallrye/smallrye-config) 59 | * https://microbean.github.io/microbean-microprofile-config/[microBean(TM) MicroProfile Config] 60 | 61 | == Design 62 | 63 | The current configuration of an application can be accessed via _ConfigProvider#getConfig()_. 64 | 65 | A _Config_ consists of the information collected from the registered _org.eclipse.microprofile.config.spi.ConfigSource_ s. 66 | These _ConfigSource_ s get sorted according to their _ordinal_. 67 | That way it is possible to overwrite configuration with lower importance from outside. 68 | 69 | By default there are 3 default ConfigSources: 70 | 71 | * _System.getProperties()_ (ordinal=400) 72 | * _System.getenv()_ (ordinal=300) 73 | * all _META-INF/microprofile-config.properties_ files on the ClassPath. 74 | (default ordinal=100, separately configurable via a config_ordinal property inside each file) 75 | 76 | Therefore, the default values can be specified in the above files packaged with the application and the value can be overwritten later for each deployment. A higher ordinal number takes precedence over a lower number. 77 | 78 | == Custom ConfigSources 79 | 80 | It is possible to write and register a custom _ConfigSources_. 81 | An example would be a ConfigSource which gets the configured values from a shared database table in a cluster. 82 | 83 | == Building 84 | 85 | The whole MicroProfile config project can be built via Apache Maven 86 | 87 | $> mvn clean install 88 | 89 | == Contributing 90 | 91 | Do you want to contribute to this project? link:CONTRIBUTING.adoc[Find out how you can help here]. 92 | -------------------------------------------------------------------------------- /api/bnd.bnd: -------------------------------------------------------------------------------- 1 | -exportcontents: \ 2 | org.eclipse.microprofile.* 3 | 4 | Bundle-SymbolicName: org.eclipse.microprofile.config 5 | 6 | # For reproducible builds 7 | -noextraheaders: true 8 | -snapshot: SNAPSHOT 9 | 10 | # Apply OSGi Portable Java Contracts [1] with "active" effectiveness so that 11 | # they are not strict runtime requirements. This removes the need to import 12 | # packages with versions. 13 | -contract: *;effective:=active 14 | 15 | # Simulate the JavaCDI contract since the compile dependencies used do not 16 | # provide them. 17 | -define-contract: \ 18 | osgi.contract;\ 19 | osgi.contract=JavaCDI;\ 20 | version:List='2.0,1.1';\ 21 | uses:='\ 22 | jakarta.decorator,\ 23 | jakarta.enterprise.context,\ 24 | jakarta.enterprise.context.spi,\ 25 | jakarta.enterprise.event,\ 26 | jakarta.enterprise.inject,\ 27 | jakarta.enterprise.inject.spi,\ 28 | jakarta.enterprise.util' 29 | 30 | # [1] https://www.osgi.org/portable-java-contract-definitions/ -------------------------------------------------------------------------------- /api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 4.0.0 18 | 19 | 20 | org.eclipse.microprofile.config 21 | microprofile-config-parent 22 | 3.2-SNAPSHOT 23 | 24 | 25 | microprofile-config-api 26 | MicroProfile Config API 27 | MicroProfile Config :: API 28 | 29 | 30 | 31 | jakarta.enterprise 32 | jakarta.enterprise.cdi-api 33 | 34 | 35 | biz.aQute.bnd 36 | biz.aQute.bnd.annotation 37 | 38 | 39 | org.osgi 40 | org.osgi.service.cdi 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/ConfigProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Contributors: 20 | * 2016-07-14 - Mark Struberg 21 | * Initial revision cf41cf130bcaf5447ff8 22 | * 2016-07-20 - Romain Manni-Bucau 23 | * Initial ConfigBuilder PR 0945b23cbf9dadb75fb9 24 | * 2016-11-14 - Emily Jiang / IBM Corp 25 | * SPI reworked into own ConfigProviderResolver 26 | * 2016-12-02 - Viktor Klang 27 | * removed ConfigFilter and security related functionality. 28 | */ 29 | package org.eclipse.microprofile.config; 30 | 31 | import org.eclipse.microprofile.config.spi.ConfigProviderResolver; 32 | 33 | /** 34 | * This is the central class to access a {@link Config}. 35 | *

36 | * A {@link Config} provides access to the application's configuration. It may have been automatically discovered, or 37 | * manually created and registered. 38 | *

39 | * The default usage is to use {@link #getConfig()} to automatically pick up the configuration for the current 40 | * thread's {@linkplain Thread#getContextClassLoader() context class loader}. 41 | *

42 | * A configuration consists of information collected from the registered 43 | * {@linkplain org.eclipse.microprofile.config.spi.ConfigSource configuration sources}, combined with the set 44 | * of registered {@linkplain org.eclipse.microprofile.config.spi.Converter converters}. The configuration 45 | * sources get sorted according to their 46 | * {@linkplain org.eclipse.microprofile.config.spi.ConfigSource#getOrdinal() ordinal value}. Thus it is 47 | * possible to override a lower-priority configuration source with a higher-priority one. 48 | *

49 | * It is also possible to register custom configuration sources to flexibly extend the configuration mechanism. 50 | * For example, a configuration source could be provided which reads configuration values from a database table. 51 | * 52 | *

53 | * Example: 54 | * 55 | *

 56 |  * String restUrl = ConfigProvider.getConfig().getValue("myproject.some.remote.service.url", String.class);
 57 |  * Integer port = ConfigProvider.getConfig().getValue("myproject.some.remote.service.port", Integer.class);
 58 |  * 
59 | * 60 | *

61 | * For more advanced use cases (e.g. registering a manually created {@link Config} instance), please see 62 | * {@link ConfigProviderResolver#registerConfig(Config, ClassLoader)} and {@link ConfigProviderResolver#getBuilder()}. 63 | * 64 | * @author Mark Struberg 65 | * @author Romain Manni-Bucau 66 | * @author Emily Jiang 67 | * @author Viktor Klang 68 | */ 69 | public final class ConfigProvider { 70 | private ConfigProvider() { 71 | } 72 | 73 | /** 74 | * Get the {@linkplain Config configuration} corresponding to the current application, as defined by the calling 75 | * thread's {@linkplain Thread#getContextClassLoader() context class loader}. 76 | *

77 | * The {@link Config} instance will be created and registered to the context class loader if no such configuration 78 | * is already created and registered. 79 | *

80 | * Each class loader corresponds to exactly one configuration. 81 | * 82 | * @return the configuration instance for the thread context class loader 83 | */ 84 | public static Config getConfig() { 85 | return ConfigProviderResolver.instance().getConfig(); 86 | } 87 | 88 | /** 89 | * Get the {@linkplain Config configuration} for the application corresponding to the given class loader instance. 90 | *

91 | * The {@link Config} instance will be created and registered to the given class loader if no such configuration is 92 | * already created and registered. 93 | *

94 | * Each class loader corresponds to exactly one configuration. 95 | * 96 | * @param cl 97 | * the Classloader used to register the configuration instance 98 | * @return the configuration instance for the given class loader 99 | */ 100 | public static Config getConfig(ClassLoader cl) { 101 | return ConfigProviderResolver.instance().getConfig(cl); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/ConfigValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config; 20 | 21 | /** 22 | * The ConfigValue holds additional information after the lookup of a configuration property and is itself immutable. 23 | *

24 | * Holds information about the configuration property name, configuration value, the 25 | * {@link org.eclipse.microprofile.config.spi.ConfigSource} name from where the configuration property was loaded and 26 | * the ordinal of the {@link org.eclipse.microprofile.config.spi.ConfigSource}. 27 | *

28 | * This is used together with {@link Config} to expose the configuration property lookup metadata. 29 | * 30 | * @since 2.0 31 | * @author Roberto Cortez 32 | */ 33 | public interface ConfigValue { 34 | /** 35 | * The name of the property. 36 | * 37 | * @return the name of the property. 38 | */ 39 | String getName(); 40 | 41 | /** 42 | * The value of the property lookup with transformations (expanded, etc). 43 | * 44 | * @return the value of the property lookup or {@code null} if the property could not be found 45 | */ 46 | String getValue(); 47 | 48 | /** 49 | * The value of the property lookup without any transformation (expanded , etc). 50 | * 51 | * @return the raw value of the property lookup or {@code null} if the property could not be found. 52 | */ 53 | String getRawValue(); 54 | 55 | /** 56 | * The {@link org.eclipse.microprofile.config.spi.ConfigSource} name that loaded the property lookup. 57 | * 58 | * @return the ConfigSource name that loaded the property lookup or {@code null} if the property could not be found 59 | */ 60 | String getSourceName(); 61 | 62 | /** 63 | * The {@link org.eclipse.microprofile.config.spi.ConfigSource} ordinal that loaded the property lookup. 64 | * 65 | * @return the ConfigSource ordinal that loaded the property lookup or {@code 0} if the property could not be found 66 | */ 67 | int getSourceOrdinal(); 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/inject/ConfigProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.inject; 20 | 21 | import static java.lang.annotation.ElementType.FIELD; 22 | import static java.lang.annotation.ElementType.METHOD; 23 | import static java.lang.annotation.ElementType.PARAMETER; 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.Target; 30 | 31 | import jakarta.enterprise.util.AnnotationLiteral; 32 | import jakarta.enterprise.util.Nonbinding; 33 | import jakarta.inject.Qualifier; 34 | 35 | /** 36 | * Retrieve a number of related configuration properties with the specified prefix into a property class. This class 37 | * should contain a zero-arg constructor. Otherwise, non-portable behaviour occurs. 38 | * 39 | *

Example

40 | * 41 | *
42 |  * @ConfigProperties(prefix = "server")
43 |  * @Dependent
44 |  * public class MyServer {
45 |  *     public String host; // maps the property name server.host
46 |  *     public int port; // maps to the property name server.port
47 |  *     private String context; // maps to the property name server.context
48 |  *     @ConfigProperty(name = "old.location")
49 |  *     public String location; // maps to the property name server.old.location
50 |  *     public String getContext() {
51 |  *         return context;
52 |  *     }
53 |  * }
54 |  * 
55 | * 56 | * @since 2.0 57 | * @author Emily Jiang 58 | */ 59 | @Target({METHOD, FIELD, PARAMETER, TYPE}) 60 | @Retention(RUNTIME) 61 | @Documented 62 | @Qualifier 63 | public @interface ConfigProperties { 64 | String UNCONFIGURED_PREFIX = "org.eclipse.microprofile.config.inject.configproperties.unconfiguredprefix"; 65 | 66 | /** 67 | * The prefix of the configuration properties. 68 | * 69 | * @return the configuration property prefix 70 | */ 71 | @Nonbinding 72 | String prefix() default UNCONFIGURED_PREFIX; 73 | 74 | /** 75 | * Support inline instantiation of the {@link ConfigProperties} qualifier. 76 | */ 77 | final class Literal extends AnnotationLiteral implements ConfigProperties { 78 | public static final Literal NO_PREFIX = of(UNCONFIGURED_PREFIX); 79 | 80 | private static final long serialVersionUID = 1L; 81 | private final String prefix; 82 | 83 | public static Literal of(String prefix) { 84 | return new Literal(prefix); 85 | } 86 | 87 | private Literal(String prefix) { 88 | this.prefix = prefix; 89 | } 90 | 91 | @Override 92 | public String prefix() { 93 | return prefix; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/inject/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | /** 21 | * CDI Support for MicroProfile Config 22 | * 23 | *

24 | * MicroProfile Config also supports injection via a JSR-330 DI container: 25 | * 26 | *

27 |  *  @Inject
28 |  *  @ConfigProperty(name="myproject.some.endpoint.url");
29 |  *  private String restUrl;
30 |  * 
31 | * 32 | *

33 | * The following types can be injected: 34 | * 35 | *

43 | * 44 | * @author Mark Struberg 45 | * @author Emily Jiang 46 | */ 47 | @org.osgi.annotation.versioning.Version("2.0") 48 | package org.eclipse.microprofile.config.inject; 49 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | /** 21 | * Configuration for Java MicroProfile 22 | * 23 | *

Rationale

24 | * 25 | *

26 | * For many project artifacts (e.g. WAR, EAR) it should be possible to build them only once and then install them at 27 | * different customers, stages, etc. They need to target those different execution environments without the necessity of 28 | * any repackaging. In other words: depending on the situation they need different configuration. 29 | * 30 | *

31 | * This is easily achievable by having a set of default configuration values inside the project artifact. But be able to 32 | * overwrite those default values from external. 33 | * 34 | *

How it works

35 | * 36 | *

37 | * A Configuration consists of the information collected from the registered 38 | * {@link org.eclipse.microprofile.config.spi.ConfigSource ConfigSources}. These {@code ConfigSources} get sorted 39 | * according to their ordinal. That way it is possible to overwrite configuration with lower importance from 40 | * outside. 41 | * 42 | *

43 | * By default there are 3 ConfigSources: 44 | * 45 | *

51 | * 52 | *

53 | * That means that one can put the default configuration in a {@code META-INF/microprofile-config.properties} anywhere 54 | * on the classpath and the Operations team can later simply e.g set a system property to change this default 55 | * configuration. 56 | * 57 | *

58 | * It is of course also possible to register own {@link org.eclipse.microprofile.config.spi.ConfigSource ConfigSources}. 59 | * A {@code ConfigSource} could e.g. read configuration values from a database table, a remote server, etc 60 | * 61 | *

Accessing and Using the Configuration

62 | * 63 | *

64 | * The configuration of an application is represented by an instance of {@link org.eclipse.microprofile.config.Config}. 65 | * The {@link org.eclipse.microprofile.config.Config} can be accessed via the 66 | * {@link org.eclipse.microprofile.config.ConfigProvider}. 67 | * 68 | *

69 |  * Config config = ConfigProvider.getConfig();
70 |  * String restUrl = config.getValue("myproject.some.endpoint.url", String.class);
71 |  * 
72 | * 73 | *

74 | * Injection via a JSR-330 DI container is also supported: 75 | * 76 | *

77 |  * @Inject
78 |  * @ConfigProperty(name="myproject.some.endpoint.url");
79 |  * private String restUrl;
80 |  * 
81 | * 82 | * @author Emily Jiang 83 | * @author Mark Struberg 84 | */ 85 | @org.osgi.annotation.versioning.Version("3.0.0") 86 | package org.eclipse.microprofile.config; 87 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/spi/ConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Contributors: 20 | * 2016-07-20 - Romain Manni-Bucau 21 | * Initial ConfigBuilder PR 0945b23cbf9dadb75fb9 22 | * 2016-07-17 - Mark Struberg 23 | * Merged and JavaDoc c8525998a43fe798f367 24 | * 2016-11-14 - Emily Jiang / IBM 25 | * API improvements + JavaDoc f53258b8eca1253fee52 26 | */ 27 | package org.eclipse.microprofile.config.spi; 28 | 29 | import org.eclipse.microprofile.config.Config; 30 | 31 | /** 32 | * A builder for manually creating a configuration instance. 33 | * 34 | * @see ConfigProviderResolver#getBuilder() 35 | * 36 | * @author Romain Manni-Bucau 37 | * @author Mark Struberg 38 | * @author Emily Jiang 39 | */ 40 | @org.osgi.annotation.versioning.ProviderType 41 | public interface ConfigBuilder { 42 | /** 43 | * Add the default configuration sources to the 44 | * configuration being built. 45 | * 46 | * @return this configuration builder instance 47 | */ 48 | ConfigBuilder addDefaultSources(); 49 | 50 | /** 51 | * Add all configuration sources which can be discovered from this 52 | * configuration builder's {@linkplain #forClassLoader(ClassLoader) class loader}. 53 | * 54 | * @return this configuration builder instance 55 | */ 56 | ConfigBuilder addDiscoveredSources(); 57 | 58 | /** 59 | * Add all configuration converters which can be discovered from this 60 | * configuration builder's {@linkplain #forClassLoader(ClassLoader) class loader}. 61 | * 62 | * @return this configuration builder instance 63 | */ 64 | ConfigBuilder addDiscoveredConverters(); 65 | 66 | /** 67 | * Specify the class loader for which this configuration is being built. 68 | * 69 | * @param loader 70 | * the class loader 71 | * @return this configuration builder instance 72 | */ 73 | ConfigBuilder forClassLoader(ClassLoader loader); 74 | 75 | /** 76 | * Add the specified {@link ConfigSource} instances to the configuration being built. 77 | * 78 | * @param sources 79 | * the configuration sources 80 | * @return this configuration builder instance 81 | */ 82 | ConfigBuilder withSources(ConfigSource... sources); 83 | 84 | /** 85 | * Add the specified {@link Converter} instances to the configuration being built. 86 | *

87 | * The implementation may use reflection to determine the target type of the converter. If the type cannot be 88 | * determined reflectively, this method may fail with a runtime exception. 89 | *

90 | * When using lambda expressions for custom converters you should use the 91 | * {@link #withConverter(Class, int, Converter)} method and pass the target type explicitly, since lambda 92 | * expressions generally do not offer enough type information to the reflection API in order to determine the target 93 | * converter type. 94 | *

95 | * The added converters will be given a priority of {@code 100}. 96 | * 97 | * @param converters 98 | * the converters to add 99 | * @return this configuration builder instance 100 | */ 101 | ConfigBuilder withConverters(Converter... converters); 102 | 103 | /** 104 | * Add the specified {@link Converter} instance for the given type to the configuration being built. 105 | *

106 | * This method does not rely on reflection to determine the target type of the converter; therefore, lambda 107 | * expressions may be used for the converter instance. 108 | *

109 | * The priority value of custom converters defaults to {@code 100} if not specified. 110 | * 111 | * @param type 112 | * the class of the type to convert 113 | * @param priority 114 | * the priority of the converter 115 | * @param converter 116 | * the converter (can not be {@code null}) 117 | * @param 118 | * the type to convert 119 | * @return this configuration builder instance 120 | */ 121 | ConfigBuilder withConverter(Class type, int priority, Converter converter); 122 | 123 | /** 124 | * Build a new {@link Config} instance based on this builder instance. 125 | * 126 | * @return the new configuration object 127 | */ 128 | Config build(); 129 | } 130 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/spi/ConfigSourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | * Contributors: 20 | * 2011-12-28 - Mark Struberg & Gerhard Petracek 21 | * Initially authored in Apache DeltaSpike fb0131106481f0b9a8fd 22 | * 2016-07-14 - Mark Struberg 23 | * Extracted the Config part out of Apache DeltaSpike and proposed as Microprofile-Config 24 | * 2016-11-14 - Emily Jiang / IBM Corp 25 | * Methods renamed, JavaDoc and cleanup 26 | */ 27 | package org.eclipse.microprofile.config.spi; 28 | 29 | /** 30 | * A provider for configuration source instances. 31 | *

32 | * Implementations of this interface may supply zero or more {@linkplain ConfigSource configuration source} instances 33 | * for a given application (as defined by the application's {@link ClassLoader}). 34 | *

35 | * Instances of this interface will be {@linkplain ConfigBuilder#addDiscoveredSources() discovered} via the 36 | * {@link java.util.ServiceLoader} mechanism and can be registered by providing a 37 | * {@code META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider} 38 | * {@linkplain ClassLoader#getResource(String) resource} which contains the fully qualified class name of the custom 39 | * {@code ConfigSourceProvider} implementation. 40 | * 41 | * @author Mark Struberg 42 | * @author Gerhard Petracek 43 | * @author Emily Jiang 44 | */ 45 | public interface ConfigSourceProvider { 46 | /** 47 | * Return the {@link ConfigSource} instances that are provided by this provider. The {@link java.lang.Iterable 48 | * Iterable} contains a fixed number of {@linkplain ConfigSource configuration sources}, determined at application 49 | * start time, and the config sources themselves may be static or dynamic. An empty {@link java.lang.Iterable 50 | * Iterable} may be returned if no sources are to be provided. 51 | * 52 | * @param forClassLoader 53 | * the class loader which should be used for discovery and resource loading purposes 54 | * @return the {@link ConfigSource} instances to register to the configuration 55 | */ 56 | Iterable getConfigSources(ClassLoader forClassLoader); 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/org/eclipse/microprofile/config/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | /** 21 | * This package contains classes which are used to implement the configuration API, and to extend the standard 22 | * configuration functionality in a portable way. 23 | *

24 | * Users and frameworks may provide custom {@link org.eclipse.microprofile.config.spi.ConfigSource} and 25 | * {@link org.eclipse.microprofile.config.spi.Converter} instances. Configuration instances may be set up and created 26 | * using the {@link org.eclipse.microprofile.config.spi.ConfigBuilder} API. 27 | *

28 | * The package also contains the class {@link org.eclipse.microprofile.config.spi.ConfigProviderResolver}, which is used 29 | * to implement the specification itself. 30 | * 31 | * @author Emily Jiang 32 | * @author Mark Struberg 33 | * 34 | */ 35 | @org.osgi.annotation.versioning.Version("3.0") 36 | package org.eclipse.microprofile.config.spi; 37 | -------------------------------------------------------------------------------- /api/src/main/resources/META-INF/NOTICE: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to section 4(d) of the Apache License, == 3 | == Version 2.0, in this case for Microprofile Config == 4 | ========================================================================= 5 | 6 | This product includes software developed at 7 | The Apache Software Foundation (http://www.apache.org/). 8 | 9 | Portions of this software were originally based on the following: 10 | * Apache DeltaSpike Config 11 | https://deltaspike.apache.org 12 | under Apache License, v2.0 13 | 14 | SPDXVersion: SPDX-2.1 15 | PackageName: Eclipse Microprofile 16 | PackageHomePage: http://www.eclipse.org/microprofile 17 | PackageLicenseDeclared: Apache-2.0 18 | 19 | PackageCopyrightText: 20 | Mark Struberg struberg@apache.org, 21 | Gerhard Petracek gpetracek@apache.org, 22 | Romain Manni-Bucau rmannibucau@apache.org, 23 | Ron Smeral rsmeral@apache.org, 24 | Emily Jiang emijiang@uk.ibm.com, 25 | Ondrej Mihalyi ondrej.mihalyi@gmail.com, 26 | Gunnar Morling gunnar@hibernate.org 27 | 28 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 4.0.0 18 | 19 | 20 | org.eclipse.microprofile 21 | microprofile-parent 22 | 2.8 23 | 24 | 25 | org.eclipse.microprofile.config 26 | microprofile-config-parent 27 | 3.2-SNAPSHOT 28 | 29 | pom 30 | MicroProfile Config 31 | https://microprofile.io/project/eclipse/microprofile-config 32 | 33 | 34 | 2016 35 | 2.8 36 | 37 | 38 | 39 | GitHub 40 | https://github.com/eclipse/microprofile-config/issues 41 | 42 | 43 | 44 | 45 | Emily-Jiang 46 | Emily Jiang 47 | https://github.com/Emily-Jiang 48 | IBM 49 | https://www.ibm.com 50 | 51 | 52 | struberg 53 | Mark Struberg 54 | https://github.com/struberg 55 | 56 | 57 | OndrejM 58 | Ondro Mihalyi 59 | https://github.com/OndrejM 60 | Payara Services 61 | https://www.payara.fish 62 | 63 | 64 | radcortez 65 | Roberto Cortez 66 | https://radcortez.com 67 | Red Hat Inc. 68 | https://redhat.com 69 | 70 | 71 | 72 | 73 | scm:git:https://github.com/eclipse/microprofile-config.git 74 | scm:git:git@github.com:eclipse/microprofile-config.git 75 | https://github.com/eclipse/microprofile-config 76 | HEAD 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.osgi 84 | osgi.annotation 85 | 8.1.0 86 | provided 87 | 88 | 89 | biz.aQute.bnd 90 | biz.aQute.bnd.annotation 91 | 6.4.1 92 | provided 93 | 94 | 95 | org.osgi 96 | org.osgi.service.cdi 97 | 1.0.1 98 | provided 99 | 100 | 101 | 102 | org.eclipse.microprofile.config 103 | microprofile-config-api 104 | ${project.version} 105 | provided 106 | 107 | 108 | 109 | 110 | 111 | spec 112 | api 113 | tck 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /site.yaml: -------------------------------------------------------------------------------- 1 | ####################################################################### 2 | ## Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | ## 4 | ## See the NOTICE file(s) distributed with this work for additional 5 | ## information regarding copyright ownership. 6 | ## 7 | ## Licensed under the Apache License, Version 2.0 (the "License"); 8 | ## you may not use this file except in compliance with the License. 9 | ## You may obtain a copy of the License at 10 | ## 11 | ## http://www.apache.org/licenses/LICENSE-2.0 12 | ## 13 | ## Unless required by applicable law or agreed to in writing, software 14 | ## distributed under the License is distributed on an "AS IS" BASIS, 15 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ## See the License for the specific language governing permissions and 17 | ## limitations under the License. 18 | ####################################################################### 19 | %YAML 1.2 20 | --- 21 | documentation: 22 | - title: Configuration for Microprofile 23 | file: spec/src/main/asciidoc/microprofile-config-spec.asciidoc 24 | 25 | - title: Architecture 26 | file: spec/src/main/asciidoc/architecture.asciidoc 27 | 28 | - title: Configuration Usage Examples 29 | file: spec/src/main/asciidoc/configexamples.asciidoc 30 | 31 | - title: Accessing or Creating a certain Configuration 32 | file: spec/src/main/asciidoc/configprovider.asciidoc 33 | 34 | - title: ConfigSources 35 | file: spec/src/main/asciidoc/configsources.asciidoc 36 | 37 | - title: Converter 38 | file: spec/src/main/asciidoc/converters.asciidoc 39 | 40 | - title: License 41 | file: spec/src/main/asciidoc/license-alv2.asciidoc 42 | -------------------------------------------------------------------------------- /spec/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 4.0.0 18 | 19 | 20 | org.eclipse.microprofile.config 21 | microprofile-config-parent 22 | 3.2-SNAPSHOT 23 | 24 | 25 | microprofile-config-spec 26 | pom 27 | MicroProfile Config Specification 28 | 29 | 30 | -------------------------------------------------------------------------------- /spec/src/main/asciidoc/architecture.asciidoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2017 Eclipse Microprofile Contributors: 3 | // Mark Struberg 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | 18 | [[architecture]] 19 | == Architecture 20 | 21 | This specification defines an easy to use and flexible system for application configuration. 22 | It also defines ways to extend the configuration mechanism itself via a SPI (Service Provider Interface) in a portable fashion. 23 | 24 | === Rationale 25 | 26 | Released binaries often contain functionality which needs to behave slightly differently depending on the deployment. 27 | This might be the port numbers and URLs of REST endpoints to talk to (e.g. depending on the customer for whom a WAR is deployed). 28 | Or it might even be whole features which need to be switched on and off depending on the installation. 29 | All this must be possible without the need to re-package the whole application binary. 30 | 31 | MicroProfile Config provides a way to achieve this goal by aggregating configuration from many different <> and presents a single merged view to the user. 32 | This allows the application to bundle default configuration within the application. 33 | It also allows to override the defaults from outside or erase the property by simply specifying the property name without providing a value or an empty string as the value, 34 | e.g. via an environment variable a Java system property or via a container like Docker. 35 | MicroProfile Config also allows to implement and register own configuration sources in a portable way, e.g. for reading configuration values from a shared database in an application cluster. 36 | 37 | 38 | Internally, the core MicroProfile Config mechanism is purely String/String based. 39 | Type-safety is intentionally only provided on top of that by using the proper <> before handing the value out to the caller. 40 | 41 | The configuration key might use dot-separated blocks to prevent name conflicts. This is similar to Java package namespacing: 42 | 43 | [source, text] 44 | ---- 45 | com.acme.myproject.someserver.url = http://some.server/some/endpoint 46 | com.acme.myproject.someserver.port = 9085 47 | com.acme.myproject.someserver.active = true 48 | com.acme.other.stuff.name = Karl 49 | com.acme.myproject.notify.onerror=karl@mycompany,sue@mcompany 50 | some.library.own.config=some value 51 | ---- 52 | 53 | 54 | TIP: while the above example is in the java property file syntax the actual content could also e.g. be read from a database. 55 | 56 | -------------------------------------------------------------------------------- /spec/src/main/asciidoc/license-alv2.asciidoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2018 Eclipse Microprofile Contributors: 3 | // Mark Struberg 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | 18 | [subs="normal"] 19 | .... 20 | 21 | Specification: {doctitle} 22 | 23 | Version: {revnumber} 24 | 25 | Status: {revremark} 26 | 27 | Release: {revdate} 28 | 29 | Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 30 | 31 | Licensed under the Apache License, Version 2.0 (the "License"); 32 | you may not use this file except in compliance with the License. 33 | You may obtain a copy of the License at 34 | 35 | http://www.apache.org/licenses/LICENSE-2.0 36 | 37 | Unless required by applicable law or agreed to in writing, software 38 | distributed under the License is distributed on an "AS IS" BASIS, 39 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | See the License for the specific language governing permissions and 41 | limitations under the License. 42 | 43 | .... 44 | -------------------------------------------------------------------------------- /spec/src/main/asciidoc/license-efsl.adoc: -------------------------------------------------------------------------------- 1 | [subs="normal"] 2 | .... 3 | Specification: {doctitle} 4 | 5 | Version: {revnumber} 6 | 7 | Status: {revremark} 8 | 9 | Release: {revdate} 10 | .... 11 | 12 | == Copyright 13 | 14 | Copyright (c) {inceptionYear} , {currentYear} Eclipse Foundation. 15 | 16 | === Eclipse Foundation Specification License 17 | 18 | By using and/or copying this document, or the Eclipse Foundation 19 | document from which this statement is linked, you (the licensee) agree 20 | that you have read, understood, and will comply with the following 21 | terms and conditions: 22 | 23 | Permission to copy, and distribute the contents of this document, or 24 | the Eclipse Foundation document from which this statement is linked, in 25 | any medium for any purpose and without fee or royalty is hereby 26 | granted, provided that you include the following on ALL copies of the 27 | document, or portions thereof, that you use: 28 | 29 | * link or URL to the original Eclipse Foundation document. 30 | * All existing copyright notices, or if one does not exist, a notice 31 | (hypertext is preferred, but a textual representation is permitted) 32 | of the form: "Copyright (c) [$date-of-document] 33 | Eclipse Foundation, Inc. \<>" 34 | 35 | Inclusion of the full text of this NOTICE must be provided. We 36 | request that authorship attribution be provided in any software, 37 | documents, or other items or products that you create pursuant to the 38 | implementation of the contents of this document, or any portion 39 | thereof. 40 | 41 | No right to create modifications or derivatives of Eclipse Foundation 42 | documents is granted pursuant to this license, except anyone may 43 | prepare and distribute derivative works and portions of this document 44 | in software that implements the specification, in supporting materials 45 | accompanying such software, and in documentation of such software, 46 | PROVIDED that all such works include the notice below. HOWEVER, the 47 | publication of derivative works of this document for use as a technical 48 | specification is expressly prohibited. 49 | 50 | The notice is: 51 | 52 | "Copyright (c) [$date-of-document] Eclipse Foundation. This software or 53 | document includes material copied from or derived from [title and URI 54 | of the Eclipse Foundation specification document]." 55 | 56 | ==== Disclaimers 57 | 58 | THIS DOCUMENT IS PROVIDED "AS IS," AND THE COPYRIGHT 59 | HOLDERS AND THE ECLIPSE FOUNDATION MAKE NO REPRESENTATIONS OR 60 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 61 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 62 | NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE DOCUMENT ARE 63 | SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS 64 | WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR 65 | OTHER RIGHTS. 66 | 67 | THE COPYRIGHT HOLDERS AND THE ECLIPSE FOUNDATION WILL NOT BE LIABLE 68 | FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT 69 | OF ANY USE OF THE DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE 70 | CONTENTS THEREOF. 71 | 72 | The name and trademarks of the copyright holders or the Eclipse 73 | Foundation may NOT be used in advertising or publicity pertaining to 74 | this document or its contents without specific, written prior 75 | permission. Title to copyright in this document will at all times 76 | remain with copyright holders. 77 | -------------------------------------------------------------------------------- /spec/src/main/asciidoc/microprofile-config-spec.asciidoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016-2019 Eclipse Microprofile Contributors: 3 | // Mark Struberg 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | 18 | = Configuration for MicroProfile 19 | :authors: Mark Struberg, Emily Jiang, John D. Ament, Roberto Cortez, Jan Bernitt 20 | :email: struberg@apache.org, emijiang@uk.ibm.com, john.d.ament@gmail.com, radcortez@yahoo.com, jaanbernitt@gmail.com 21 | :version-label!: 22 | :sectanchors: 23 | :doctype: book 24 | :license: Eclipse Foundation Specification License v1.0 25 | :source-highlighter: coderay 26 | :toc: left 27 | :toclevels: 4 28 | :sectnumlevels: 4 29 | ifdef::backend-pdf[] 30 | :pagenums: 31 | endif::[] 32 | 33 | // == License 34 | :sectnums!: 35 | include::license-efsl.adoc[] 36 | 37 | :sectnums: 38 | 39 | == MicroProfile Config 40 | 41 | 42 | include::architecture.asciidoc[] 43 | 44 | include::configexamples.asciidoc[] 45 | 46 | include::configprovider.asciidoc[] 47 | 48 | include::configsources.asciidoc[] 49 | 50 | include::converters.asciidoc[] 51 | 52 | include::configprofile.asciidoc[] 53 | 54 | include::property-expressions.asciidoc[] 55 | 56 | :sectnums!: 57 | include::release_notes.asciidoc[] 58 | -------------------------------------------------------------------------------- /spec/src/main/asciidoc/property-expressions.asciidoc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | // 4 | // See the NOTICE file(s) distributed with this work for additional 5 | // information regarding copyright ownership. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // You may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // Contributors: 19 | // Roberto Cortez 20 | 21 | [[property-expressions]] 22 | == Property Expressions 23 | 24 | The value of a configuration property may contain an expression corresponding to another configuration property. An 25 | expression string is a mix of plain strings and expression segments, which are wrapped by the sequence `${ ... }`. 26 | 27 | Consider the following configuration properties file: 28 | 29 | [source,properties] 30 | ---- 31 | server.url=http://${server.host}/endpoint 32 | server.host=example.org 33 | ---- 34 | 35 | When looking up the `server.url` property, the value will be resolved and expanded to `http://example.org/endpoint`. 36 | All MicroProfile Config rules still apply. The `Config` is able to resolve expressions from different ConfigSources. 37 | 38 | Additionally, it is also possible to use the following syntax for property expressions: 39 | 40 | * `${expression:value}` - Provides a default value after the `:` if the expression doesn't find a value. 41 | * `${my.prop${compose}}` - Composed expressions. Inner expressions are resolved first. 42 | * `${my.prop}${my.prop}` - Multiple expressions. 43 | 44 | Consider the following configuration properties file: 45 | 46 | [source,properties] 47 | ---- 48 | server.url=http://${server.host:example.org}:${server.port}/${server.endpoint} 49 | server.port=8080 50 | server.endpoint=${server.endpoint.path.${server.endpoint.path.bar}} 51 | server.endpoint.path.foo=foo 52 | server.endpoint.path.bar=foo 53 | ---- 54 | 55 | The property `server.url` is expanded to `http://example.org:8080/foo`. 56 | 57 | If an expression cannot be expanded and does not have a default value, a `NoSuchElementException` is thrown. In the 58 | Optional case, an empty Optional will be returned. In the `ConfigValue` case, an `ConfigValue` with only 59 | the name of the property will be returned. 60 | 61 | The number of recursion lookups is not infinite, but a limited number for composed expressions. Implementations are 62 | encouraged to limit the number to `5`, but they can use higher limits if they wish to. When the number of allowed 63 | lookups exceeds the limit, an `IllegalArgumentException` is thrown. 64 | 65 | Property expressions applies to all the methods in `Config` that performs resolution of a configuration property, 66 | including `getValue`, `getValues`, `getConfigValue`, `getValues`, `getOptionalValue`, `getOptionalValues` 67 | and `getConfigProperties`. The methods `getValue` and `getProperties` in `ConfigSource`, may support property 68 | expressions as well, but it is not required by the specification. 69 | 70 | Property expressions must also be applied to configuration properties injected via CDI. A default value 71 | defined via `org.eclipse.microprofile.config.inject.ConfigProperty#defaultValue` is not eligible to be expanded since 72 | multiple candidates may be available. 73 | 74 | If a configuration property value or default value requires the raw value without expansion, the expression may be 75 | escaped with a backslash ("\", double "\\" for property file-based sources). For instance: 76 | 77 | [source,properties] 78 | ---- 79 | server.url=\\${server.host} 80 | server.host=localhost 81 | ---- 82 | 83 | The value of `server.url` is `${server.host}`. 84 | 85 | === Backwards Compatibility 86 | 87 | MicroProfile Config implementations MUST provide a way to disable variable evaluation to provide backwards 88 | compatibility. The property `mp.config.property.expressions.enabled` was introduced for this purpose. The value of the 89 | property determines whether the property expression is enabled or disabled. The value `false` means the property 90 | expression is disabled, while `true` means enabled. 91 | 92 | If property expression expansion is not desirable for a specific case, the raw value on a configuration property may be 93 | retrieved by calling `getRawValue()` in `ConfigValue`. 94 | 95 | Specific sources may already use a similar or identical syntax to the one described in this specification. To preserve 96 | this usage, `ConfigSource#getValue()` should perform the expression substitution and then return the resolved value. 97 | Should such a source return a value with an expression from `ConfigSource#getValue()`, usual expression substitution 98 | does occur as described by this spec. 99 | -------------------------------------------------------------------------------- /spec/src/main/resources/META-INF/NOTICE: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to section 4(d) of the Apache License, == 3 | == Version 2.0, in this case for Microprofile Config == 4 | ========================================================================= 5 | 6 | SPDXVersion: SPDX-2.1 7 | PackageName: Eclipse Microprofile 8 | PackageHomePage: http://www.eclipse.org/microprofile 9 | PackageLicenseDeclared: Apache-2.0 10 | 11 | PackageCopyrightText: 12 | Mark Struberg struberg@apache.org 13 | Emily Jiang emijiang@uk.ibm.com 14 | -------------------------------------------------------------------------------- /tck/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 4.0.0 18 | 19 | 20 | org.eclipse.microprofile.config 21 | microprofile-config-parent 22 | 3.2-SNAPSHOT 23 | 24 | 25 | microprofile-config-tck 26 | MicroProfile Config TCK 27 | 28 | 29 | 30 | 31 | org.eclipse.microprofile 32 | microprofile-tck-bom 33 | ${version.microprofile.tck.bom} 34 | pom 35 | import 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | jakarta.enterprise 44 | jakarta.enterprise.cdi-api 45 | 46 | 47 | 48 | org.eclipse.microprofile.config 49 | microprofile-config-api 50 | 51 | 52 | 53 | org.osgi 54 | osgi.annotation 55 | 56 | 57 | 58 | org.testng 59 | testng 60 | 61 | 62 | 63 | org.hamcrest 64 | hamcrest-all 65 | 66 | 67 | 68 | org.jboss.arquillian.testng 69 | arquillian-testng-container 70 | 71 | 72 | 73 | org.jboss.shrinkwrap 74 | shrinkwrap-api 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/AutoDiscoveredConfigSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 4 | * 5 | * See the NOTICE file(s) distributed with this work for additional 6 | * information regarding copyright ownership. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * You may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | *******************************************************************************/ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import org.eclipse.microprofile.config.Config; 23 | import org.eclipse.microprofile.config.spi.ConfigProviderResolver; 24 | import org.eclipse.microprofile.config.spi.ConfigSource; 25 | import org.eclipse.microprofile.config.spi.Converter; 26 | import org.eclipse.microprofile.config.tck.configsources.CustomDbConfigSource; 27 | import org.eclipse.microprofile.config.tck.converters.Pizza; 28 | import org.eclipse.microprofile.config.tck.converters.PizzaConverter; 29 | import org.jboss.arquillian.container.test.api.Deployment; 30 | import org.jboss.arquillian.testng.Arquillian; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.Assert; 36 | import org.testng.annotations.Test; 37 | 38 | /** 39 | * Verify the method addDiscoveredSources() on ConfigBuilder. 40 | * 41 | * @author Emily Jiang 42 | * @author Mark Struberg 43 | */ 44 | public class AutoDiscoveredConfigSourceTest extends Arquillian { 45 | 46 | @Deployment 47 | public static WebArchive deploy() { 48 | JavaArchive testJar = ShrinkWrap 49 | .create(JavaArchive.class, "customConfigSourceTest.jar") 50 | .addClasses(AutoDiscoveredConfigSourceTest.class, CustomDbConfigSource.class, Pizza.class, 51 | PizzaConverter.class) 52 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 53 | .addAsServiceProvider(ConfigSource.class, CustomDbConfigSource.class) 54 | .addAsServiceProvider(Converter.class, PizzaConverter.class) 55 | .as(JavaArchive.class); 56 | 57 | WebArchive war = ShrinkWrap 58 | .create(WebArchive.class, "customConfigSourceTest.war") 59 | .addAsLibrary(testJar); 60 | return war; 61 | } 62 | 63 | @Test 64 | public void testAutoDiscoveredConfigureSources() { 65 | Config config = 66 | ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().build(); 67 | Assert.assertEquals(config.getValue("tck.config.test.customDbConfig.key1", String.class), "valueFromDb1"); 68 | } 69 | @Test 70 | public void testAutoDiscoveredConverterManuallyAdded() { 71 | 72 | Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources() 73 | .addDiscoveredConverters().build(); 74 | Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class); 75 | Assert.assertEquals(dVaule.getSize(), "big"); 76 | Assert.assertEquals(dVaule.getFlavor(), "cheese"); 77 | } 78 | 79 | @Test(expectedExceptions = IllegalArgumentException.class) 80 | public void testAutoDiscoveredConverterNotAddedAutomatically() { 81 | Config config = 82 | ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().build(); 83 | Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class); 84 | Assert.fail("The auto discovered converter should not be added automatically."); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/CdiOptionalInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.testng.Arquillian; 24 | import org.jboss.shrinkwrap.api.ShrinkWrap; 25 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 26 | import org.jboss.shrinkwrap.api.asset.StringAsset; 27 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 28 | import org.jboss.shrinkwrap.api.spec.WebArchive; 29 | import org.testng.Assert; 30 | import org.testng.annotations.Test; 31 | 32 | import jakarta.inject.Inject; 33 | 34 | /** 35 | * Verify injection of {@code Optional} fields. 36 | * 37 | * @author Mark Struberg 38 | */ 39 | public class CdiOptionalInjectionTest extends Arquillian { 40 | 41 | private @Inject OptionalValuesBean optionalValuesBean; 42 | 43 | @Deployment 44 | public static WebArchive deploy() { 45 | JavaArchive testJar = ShrinkWrap 46 | .create(JavaArchive.class, "cdiOptionalInjectionTest.jar") 47 | .addClasses(CdiOptionalInjectionTest.class, OptionalValuesBean.class) 48 | .addAsManifestResource( 49 | new StringAsset( 50 | "my.optional.int.property=1234\n" + 51 | "my.optional.long.property=1234\n" + 52 | "my.optional.double.property=1234.5\n" + 53 | "my.optional.string.property=hello"), 54 | "microprofile-config.properties") 55 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 56 | .as(JavaArchive.class); 57 | 58 | WebArchive war = ShrinkWrap 59 | .create(WebArchive.class, "cdiOptionalInjectionTest.war") 60 | .addAsLibrary(testJar); 61 | return war; 62 | } 63 | 64 | @Test 65 | public void testOptionalInjection() { 66 | Assert.assertTrue(optionalValuesBean.getIntProperty().isPresent()); 67 | Assert.assertEquals(optionalValuesBean.getIntProperty().get(), Integer.valueOf(1234)); 68 | 69 | Assert.assertFalse(optionalValuesBean.getNotexistingProperty().isPresent()); 70 | 71 | Assert.assertTrue(optionalValuesBean.getStringValue().isPresent()); 72 | Assert.assertEquals(optionalValuesBean.getStringValue().get(), "hello"); 73 | 74 | Assert.assertFalse(optionalValuesBean.getNotExistingStringProperty().isPresent()); 75 | 76 | Assert.assertTrue(optionalValuesBean.getOptionalIntProperty().isPresent()); 77 | Assert.assertEquals(optionalValuesBean.getOptionalIntProperty().getAsInt(), 1234); 78 | 79 | Assert.assertFalse(optionalValuesBean.getOptionalNotExistingIntProperty().isPresent()); 80 | 81 | Assert.assertTrue(optionalValuesBean.getOptionalLongProperty().isPresent()); 82 | Assert.assertEquals(optionalValuesBean.getOptionalLongProperty().getAsLong(), 1234); 83 | 84 | Assert.assertFalse(optionalValuesBean.getOptionalNotExistingLongProperty().isPresent()); 85 | 86 | Assert.assertTrue(optionalValuesBean.getOptionalDoubleProperty().isPresent()); 87 | Assert.assertEquals(optionalValuesBean.getOptionalDoubleProperty().getAsDouble(), 1234.5); 88 | 89 | Assert.assertFalse(optionalValuesBean.getOptionalNotExistingDoubleProperty().isPresent()); 90 | } 91 | 92 | @Test 93 | public void testOptionalInjectionWithNoDefaultValueOrElseIsReturned() { 94 | Assert.assertEquals("foo", optionalValuesBean.getNotExistingStringProperty().orElse("foo")); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/ClassConverterBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import java.util.List; 23 | import java.util.Set; 24 | 25 | import org.eclipse.microprofile.config.inject.ConfigProperty; 26 | 27 | import jakarta.enterprise.context.Dependent; 28 | import jakarta.inject.Inject; 29 | 30 | @Dependent 31 | public class ClassConverterBean { 32 | @Inject 33 | @ConfigProperty(name = "tck.config.test.javaconfig.converter.class") 34 | private Class testClass; 35 | 36 | @Inject 37 | @ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array") 38 | private Class[] testClasses; 39 | 40 | @Inject 41 | @ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array") 42 | private Set testClassSet; 43 | 44 | @Inject 45 | @ConfigProperty(name = "tck.config.test.javaconfig.converter.class.array") 46 | private List testClassList; 47 | 48 | public Class getTestClass() { 49 | return testClass; 50 | } 51 | 52 | public Class[] getTestClasses() { 53 | return testClasses; 54 | } 55 | 56 | public Set getTestClassSet() { 57 | return testClassSet; 58 | } 59 | 60 | public List getTestClassList() { 61 | return testClassList; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/ClassConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import static org.eclipse.microprofile.config.tck.base.AbstractTest.addFile; 23 | import static org.testng.Assert.assertEquals; 24 | 25 | import java.util.Arrays; 26 | import java.util.LinkedHashSet; 27 | 28 | import org.eclipse.microprofile.config.Config; 29 | import org.jboss.arquillian.container.test.api.Deployment; 30 | import org.jboss.arquillian.testng.Arquillian; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.annotations.Test; 36 | 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test Class type converter handling 41 | * 42 | * @author John D. Ament 43 | */ 44 | public class ClassConverterTest extends Arquillian { 45 | 46 | @Deployment 47 | public static WebArchive deploy() { 48 | String archiveName = ClassConverterTest.class.getSimpleName(); 49 | JavaArchive testJar = ShrinkWrap 50 | .create(JavaArchive.class, archiveName + ".jar") 51 | .addClasses(ClassConverterBean.class, ClassConverterTest.class) 52 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 53 | .as(JavaArchive.class); 54 | 55 | addFile(testJar, "META-INF/microprofile-config.properties"); 56 | 57 | WebArchive war = ShrinkWrap 58 | .create(WebArchive.class, archiveName + ".war") 59 | .addAsLibrary(testJar); 60 | return war; 61 | } 62 | 63 | @Inject 64 | private Config config; 65 | 66 | @Inject 67 | private ClassConverterBean classConverterBean; 68 | 69 | @Test 70 | public void testClassConverterWithLookup() { 71 | Class testClass = config.getValue("tck.config.test.javaconfig.converter.class", Class.class); 72 | assertEquals(testClass, ClassConverterTest.class); 73 | Class[] testClasses = config.getValue("tck.config.test.javaconfig.converter.class.array", Class[].class); 74 | assertEquals(testClasses.length, 2); 75 | assertEquals(testClasses, new Class[]{ClassConverterTest.class, String.class}); 76 | } 77 | 78 | @Test 79 | public void testGetClassConverter() { 80 | Class testClass = config.getConverter(Class.class).get() 81 | .convert("org.eclipse.microprofile.config.tck.ClassConverterTest"); 82 | assertEquals(testClass, ClassConverterTest.class); 83 | Class[] testClasses = config.getConverter(Class[].class).get() 84 | .convert("org.eclipse.microprofile.config.tck.ClassConverterTest,java.lang.String"); 85 | assertEquals(testClasses.length, 2); 86 | assertEquals(testClasses, new Class[]{ClassConverterTest.class, String.class}); 87 | } 88 | 89 | @Test 90 | public void testConverterForClassLoadedInBean() { 91 | assertEquals(classConverterBean.getTestClass(), ClassConverterTest.class); 92 | assertEquals(classConverterBean.getTestClasses().length, 2); 93 | assertEquals(classConverterBean.getTestClasses(), new Class[]{ClassConverterTest.class, String.class}); 94 | assertEquals(classConverterBean.getTestClassSet().size(), 2); 95 | assertEquals(classConverterBean.getTestClassSet(), 96 | new LinkedHashSet<>(Arrays.asList(ClassConverterTest.class, String.class))); 97 | assertEquals(classConverterBean.getTestClassList().size(), 2); 98 | assertEquals(classConverterBean.getTestClassList(), Arrays.asList(ClassConverterTest.class, String.class)); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/CustomConfigSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import static org.eclipse.microprofile.config.tck.base.AbstractTest.addFile; 23 | 24 | import org.eclipse.microprofile.config.Config; 25 | import org.eclipse.microprofile.config.spi.ConfigSource; 26 | import org.eclipse.microprofile.config.spi.ConfigSourceProvider; 27 | import org.eclipse.microprofile.config.tck.configsources.CustomConfigSourceProvider; 28 | import org.eclipse.microprofile.config.tck.configsources.CustomDbConfigSource; 29 | import org.jboss.arquillian.container.test.api.Deployment; 30 | import org.jboss.arquillian.testng.Arquillian; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.Assert; 36 | import org.testng.annotations.Test; 37 | 38 | import jakarta.inject.Inject; 39 | 40 | /** 41 | * @author Mark Struberg 42 | */ 43 | public class CustomConfigSourceTest extends Arquillian { 44 | 45 | private @Inject Config config; 46 | 47 | @Deployment 48 | public static WebArchive deploy() { 49 | JavaArchive testJar = ShrinkWrap 50 | .create(JavaArchive.class, "customConfigSourceTest.jar") 51 | .addClasses(CustomConfigSourceTest.class, CustomDbConfigSource.class, CustomConfigSourceProvider.class) 52 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 53 | .addAsServiceProvider(ConfigSource.class, CustomDbConfigSource.class) 54 | .addAsServiceProvider(ConfigSourceProvider.class, CustomConfigSourceProvider.class) 55 | .as(JavaArchive.class); 56 | 57 | addFile(testJar, "META-INF/microprofile-config.properties"); 58 | 59 | WebArchive war = ShrinkWrap 60 | .create(WebArchive.class, "customConfigSourceTest.war") 61 | .addAsLibrary(testJar); 62 | return war; 63 | } 64 | 65 | @Test 66 | public void testConfigSourceProvider() { 67 | Assert.assertEquals(config.getValue("tck.config.test.customDbConfig.key1", String.class), "valueFromDb1"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/Location.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import java.util.Objects; 23 | 24 | public class Location { 25 | private String road; 26 | private String city; 27 | private String county; 28 | private String postcode; 29 | private String country; 30 | 31 | public Location(String loc) { 32 | String[] parts = loc.split(","); 33 | this.road = parts[0]; 34 | this.city = parts[1]; 35 | this.county = parts[2]; 36 | this.postcode = parts[3]; 37 | this.country = parts[4]; 38 | } 39 | 40 | /** 41 | * @return String return the road 42 | */ 43 | public String getRoad() { 44 | return road; 45 | } 46 | 47 | /** 48 | * @return String return the city 49 | */ 50 | public String getCity() { 51 | return city; 52 | } 53 | 54 | /** 55 | * @return String return the county 56 | */ 57 | public String getCounty() { 58 | return county; 59 | } 60 | 61 | /** 62 | * @return String return the postcode 63 | */ 64 | public String getPostcode() { 65 | return postcode; 66 | } 67 | 68 | /** 69 | * @return String return the country 70 | */ 71 | public String getCountry() { 72 | return country; 73 | } 74 | 75 | @Override 76 | public boolean equals(Object o) { 77 | if (o == this) { 78 | return true; 79 | } 80 | if (!(o instanceof Location)) { 81 | return false; 82 | } 83 | Location location = (Location) o; 84 | return Objects.equals(road, location.road) && Objects.equals(city, location.city) 85 | && Objects.equals(county, location.county) && Objects.equals(postcode, location.postcode) 86 | && Objects.equals(country, location.country); 87 | } 88 | 89 | @Override 90 | public int hashCode() { 91 | return Objects.hash(road, city, county, postcode, country); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/OptionalValuesBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import java.util.Optional; 23 | import java.util.OptionalDouble; 24 | import java.util.OptionalInt; 25 | import java.util.OptionalLong; 26 | 27 | import org.eclipse.microprofile.config.inject.ConfigProperty; 28 | 29 | import jakarta.enterprise.context.Dependent; 30 | import jakarta.inject.Inject; 31 | 32 | /** 33 | * Declare a bean for config property injections. 34 | * 35 | * @author Mark Struberg 36 | * @author Emily Jiang 37 | */ 38 | @Dependent 39 | public class OptionalValuesBean { 40 | @Inject 41 | @ConfigProperty(name = "my.optional.int.property") 42 | private Optional intProperty; 43 | 44 | @Inject 45 | @ConfigProperty(name = "my.notexisting.property") 46 | private Optional notexistingProperty; 47 | 48 | @Inject 49 | @ConfigProperty(name = "my.notexisting.string.property") 50 | private Optional notExistingStringProperty; 51 | 52 | private Optional stringValue; 53 | 54 | @Inject 55 | @ConfigProperty(name = "my.optional.int.property") 56 | private OptionalInt optionalIntProperty; 57 | @Inject 58 | @ConfigProperty(name = "my.notexisting.property") 59 | private OptionalInt optionalNotExistingIntProperty; 60 | 61 | @Inject 62 | @ConfigProperty(name = "my.optional.long.property") 63 | private OptionalLong optionalLongProperty; 64 | @Inject 65 | @ConfigProperty(name = "my.notexisting.property") 66 | private OptionalLong optionalNotExistingLongProperty; 67 | 68 | @Inject 69 | @ConfigProperty(name = "my.optional.double.property") 70 | private OptionalDouble optionalDoubleProperty; 71 | @Inject 72 | @ConfigProperty(name = "my.notexisting.property") 73 | private OptionalDouble optionalNotExistingDoubleProperty; 74 | 75 | @Inject 76 | public void setStringValue(@ConfigProperty(name = "my.optional.string.property") Optional stringValue) { 77 | this.stringValue = stringValue; 78 | } 79 | 80 | public Optional getStringValue() { 81 | return stringValue; 82 | } 83 | 84 | public Optional getIntProperty() { 85 | return intProperty; 86 | } 87 | 88 | public Optional getNotexistingProperty() { 89 | return notexistingProperty; 90 | } 91 | 92 | public Optional getNotExistingStringProperty() { 93 | return notExistingStringProperty; 94 | } 95 | 96 | public OptionalInt getOptionalIntProperty() { 97 | return optionalIntProperty; 98 | } 99 | 100 | public OptionalInt getOptionalNotExistingIntProperty() { 101 | return optionalNotExistingIntProperty; 102 | } 103 | 104 | public OptionalLong getOptionalLongProperty() { 105 | return optionalLongProperty; 106 | } 107 | 108 | public OptionalLong getOptionalNotExistingLongProperty() { 109 | return optionalNotExistingLongProperty; 110 | } 111 | 112 | public OptionalDouble getOptionalDoubleProperty() { 113 | return optionalDoubleProperty; 114 | } 115 | 116 | public OptionalDouble getOptionalNotExistingDoubleProperty() { 117 | return optionalNotExistingDoubleProperty; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/ParseConverterInjection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import java.time.YearMonth; 23 | 24 | import org.eclipse.microprofile.config.inject.ConfigProperty; 25 | 26 | import jakarta.enterprise.context.Dependent; 27 | import jakarta.inject.Inject; 28 | 29 | @Dependent 30 | public class ParseConverterInjection { 31 | private @Inject @ConfigProperty(name = "tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth") YearMonth yearMonth; 32 | 33 | public YearMonth getYearMonth() { 34 | return yearMonth; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/SimpleValuesBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | 24 | import jakarta.enterprise.context.Dependent; 25 | import jakarta.inject.Inject; 26 | 27 | @Dependent 28 | public class SimpleValuesBean { 29 | 30 | @Inject 31 | @ConfigProperty(name = "my.string/property") 32 | private String stringProperty; 33 | 34 | @Inject 35 | @ConfigProperty(name = "my.boolean.property") 36 | private boolean booleanProperty; 37 | 38 | @Inject 39 | @ConfigProperty(name = "my.int/property") 40 | private int intProperty; 41 | 42 | public String getStringProperty() { 43 | return this.stringProperty; 44 | } 45 | 46 | public boolean getBooleanProperty() { 47 | return this.booleanProperty; 48 | } 49 | 50 | public int getIntProperty() { 51 | return this.intProperty; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/WarPropertiesLocationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck; 21 | 22 | import static org.testng.Assert.assertEquals; 23 | 24 | import org.eclipse.microprofile.config.ConfigProvider; 25 | import org.jboss.arquillian.container.test.api.Deployment; 26 | import org.jboss.arquillian.testng.Arquillian; 27 | import org.jboss.shrinkwrap.api.ShrinkWrap; 28 | import org.jboss.shrinkwrap.api.asset.StringAsset; 29 | import org.jboss.shrinkwrap.api.spec.WebArchive; 30 | import org.testng.annotations.Test; 31 | 32 | public class WarPropertiesLocationTest extends Arquillian { 33 | private static final String SOME_KEY = "org.eclipse.microprofile.config.test.internal.somekey"; 34 | 35 | @Deployment 36 | public static WebArchive deploy() { 37 | StringAsset mpConfig = new StringAsset(SOME_KEY + "=someval"); 38 | return ShrinkWrap 39 | .create(WebArchive.class, "configProviderTest.war") 40 | .addClasses(WarPropertiesLocationTest.class) 41 | .addAsWebInfResource(mpConfig, "classes/META-INF/microprofile-config.properties"); 42 | } 43 | 44 | @Test 45 | public void testReadPropertyInWar() { 46 | String value = ConfigProvider.getConfig().getValue(SOME_KEY, String.class); 47 | assertEquals(value, "someval"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/base/AbstractTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.base; 21 | 22 | import org.jboss.arquillian.testng.Arquillian; 23 | import org.jboss.shrinkwrap.api.asset.UrlAsset; 24 | import org.jboss.shrinkwrap.api.container.ResourceContainer; 25 | 26 | /** 27 | * @author Mark Struberg 28 | */ 29 | public class AbstractTest extends Arquillian { 30 | 31 | public static void addFile(ResourceContainer archive, String originalPath) { 32 | archive.addAsResource( 33 | new UrlAsset(Thread.currentThread().getContextClassLoader().getResource("internal/" + originalPath)), 34 | originalPath); 35 | } 36 | 37 | public static void addFile(ResourceContainer archive, String originalFile, String targetFile) { 38 | archive.addAsResource(new UrlAsset(Thread.currentThread().getContextClassLoader().getResource(originalFile)), 39 | targetFile); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/ConfigObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | 24 | import jakarta.enterprise.context.ApplicationScoped; 25 | import jakarta.enterprise.context.Initialized; 26 | import jakarta.enterprise.event.Observes; 27 | 28 | /** 29 | * A bean supporting the {@link MissingValueOnObserverMethodInjectionTest} test that injects a non-existent 30 | * configuration property in a container lifecycle event observer method. 31 | * 32 | * @author Laird Nelson 33 | * 34 | * @see MissingValueOnObserverMethodInjectionTest 35 | */ 36 | @ApplicationScoped 37 | public class ConfigObserver { 38 | 39 | public void onStartup(@Observes @Initialized(ApplicationScoped.class) final Object event, 40 | @ConfigProperty(name = "this.property.does.not.exist") final String nonExistentConfigurationPropertyValue) { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/ConfigOwner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | 24 | import jakarta.enterprise.context.RequestScoped; 25 | import jakarta.inject.Inject; 26 | 27 | /** 28 | * A bean contains a config property injection 29 | * 30 | * @author Mark Struberg 31 | * @author Emily Jiang 32 | */ 33 | @RequestScoped 34 | public class ConfigOwner { 35 | 36 | @Inject 37 | @ConfigProperty(name = "my.long.value") 38 | private Long configValue; 39 | } 40 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/ConfigPropertiesBeanMissingProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperties; 23 | 24 | import jakarta.enterprise.context.Dependent; 25 | 26 | @ConfigProperties(prefix = "customer") 27 | @Dependent 28 | public class ConfigPropertiesBeanMissingProperty { 29 | private String name; 30 | public int age; 31 | public String nationality; // no corresponding config property customer.nationality exists 32 | 33 | /** 34 | * @return String return the name 35 | */ 36 | public String getName() { 37 | return name; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/ConfigPropertiesMissingPropertyInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.ShrinkWrap; 26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 27 | import org.jboss.shrinkwrap.api.asset.StringAsset; 28 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 29 | import org.jboss.shrinkwrap.api.spec.WebArchive; 30 | import org.testng.annotations.Test; 31 | 32 | import jakarta.enterprise.inject.spi.DeploymentException; 33 | 34 | /** 35 | * Verify the support {@code ConfigProperties}. 36 | * 37 | * @author Emily Jiang 38 | */ 39 | public class ConfigPropertiesMissingPropertyInjectionTest extends Arquillian { 40 | 41 | @Deployment 42 | @ShouldThrowException(DeploymentException.class) 43 | public static WebArchive deploy() { 44 | JavaArchive testJar = ShrinkWrap 45 | .create(JavaArchive.class, "ConfigPropertiesTest.jar") 46 | .addClasses(ConfigPropertiesBeanMissingProperty.class) 47 | .addAsManifestResource( 48 | new StringAsset( 49 | "customer.name=Bob\n" + 50 | "customer.age=24\n"), 51 | "microprofile-config.properties") 52 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 53 | .as(JavaArchive.class); 54 | 55 | return ShrinkWrap 56 | .create(WebArchive.class, "ConfigPropertiesTest.war") 57 | .addAsLibrary(testJar); 58 | } 59 | 60 | @Test 61 | public void test() { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/CustomConverterBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | 24 | import jakarta.enterprise.context.RequestScoped; 25 | import jakarta.inject.Inject; 26 | 27 | /** 28 | * A bean contains a config property injection, which converts to CustomType 29 | * 30 | * @author Mark Struberg 31 | * @author Emily Jiang 32 | */ 33 | 34 | public class CustomConverterBean { 35 | 36 | @RequestScoped 37 | public static class ConfigOwner { 38 | 39 | @Inject 40 | @ConfigProperty(name = "my.customtype.value") 41 | private CustomType configValue; 42 | } 43 | 44 | public static class CustomType { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/MissingConverterOnInstanceInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.ShrinkWrap; 26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 27 | import org.jboss.shrinkwrap.api.asset.StringAsset; 28 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 29 | import org.jboss.shrinkwrap.api.spec.WebArchive; 30 | import org.testng.annotations.Test; 31 | 32 | import jakarta.enterprise.inject.spi.DeploymentException; 33 | 34 | /** 35 | * Verify that a Converter exists which can handle the configured string. 36 | * 37 | * @author Mark Struberg 38 | */ 39 | public class MissingConverterOnInstanceInjectionTest extends Arquillian { 40 | 41 | @ShouldThrowException(DeploymentException.class) 42 | @Deployment 43 | public static WebArchive deploy() { 44 | JavaArchive testJar = ShrinkWrap 45 | .create(JavaArchive.class, "missingConverterOnInstanceInjectionTest.jar") 46 | .addClass(CustomConverterBean.class) 47 | .addAsManifestResource(new StringAsset("my.customtype.value=xxxxx"), "microprofile-config.properties") 48 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 49 | .as(JavaArchive.class); 50 | 51 | WebArchive war = ShrinkWrap 52 | .create(WebArchive.class, "missingConverterOnInstanceInjectionTest.war") 53 | .addAsLibrary(testJar); 54 | return war; 55 | } 56 | 57 | @Test 58 | public void test() { 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/MissingValueOnInstanceInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.ShrinkWrap; 26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 27 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 28 | import org.jboss.shrinkwrap.api.spec.WebArchive; 29 | import org.testng.annotations.Test; 30 | 31 | import jakarta.enterprise.inject.spi.DeploymentException; 32 | 33 | /** 34 | * Verify that injectng a native value which is not configured will lead to a deployment error. 35 | * 36 | * @author Mark Struberg 37 | */ 38 | public class MissingValueOnInstanceInjectionTest extends Arquillian { 39 | 40 | @ShouldThrowException(DeploymentException.class) 41 | @Deployment 42 | public static WebArchive deploy() { 43 | JavaArchive testJar = ShrinkWrap 44 | .create(JavaArchive.class, "missingValueOnInstanceInjectionTest.jar") 45 | .addClass(ConfigOwner.class) 46 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 47 | .as(JavaArchive.class); 48 | 49 | WebArchive war = ShrinkWrap 50 | .create(WebArchive.class, "missingValueOnInstanceInjectionTest.war") 51 | .addAsLibrary(testJar); 52 | return war; 53 | } 54 | 55 | @Test 56 | public void test() { 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/MissingValueOnObserverMethodInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.ShrinkWrap; 26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 27 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 28 | import org.jboss.shrinkwrap.api.spec.WebArchive; 29 | import org.testng.annotations.Test; 30 | 31 | import jakarta.enterprise.inject.spi.DeploymentException; 32 | 33 | /** 34 | * A test to verify that a {@link org.eclipse.microprofile.config.inject.ConfigProperty}-annotated injection point in an 35 | * observer method with a payload that is not an instance of {@link java.util.Optional} that does not have a 36 | * corresponding configuration property value set will cause a {@link DeploymentException} to be thrown. 37 | * 38 | * @author Laird Nelson 39 | */ 40 | public class MissingValueOnObserverMethodInjectionTest extends Arquillian { 41 | 42 | @ShouldThrowException(DeploymentException.class) 43 | @Deployment 44 | public static WebArchive deploy() { 45 | JavaArchive testJar = ShrinkWrap 46 | .create(JavaArchive.class, "missingValueOnObserverMethodInjectionTest.jar") 47 | .addClass(ConfigObserver.class) 48 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 49 | .as(JavaArchive.class); 50 | 51 | WebArchive war = ShrinkWrap 52 | .create(WebArchive.class, "missingValueOnObserverMethodInjectionTest.war") 53 | .addAsLibrary(testJar); 54 | return war; 55 | } 56 | 57 | @Test 58 | public void test() { 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/broken/WrongConverterOnInstanceInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.broken; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.ShrinkWrap; 26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 27 | import org.jboss.shrinkwrap.api.asset.StringAsset; 28 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 29 | import org.jboss.shrinkwrap.api.spec.WebArchive; 30 | import org.testng.annotations.Test; 31 | 32 | import jakarta.enterprise.inject.spi.DeploymentException; 33 | 34 | /** 35 | * Verify that injectng a native value also has a valid converter which can handle the configured string. 36 | * 37 | * @author Mark Struberg 38 | */ 39 | public class WrongConverterOnInstanceInjectionTest extends Arquillian { 40 | 41 | @ShouldThrowException(DeploymentException.class) 42 | @Deployment 43 | public static WebArchive deploy() { 44 | JavaArchive testJar = ShrinkWrap 45 | .create(JavaArchive.class, "wrongConverterOnInstanceInjectionTest.jar") 46 | .addClass(ConfigOwner.class) 47 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 48 | .addAsManifestResource(new StringAsset("my.long.value=xxxxx"), "microprofile-config.properties") 49 | .as(JavaArchive.class); 50 | 51 | WebArchive war = ShrinkWrap 52 | .create(WebArchive.class, "wrongConverterOnInstanceInjectionTest.war") 53 | .addAsLibrary(testJar); 54 | return war; 55 | } 56 | 57 | @Test 58 | public void test() { 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/configsources/CustomConfigProfileConfigSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.configsources; 21 | 22 | import static org.eclipse.microprofile.config.Config.PROFILE; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | import org.eclipse.microprofile.config.spi.ConfigSource; 29 | 30 | /** 31 | * @author Emily Jiang 32 | */ 33 | public class CustomConfigProfileConfigSource implements ConfigSource { 34 | 35 | private Map configValues = new HashMap<>(); 36 | 37 | public CustomConfigProfileConfigSource() { 38 | configValues.put(PROFILE, "test"); 39 | configValues.put("%dev.vehicle.name", "bike"); 40 | configValues.put("%prod.vehicle.name", "bus"); 41 | configValues.put("%test.vehicle.name", "van"); 42 | configValues.put("vehicle.name", "car"); 43 | } 44 | 45 | @Override 46 | public int getOrdinal() { 47 | return 500; 48 | } 49 | 50 | @Override 51 | public String getValue(String key) { 52 | return configValues.get(key); 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | return "customConfigProfileSource"; 58 | } 59 | 60 | @Override 61 | public Set getPropertyNames() { 62 | return configValues.keySet(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/configsources/CustomConfigSourceProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.configsources; 21 | 22 | import java.io.IOException; 23 | import java.net.URL; 24 | import java.util.ArrayList; 25 | import java.util.Enumeration; 26 | import java.util.List; 27 | 28 | import org.eclipse.microprofile.config.spi.ConfigSource; 29 | import org.eclipse.microprofile.config.spi.ConfigSourceProvider; 30 | 31 | /** 32 | * @author Mark Struberg 33 | */ 34 | public class CustomConfigSourceProvider implements ConfigSourceProvider { 35 | 36 | @Override 37 | public Iterable getConfigSources(ClassLoader forClassLoader) { 38 | List detectedConfigSources = new ArrayList<>(); 39 | 40 | Enumeration yamlFiles = null; 41 | try { 42 | yamlFiles = forClassLoader.getResources("sampleconfig.yaml"); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | while (yamlFiles.hasMoreElements()) { 47 | detectedConfigSources.add(new SampleYamlConfigSource(yamlFiles.nextElement())); 48 | } 49 | return detectedConfigSources; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/configsources/CustomDbConfigSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.configsources; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | import org.eclipse.microprofile.config.spi.ConfigSource; 27 | 28 | /** 29 | * @author Mark Struberg 30 | */ 31 | public class CustomDbConfigSource implements ConfigSource { 32 | 33 | private Map configValues = new HashMap<>(); 34 | 35 | public CustomDbConfigSource() { 36 | configValues.put("tck.config.test.customDbConfig.key1", "valueFromDb1"); 37 | configValues.put("tck.config.test.customDbConfig.key2", "valueFromDb2"); 38 | configValues.put("tck.config.test.customDbConfig.key3", "big:cheese"); 39 | } 40 | 41 | @Override 42 | public int getOrdinal() { 43 | return 112; 44 | } 45 | @Override 46 | public String getValue(String key) { 47 | return readPropertyFromDb(key); 48 | } 49 | 50 | @Override 51 | public String getName() { 52 | return "customDbConfig"; 53 | } 54 | 55 | private String readPropertyFromDb(String key) { 56 | return configValues.get(key); 57 | } 58 | 59 | @Override 60 | public Set getPropertyNames() { 61 | 62 | return configValues.keySet(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/configsources/DefaultConfigSourceOrdinalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.configsources; 21 | 22 | import org.eclipse.microprofile.config.Config; 23 | import org.jboss.arquillian.container.test.api.Deployment; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.Archive; 26 | import org.jboss.shrinkwrap.api.ShrinkWrap; 27 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 28 | import org.jboss.shrinkwrap.api.asset.StringAsset; 29 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 30 | import org.jboss.shrinkwrap.api.spec.WebArchive; 31 | import org.testng.Assert; 32 | import org.testng.annotations.BeforeClass; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.inject.Inject; 36 | 37 | /** 38 | * 39 | * @author Emily Jiang 40 | */ 41 | public class DefaultConfigSourceOrdinalTest extends Arquillian { 42 | 43 | private @Inject Config config; 44 | 45 | @Deployment 46 | public static Archive deployment() { 47 | JavaArchive testJar = ShrinkWrap 48 | .create(JavaArchive.class, "DefaultConfigSourceOrdinalTest.jar") 49 | .addClasses(DefaultConfigSourceOrdinalTest.class) 50 | .addAsManifestResource( 51 | new StringAsset( 52 | "config_ordinal=200\n" + 53 | "customer_name=Bill\n" + 54 | "customer.hobby=Badminton"), 55 | "microprofile-config.properties") 56 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 57 | .as(JavaArchive.class); 58 | 59 | WebArchive war = ShrinkWrap 60 | .create(WebArchive.class, "DefaultConfigSourceOrdinalTest.war") 61 | .addAsLibrary(testJar); 62 | return war; 63 | } 64 | 65 | @BeforeClass 66 | public void checkSetup() { 67 | // check whether the environment variables were populated by the executor correctly 68 | 69 | if (!"45".equals(System.getenv("config_ordinal"))) { 70 | Assert.fail( 71 | "Before running this test, the environment variable \"config_ordinal\" must be set with the value of 45"); 72 | } 73 | if (!"Bob".equals(System.getenv("customer_name"))) { 74 | Assert.fail( 75 | "Before running this test, the environment variable \"customer_name\" must be set with the value of Bob"); 76 | } 77 | if (!"120".equals(System.getProperty("config_ordinal"))) { 78 | Assert.fail( 79 | "Before running this test, the system property \"config_ordinal\" must be set with the value of 120"); 80 | } 81 | if (!"Tennis".equals(System.getProperty("customer.hobby"))) { 82 | Assert.fail( 83 | "Before running this test, the system property \"customer.hobby\" must be set with the value of Tennis"); 84 | } 85 | } 86 | 87 | @Test 88 | public void testOrdinalForEnv() { 89 | Assert.assertEquals(config.getValue("customer_name", String.class), "Bill"); 90 | Assert.assertEquals(config.getConfigValue("customer_name").getSourceOrdinal(), 200); 91 | } 92 | 93 | @Test 94 | public void testOrdinalForSystemProps() { 95 | Assert.assertEquals(config.getValue("customer.hobby", String.class), "Badminton"); 96 | Assert.assertEquals(config.getConfigValue("customer.hobby").getSourceOrdinal(), 200); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/configsources/SampleYamlConfigSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.configsources; 21 | 22 | import java.net.URL; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | import java.util.Set; 26 | 27 | import org.eclipse.microprofile.config.spi.ConfigSource; 28 | 29 | /** 30 | * @author Mark Struberg 31 | */ 32 | public class SampleYamlConfigSource implements ConfigSource { 33 | private Map config = new HashMap<>(); 34 | 35 | public SampleYamlConfigSource(URL url) { 36 | config.put("tck.config.test.sampleyaml.key1", "yamlvalue1"); 37 | } 38 | 39 | @Override 40 | public int getOrdinal() { 41 | return 110; 42 | } 43 | 44 | @Override 45 | public String getValue(String key) { 46 | return config.get(key); 47 | } 48 | 49 | @Override 50 | public String getName() { 51 | return null; 52 | } 53 | 54 | @Override 55 | public Set getPropertyNames() { 56 | 57 | return config.keySet(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/Donald.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package org.eclipse.microprofile.config.tck.converters; 22 | 23 | /** 24 | * Class, which is converted using a Lambda based converter. 25 | * 26 | * @author Anatole Tresch 27 | */ 28 | public class Donald { 29 | 30 | private String name; 31 | private boolean bool; 32 | 33 | private Donald(String name, boolean bool) { 34 | this.name = name; 35 | this.bool = bool; 36 | } 37 | 38 | /** 39 | * Ensure constructor cannot be auto-detected/auto-constructed. 40 | * 41 | * @param name 42 | * the name, not null 43 | * @return a new instance, never null. 44 | */ 45 | public static Donald iLikeDonald(String name) { 46 | return new Donald(name, true); 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/Duck.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters; 21 | 22 | /** 23 | * @author Mark Struberg 24 | */ 25 | public class Duck { 26 | private final String name; 27 | 28 | public Duck(String name) { 29 | this.name = name; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/DuckConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | /** 25 | * @author Mark Struberg 26 | */ 27 | public class DuckConverter implements Converter { 28 | 29 | @Override 30 | public Duck convert(String value) { 31 | return new Duck(value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/NullConvertersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters; 20 | 21 | import static org.testng.Assert.assertThrows; 22 | 23 | import java.util.NoSuchElementException; 24 | import java.util.OptionalDouble; 25 | import java.util.OptionalInt; 26 | import java.util.OptionalLong; 27 | 28 | import org.eclipse.microprofile.config.Config; 29 | import org.eclipse.microprofile.config.ConfigProvider; 30 | import org.jboss.arquillian.container.test.api.Deployment; 31 | import org.jboss.arquillian.testng.Arquillian; 32 | import org.jboss.shrinkwrap.api.ShrinkWrap; 33 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.annotations.Test; 36 | 37 | public class NullConvertersTest extends Arquillian { 38 | 39 | @Deployment 40 | public static WebArchive deployment() { 41 | return ShrinkWrap 42 | .create(WebArchive.class, "NullConvertersTest.war") 43 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 44 | } 45 | 46 | @Test 47 | public void nulls() { 48 | final Config config = ConfigProvider.getConfig(); 49 | 50 | assertThrows(NullPointerException.class, () -> convertNull(config, Boolean.class)); 51 | assertThrows(NullPointerException.class, () -> convertNull(config, Byte.class)); 52 | assertThrows(NullPointerException.class, () -> convertNull(config, Short.class)); 53 | assertThrows(NullPointerException.class, () -> convertNull(config, Integer.class)); 54 | assertThrows(NullPointerException.class, () -> convertNull(config, Long.class)); 55 | assertThrows(NullPointerException.class, () -> convertNull(config, Float.class)); 56 | assertThrows(NullPointerException.class, () -> convertNull(config, Double.class)); 57 | assertThrows(NullPointerException.class, () -> convertNull(config, Character.class)); 58 | 59 | assertThrows(NullPointerException.class, () -> convertNull(config, OptionalInt.class)); 60 | assertThrows(NullPointerException.class, () -> convertNull(config, OptionalLong.class)); 61 | assertThrows(NullPointerException.class, () -> convertNull(config, OptionalDouble.class)); 62 | } 63 | 64 | private static void convertNull(Config config, Class converterType) { 65 | config.getConverter(converterType) 66 | .map(converter -> converter.convert(null)) 67 | .orElseThrow(NoSuchElementException::new); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/Pizza.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters; 21 | 22 | /** 23 | * @author Emily Jiang 24 | */ 25 | public class Pizza { 26 | private String flavor; 27 | private String size; 28 | 29 | public Pizza(String flavour, String size) { 30 | this.flavor = flavour; 31 | this.size = size; 32 | } 33 | 34 | public String getSize() { 35 | return size; 36 | } 37 | 38 | public String getFlavor() { 39 | return flavor; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * 45 | * @see java.lang.Object#hashCode() 46 | */ 47 | @Override 48 | public int hashCode() { 49 | final int prime = 31; 50 | int result = 1; 51 | result = prime * result + ((flavor == null) ? 0 : flavor.hashCode()); 52 | result = prime * result + ((size == null) ? 0 : size.hashCode()); 53 | return result; 54 | } 55 | 56 | /* 57 | * (non-Javadoc) 58 | * 59 | * @see java.lang.Object#equals(java.lang.Object) 60 | */ 61 | @Override 62 | public boolean equals(Object obj) { 63 | if (this == obj) { 64 | return true; 65 | } 66 | if (obj == null) { 67 | return false; 68 | } 69 | if (getClass() != obj.getClass()) { 70 | return false; 71 | } 72 | 73 | Pizza other = (Pizza) obj; 74 | if (flavor == null) { 75 | if (other.flavor != null) { 76 | return false; 77 | } 78 | } else if (!flavor.equals(other.flavor)) { 79 | return false; 80 | } 81 | if (size == null) { 82 | if (other.size != null) { 83 | return false; 84 | } 85 | } else if (!size.equals(other.size)) { 86 | return false; 87 | } 88 | return true; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/PizzaConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | /** 25 | * @author Emily Jiang 26 | */ 27 | public class PizzaConverter implements Converter { 28 | 29 | @Override 30 | public Pizza convert(String value) { 31 | String[] parts = value.split(":"); 32 | if (parts.length == 2) { 33 | String size = parts[0]; 34 | String flavor = parts[1]; 35 | return new Pizza(flavor, size); 36 | } 37 | 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/UpperCaseDuckConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package org.eclipse.microprofile.config.tck.converters; 22 | 23 | import org.eclipse.microprofile.config.spi.Converter; 24 | 25 | import jakarta.annotation.Priority; 26 | 27 | /** 28 | * Always create a duck with an upper case name 29 | * 30 | * @author Jeff Mesnil 31 | */ 32 | @Priority(101) 33 | public class UpperCaseDuckConverter implements Converter { 34 | @Override 35 | public Duck convert(String value) { 36 | return new Duck(value.toUpperCase()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/convertToNull/ConvertedNullValueBrokenInjectionBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.convertToNull; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | import org.eclipse.microprofile.config.tck.converters.Pizza; 24 | 25 | import jakarta.enterprise.context.ApplicationScoped; 26 | import jakarta.inject.Inject; 27 | 28 | @ApplicationScoped 29 | public class ConvertedNullValueBrokenInjectionBean { 30 | 31 | private @Inject @ConfigProperty(name = "partial.pizza", defaultValue = "medium:chicken") Pizza myPizza; 32 | 33 | public Pizza getPizza() { 34 | return myPizza; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/convertToNull/ConvertedNullValueBrokenInjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.convertToNull; 21 | 22 | import org.eclipse.microprofile.config.Config; 23 | import org.eclipse.microprofile.config.spi.Converter; 24 | import org.eclipse.microprofile.config.tck.converters.Pizza; 25 | import org.eclipse.microprofile.config.tck.converters.PizzaConverter; 26 | import org.jboss.arquillian.container.test.api.Deployment; 27 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.Archive; 30 | import org.jboss.shrinkwrap.api.ShrinkWrap; 31 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 32 | import org.jboss.shrinkwrap.api.asset.StringAsset; 33 | import org.jboss.shrinkwrap.api.spec.WebArchive; 34 | import org.testng.annotations.Test; 35 | 36 | import jakarta.enterprise.inject.spi.DeploymentException; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * This is to test that when a converter returns null for some config value, an exception should be thrown and the 41 | * defaultValue should not be used. 42 | */ 43 | public class ConvertedNullValueBrokenInjectionTest extends Arquillian { 44 | private @Inject Config config; 45 | private @Inject ConvertedNullValueBrokenInjectionBean myBean; 46 | 47 | @Deployment 48 | @ShouldThrowException(DeploymentException.class) 49 | public static Archive deployment() { 50 | return ShrinkWrap.create(WebArchive.class, "ConvertedNullValueBrokenInjectionTest.war") 51 | .addClasses(ConvertedNullValueBrokenInjectionTest.class, Pizza.class, PizzaConverter.class, 52 | ConvertedNullValueBrokenInjectionBean.class) 53 | .addAsResource( 54 | new StringAsset( 55 | "partial.pizza=cheese"), 56 | "META-INF/microprofile-config.properties") 57 | .addAsServiceProvider(Converter.class, PizzaConverter.class) 58 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 59 | 60 | } 61 | 62 | @Test 63 | public void test() { 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/convertToNull/ConvertedNullValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.convertToNull; 21 | 22 | import java.util.NoSuchElementException; 23 | import java.util.Optional; 24 | 25 | import org.eclipse.microprofile.config.Config; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.eclipse.microprofile.config.spi.Converter; 28 | import org.eclipse.microprofile.config.tck.converters.Pizza; 29 | import org.eclipse.microprofile.config.tck.converters.PizzaConverter; 30 | import org.jboss.arquillian.container.test.api.Deployment; 31 | import org.jboss.arquillian.testng.Arquillian; 32 | import org.jboss.shrinkwrap.api.Archive; 33 | import org.jboss.shrinkwrap.api.ShrinkWrap; 34 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 35 | import org.jboss.shrinkwrap.api.asset.StringAsset; 36 | import org.jboss.shrinkwrap.api.spec.WebArchive; 37 | import org.testng.Assert; 38 | import org.testng.annotations.Test; 39 | 40 | import jakarta.enterprise.context.ApplicationScoped; 41 | import jakarta.inject.Inject; 42 | 43 | /** 44 | * This is to test that when a converter returns null for some config value, null will be assigned. This means the 45 | * property still exists but the value is set to null on purpose. 46 | */ 47 | public class ConvertedNullValueTest extends Arquillian { 48 | private @Inject Config config; 49 | private @Inject MyBean myBean; 50 | 51 | @Deployment 52 | public static Archive deployment() { 53 | return ShrinkWrap 54 | .create(WebArchive.class, "ConvertedNullValueTest.war") 55 | .addClasses(ConvertedNullValueTest.class, Pizza.class, PizzaConverter.class, MyBean.class) 56 | .addAsResource( 57 | new StringAsset( 58 | "partial.pizza=cheese"), 59 | "META-INF/microprofile-config.properties") 60 | .addAsServiceProvider(Converter.class, PizzaConverter.class) 61 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 62 | 63 | } 64 | 65 | @Test 66 | public void testDefaultValueNotUsed() { 67 | // The converter returns null as the converter returns null if the property does not contain : 68 | // This will treat as if the property has been removed. The defaultValue will not be used. 69 | Assert.assertNull(myBean.getPizza()); 70 | } 71 | 72 | @Test 73 | public void testGetValue() { 74 | // The converter returns null as the converter returns null if the property does not contain : 75 | // Therefore, it will be treated as non-existence. 76 | Assert.assertThrows(NoSuchElementException.class, () -> config.getValue("partial.pizza", Pizza.class)); 77 | } 78 | 79 | @Test 80 | public void testGetOptionalValue() { 81 | // The converter returns null as the converter returns null if the property does not contain : 82 | // Therefore, it will be treated as non-existence. 83 | Assert.assertFalse(config.getOptionalValue("partial.pizza", Pizza.class).isPresent()); 84 | } 85 | 86 | @ApplicationScoped 87 | public static class MyBean { 88 | 89 | private @Inject @ConfigProperty(name = "partial.pizza", defaultValue = "medium:chicken") Optional myPizza; 90 | 91 | public Pizza getPizza() { 92 | return myPizza.isPresent() ? myPizza.get() : null; 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/custom/BooleanConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.custom; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | import jakarta.annotation.Priority; 25 | 26 | @Priority(101) 27 | public class BooleanConverter implements Converter { 28 | @Override 29 | public Boolean convert(final String value) { 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/custom/CharacterConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.custom; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | import jakarta.annotation.Priority; 25 | 26 | @Priority(101) 27 | public class CharacterConverter implements Converter { 28 | @Override 29 | public Character convert(final String value) { 30 | return 'r'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/custom/DoubleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.custom; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | import jakarta.annotation.Priority; 25 | 26 | @Priority(101) 27 | public class DoubleConverter implements Converter { 28 | @Override 29 | public Double convert(final String value) { 30 | return 999.9D; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/custom/IntegerConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.custom; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | import jakarta.annotation.Priority; 25 | 26 | @Priority(101) 27 | public class IntegerConverter implements Converter { 28 | @Override 29 | public Integer convert(final String value) { 30 | return 999; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/custom/LongConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.converters.custom; 21 | 22 | import org.eclipse.microprofile.config.spi.Converter; 23 | 24 | import jakarta.annotation.Priority; 25 | 26 | @Priority(101) 27 | public class LongConverter implements Converter { 28 | @Override 29 | public Long convert(final String value) { 30 | return 999L; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestSequenceOfBeforeValueOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a of(String) and valueOf(String) method. The method of() should be used instead of valueOf(). 25 | * 26 | * @author Emily Jiang 27 | */ 28 | public class ConvTestSequenceOfBeforeValueOf { 29 | private String val; 30 | 31 | public static ConvTestSequenceOfBeforeValueOf of(String val) { 32 | ConvTestSequenceOfBeforeValueOf o = new ConvTestSequenceOfBeforeValueOf(); 33 | o.val = val.toString(); 34 | return o; 35 | } 36 | 37 | public static ConvTestSequenceOfBeforeValueOf valueOf(String val) { 38 | ConvTestSequenceOfBeforeValueOf o = new ConvTestSequenceOfBeforeValueOf(); 39 | o.val = "valueOf"; 40 | return o; 41 | } 42 | 43 | public String getVal() { 44 | return val; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestSequenceParseBeforeConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a parse(CharSequence) and Constructor(String) method. The method parse(CharSequence) should be 25 | * used instead of constructor(String). 26 | * 27 | * @author Emily Jiang 28 | */ 29 | public class ConvTestSequenceParseBeforeConstructor { 30 | private String val; 31 | 32 | public static ConvTestSequenceParseBeforeConstructor parse(CharSequence val) { 33 | ConvTestSequenceParseBeforeConstructor o = new ConvTestSequenceParseBeforeConstructor(); 34 | o.val = val.toString(); 35 | return o; 36 | } 37 | 38 | ConvTestSequenceParseBeforeConstructor() { 39 | } 40 | 41 | public ConvTestSequenceParseBeforeConstructor(String val) { 42 | this.val = "constructor"; 43 | } 44 | 45 | public String getVal() { 46 | return val; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestSequenceValueOfBeforeParse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a parse(CharSequence) and valueOf(String) method. The method valueOf(String) should be used 25 | * instead of the parse(Charsequence) method. 26 | * 27 | * @author Emily Jiang 28 | */ 29 | public class ConvTestSequenceValueOfBeforeParse { 30 | private String val; 31 | 32 | public static ConvTestSequenceValueOfBeforeParse parse(CharSequence val) { 33 | ConvTestSequenceValueOfBeforeParse o = new ConvTestSequenceValueOfBeforeParse(); 34 | o.val = "parse"; 35 | return o; 36 | } 37 | 38 | public static ConvTestSequenceValueOfBeforeParse valueOf(String val) { 39 | ConvTestSequenceValueOfBeforeParse o = new ConvTestSequenceValueOfBeforeParse(); 40 | o.val = val; 41 | return o; 42 | } 43 | 44 | public String getVal() { 45 | return val; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestTypeWCharSequenceParse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 20162017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a parse(CharSequence) constructor 25 | * 26 | * @author Mark Struberg 27 | */ 28 | 29 | public class ConvTestTypeWCharSequenceParse { 30 | private String val; 31 | 32 | public static ConvTestTypeWCharSequenceParse parse(CharSequence val) { 33 | ConvTestTypeWCharSequenceParse o = new ConvTestTypeWCharSequenceParse(); 34 | o.val = val.toString(); 35 | return o; 36 | } 37 | 38 | public String getVal() { 39 | return val; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestTypeWStringCt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a String param constructor 25 | * 26 | * @author Mark Struberg 27 | */ 28 | public class ConvTestTypeWStringCt { 29 | private final String val; 30 | 31 | public ConvTestTypeWStringCt(String val) { 32 | this.val = val; 33 | } 34 | 35 | public String getVal() { 36 | return val; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestTypeWStringOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a of(String) method 25 | * 26 | * @author Emily Jiang 27 | */ 28 | public class ConvTestTypeWStringOf { 29 | private String val; 30 | 31 | public static ConvTestTypeWStringOf of(String val) { 32 | ConvTestTypeWStringOf o = new ConvTestTypeWStringOf(); 33 | o.val = val; 34 | return o; 35 | } 36 | 37 | public String getVal() { 38 | return val; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/ConvTestTypeWStringValueOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Part of the implicit Converter test. 23 | * 24 | * Sample class which has a valueOf(String) method 25 | * 26 | * @author Mark Struberg 27 | */ 28 | public class ConvTestTypeWStringValueOf { 29 | private String val; 30 | 31 | public static ConvTestTypeWStringValueOf valueOf(String val) { 32 | ConvTestTypeWStringValueOf o = new ConvTestTypeWStringValueOf(); 33 | o.val = val; 34 | return o; 35 | } 36 | 37 | public String getVal() { 38 | return val; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/converters/implicit/SomeEnumToConvert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.converters.implicit; 20 | 21 | /** 22 | * Sample enum to test implicit Converter Rules 23 | * 24 | * @author Mark Struberg 25 | */ 26 | public enum SomeEnumToConvert { 27 | FOO, BAR, BAZ 28 | } 29 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/emptyvalue/EmptyValuesBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.emptyvalue; 21 | 22 | import org.eclipse.microprofile.config.inject.ConfigProperty; 23 | 24 | import jakarta.enterprise.context.ApplicationScoped; 25 | import jakarta.inject.Inject; 26 | 27 | @ApplicationScoped 28 | public class EmptyValuesBean { 29 | @Inject 30 | @ConfigProperty(name = "my.unset.property", defaultValue = "") 31 | private String stringValue; 32 | 33 | public String getStringValue() { 34 | return stringValue; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/emptyvalue/EmptyValuesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | package org.eclipse.microprofile.config.tck.emptyvalue; 21 | 22 | import org.jboss.arquillian.container.test.api.Deployment; 23 | import org.jboss.arquillian.container.test.api.ShouldThrowException; 24 | import org.jboss.arquillian.testng.Arquillian; 25 | import org.jboss.shrinkwrap.api.Archive; 26 | import org.jboss.shrinkwrap.api.ShrinkWrap; 27 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 28 | import org.jboss.shrinkwrap.api.asset.StringAsset; 29 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 30 | import org.jboss.shrinkwrap.api.spec.WebArchive; 31 | import org.testng.annotations.Test; 32 | 33 | import jakarta.enterprise.inject.spi.DeploymentException; 34 | import jakarta.inject.Inject; 35 | 36 | public class EmptyValuesTest extends Arquillian { 37 | 38 | private static final String EMPTY_PROPERTY = "my.empty.property"; 39 | private static final String PROP_FILE_EMPTY_PROPERTY = "my.empty.property.in.config.file"; 40 | public static final StringAsset EMPTY_STRING_ASSET = new StringAsset(PROP_FILE_EMPTY_PROPERTY + "="); 41 | 42 | @Deployment 43 | @ShouldThrowException(DeploymentException.class) 44 | public static Archive deployment() { 45 | JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "emptyValues.jar") 46 | .addClasses(EmptyValuesTest.class, EmptyValuesBean.class) 47 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") 48 | .addAsManifestResource(EMPTY_STRING_ASSET, "microprofile-config.properties"); 49 | 50 | return ShrinkWrap.create(WebArchive.class) 51 | .addAsLibrary(jar) 52 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 53 | } 54 | 55 | @Inject 56 | private EmptyValuesBean emptyValuesBean; 57 | 58 | @Test 59 | public void test() { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/ConfigPropertyFileProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | import static org.testng.Assert.assertEquals; 25 | import static org.testng.Assert.assertFalse; 26 | 27 | import org.eclipse.microprofile.config.ConfigProvider; 28 | import org.eclipse.microprofile.config.inject.ConfigProperty; 29 | import org.jboss.arquillian.container.test.api.Deployment; 30 | import org.jboss.arquillian.testng.Arquillian; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.asset.StringAsset; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.annotations.Test; 36 | 37 | import jakarta.enterprise.context.Dependent; 38 | import jakarta.enterprise.inject.spi.CDI; 39 | import jakarta.inject.Inject; 40 | 41 | /** 42 | * Test cases for Config profile 43 | * 44 | * @author Emily Jiang 45 | */ 46 | public class ConfigPropertyFileProfileTest extends Arquillian { 47 | @Deployment 48 | public static WebArchive deployment() { 49 | 50 | WebArchive war = ShrinkWrap 51 | .create(WebArchive.class, "ConfigPropertyFileProfileTest.war") 52 | .addClasses(ConfigPropertyFileProfileTest.class, ProfilePropertyBean.class) 53 | .addAsResource( 54 | new StringAsset( 55 | "mp.config.profile=dev\n" + 56 | "vehicle.name=car\n" + 57 | "vehicle.colour=red"), 58 | "META-INF/microprofile-config.properties") 59 | .addAsResource(new StringAsset( 60 | "vehicle.name=bike\n" + 61 | "vehicle.owner=Bob"), 62 | "META-INF/microprofile-config-dev.properties") 63 | .addAsResource(new StringAsset( 64 | "vehicle.name=bike\n" + 65 | "vehicle.age=5"), 66 | "META-INF/microprofile-config-prod.properties") 67 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 68 | 69 | return war; 70 | } 71 | 72 | /** 73 | * Check both the file microprofile-config.properties and microprofile-config-dev.properties are loaded as config 74 | * sources but the file microprofile-config-prod.properties is ignored. 75 | */ 76 | @Test 77 | public void testConfigProfileWithDev() { 78 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 79 | assertThat(bean.getName(), is(equalTo("bike"))); 80 | assertThat(bean.getColour(), is(equalTo("red"))); 81 | assertThat(bean.getOwner(), is(equalTo("Bob"))); 82 | assertEquals(bean.getVehicleAge(), 10); 83 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("bike"))); 84 | assertThat(ConfigProvider.getConfig().getValue("vehicle.colour", String.class), is(equalTo("red"))); 85 | assertThat(ConfigProvider.getConfig().getValue("vehicle.owner", String.class), is(equalTo("Bob"))); 86 | assertFalse(ConfigProvider.getConfig().getOptionalValue("vehicle.age", Integer.class).isPresent()); 87 | } 88 | 89 | @Dependent 90 | public static class ProfilePropertyBean { 91 | @Inject 92 | @ConfigProperty(name = "vehicle.name") 93 | private String name; 94 | 95 | @Inject 96 | @ConfigProperty(name = "vehicle.age", defaultValue = "10") 97 | private int age; 98 | 99 | @Inject 100 | @ConfigProperty(name = "vehicle.colour", defaultValue = "black") 101 | private String colour; 102 | 103 | @Inject 104 | @ConfigProperty(name = "vehicle.owner", defaultValue = "Jane") 105 | private String owner; 106 | 107 | public String getName() { 108 | return name; 109 | } 110 | 111 | public int getVehicleAge() { 112 | return age; 113 | } 114 | 115 | public String getColour() { 116 | return colour; 117 | } 118 | 119 | public String getOwner() { 120 | return owner; 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/DevConfigProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.ShrinkWrap; 30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 31 | import org.jboss.shrinkwrap.api.asset.StringAsset; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.enterprise.context.Dependent; 36 | import jakarta.enterprise.inject.spi.CDI; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test cases for Config profile 41 | * 42 | * @author Emily Jiang 43 | */ 44 | public class DevConfigProfileTest extends Arquillian { 45 | @Deployment 46 | public static WebArchive deployment() { 47 | WebArchive war = ShrinkWrap 48 | .create(WebArchive.class, "DevConfigProfileTest.war") 49 | .addClasses(DevConfigProfileTest.class, ProfilePropertyBean.class) 50 | .addAsResource( 51 | new StringAsset( 52 | "mp.config.profile=dev\n" + 53 | "%dev.vehicle.name=bike\n" + 54 | "%prod.vehicle.name=bus\n" + 55 | "%test.vehicle.name=van\n" + 56 | "vehicle.name=car"), 57 | "META-INF/microprofile-config.properties") 58 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 59 | 60 | return war; 61 | } 62 | 63 | @Test 64 | public void testConfigProfileWithDev() { 65 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 66 | assertThat(bean.getConfigProperty(), is(equalTo("bike"))); 67 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("bike"))); 68 | } 69 | 70 | @Dependent 71 | public static class ProfilePropertyBean { 72 | @Inject 73 | @ConfigProperty(name = "vehicle.name") 74 | private String vehicleName; 75 | public String getConfigProperty() { 76 | return vehicleName; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/InvalidConfigProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.ShrinkWrap; 30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 31 | import org.jboss.shrinkwrap.api.asset.StringAsset; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.enterprise.context.Dependent; 36 | import jakarta.enterprise.inject.spi.CDI; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test cases for Config profile 41 | * 42 | * @author Emily Jiang 43 | */ 44 | public class InvalidConfigProfileTest extends Arquillian { 45 | @Deployment 46 | public static WebArchive deployment() { 47 | 48 | WebArchive war = ShrinkWrap 49 | .create(WebArchive.class, "InvalidConfigProfileTest.war") 50 | .addClasses(InvalidConfigProfileTest.class, ProfilePropertyBean.class) 51 | .addAsResource( 52 | new StringAsset( 53 | "mp.config.profile=invalid\n" + 54 | "%dev.vehicle.name=bike\n" + 55 | "%prod.vehicle.name=bus\n" + 56 | "%test.vehicle.name=van\n" + 57 | "vehicle.name=car"), 58 | "META-INF/microprofile-config.properties") 59 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 60 | 61 | return war; 62 | } 63 | 64 | @Test 65 | public void testConfigProfileWithDev() { 66 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 67 | assertThat(bean.getConfigProperty(), is(equalTo("car"))); 68 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("car"))); 69 | } 70 | 71 | @Dependent 72 | public static class ProfilePropertyBean { 73 | @Inject 74 | @ConfigProperty(name = "vehicle.name") 75 | private String vehicleName; 76 | public String getConfigProperty() { 77 | return vehicleName; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/OverrideConfigProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.ShrinkWrap; 30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 31 | import org.jboss.shrinkwrap.api.asset.StringAsset; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.enterprise.context.Dependent; 36 | import jakarta.enterprise.inject.spi.CDI; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test cases for Config profile 41 | * 42 | * @author Oliver Bertuch 43 | */ 44 | public class OverrideConfigProfileTest extends Arquillian { 45 | @Deployment 46 | public static WebArchive deployment() { 47 | WebArchive war = ShrinkWrap 48 | .create(WebArchive.class, "OverrideConfigProfileTest.war") 49 | .addClasses(OverrideConfigProfileTest.class, ProfilePropertyBean.class) 50 | .addAsResource( 51 | new StringAsset( 52 | "mp.config.profile=dev\n" + 53 | "%dev." + PROPERTY + "=foo\n" + 54 | PROPERTY + "=bar\n"), 55 | "META-INF/microprofile-config.properties") 56 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 57 | 58 | return war; 59 | } 60 | 61 | private static final String PROPERTY = "mp.tck.prop.dummy"; 62 | private static final String EXPECTED = "dummy"; 63 | 64 | /** 65 | * This test relies on the system property "mp.tck.prop.dummy" being set to "dummy" as described in the TCK README 66 | * as a requirement for runners. System properties are per the TCK requirements at ordinal 120, so shall override 67 | * the given properties in the microprofile-config.properties file (ordinal 100) included in the WAR above. 68 | */ 69 | @Test 70 | public void testConfigProfileWithDevAndOverride() { 71 | assertThat(System.getProperty(PROPERTY), is(equalTo(EXPECTED))); 72 | 73 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 74 | assertThat(bean.getConfigProperty(), is(equalTo(EXPECTED))); 75 | 76 | assertThat(ConfigProvider.getConfig().getValue(PROPERTY, String.class), is(equalTo(EXPECTED))); 77 | } 78 | 79 | @Dependent 80 | public static class ProfilePropertyBean { 81 | @Inject 82 | @ConfigProperty(name = PROPERTY) 83 | private String stringProperty; 84 | public String getConfigProperty() { 85 | return stringProperty; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/ProdProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.ShrinkWrap; 30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 31 | import org.jboss.shrinkwrap.api.asset.StringAsset; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.enterprise.context.Dependent; 36 | import jakarta.enterprise.inject.spi.CDI; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test cases for Config profile 41 | * 42 | * @author Emily Jiang 43 | */ 44 | public class ProdProfileTest extends Arquillian { 45 | @Deployment 46 | public static WebArchive deployment() { 47 | WebArchive war = ShrinkWrap 48 | .create(WebArchive.class, "ProdProfileTest.war") 49 | .addClasses(ProdProfileTest.class, ProfilePropertyBean.class) 50 | .addAsResource( 51 | new StringAsset( 52 | "mp.config.profile=prod\n" + 53 | "%dev.vehicle.name=bike\n" + 54 | "%prod.vehicle.name=bus\n" + 55 | "%test.vehicle.name=van\n" + 56 | "vehicle.name=car"), 57 | "META-INF/microprofile-config.properties") 58 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 59 | 60 | return war; 61 | } 62 | 63 | @Test 64 | public void testConfigProfileWithDev() { 65 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 66 | assertThat(bean.getConfigProperty(), is(equalTo("bus"))); 67 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("bus"))); 68 | } 69 | 70 | @Dependent 71 | public static class ProfilePropertyBean { 72 | @Inject 73 | @ConfigProperty(name = "vehicle.name") 74 | private String vehicleName; 75 | public String getConfigProperty() { 76 | return vehicleName; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/TestConfigProfileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.jboss.arquillian.container.test.api.Deployment; 28 | import org.jboss.arquillian.testng.Arquillian; 29 | import org.jboss.shrinkwrap.api.ShrinkWrap; 30 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 31 | import org.jboss.shrinkwrap.api.asset.StringAsset; 32 | import org.jboss.shrinkwrap.api.spec.WebArchive; 33 | import org.testng.annotations.Test; 34 | 35 | import jakarta.enterprise.context.Dependent; 36 | import jakarta.enterprise.inject.spi.CDI; 37 | import jakarta.inject.Inject; 38 | 39 | /** 40 | * Test cases for Config profile 41 | * 42 | * @author Emily Jiang 43 | */ 44 | public class TestConfigProfileTest extends Arquillian { 45 | @Deployment 46 | public static WebArchive deployment() { 47 | WebArchive war = ShrinkWrap 48 | .create(WebArchive.class, "TestConfigProfileTest.war") 49 | .addClasses(TestConfigProfileTest.class, ProfilePropertyBean.class) 50 | .addAsResource( 51 | new StringAsset( 52 | "mp.config.profile=test\n" + 53 | "%dev.vehicle.name=bike\n" + 54 | "%prod.vehicle.name=bus\n" + 55 | "%test.vehicle.name=van\n" + 56 | "vehicle.name=car"), 57 | "META-INF/microprofile-config.properties") 58 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 59 | return war; 60 | } 61 | 62 | @Test 63 | public void testConfigProfileWithDev() { 64 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 65 | assertThat(bean.getConfigProperty(), is(equalTo("van"))); 66 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("van"))); 67 | } 68 | 69 | @Dependent 70 | public static class ProfilePropertyBean { 71 | @Inject 72 | @ConfigProperty(name = "vehicle.name") 73 | private String vehicleName; 74 | public String getConfigProperty() { 75 | return vehicleName; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/profile/TestCustomConfigProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | package org.eclipse.microprofile.config.tck.profile; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | 25 | import org.eclipse.microprofile.config.ConfigProvider; 26 | import org.eclipse.microprofile.config.inject.ConfigProperty; 27 | import org.eclipse.microprofile.config.spi.ConfigSource; 28 | import org.eclipse.microprofile.config.tck.configsources.CustomConfigProfileConfigSource; 29 | import org.jboss.arquillian.container.test.api.Deployment; 30 | import org.jboss.arquillian.testng.Arquillian; 31 | import org.jboss.shrinkwrap.api.ShrinkWrap; 32 | import org.jboss.shrinkwrap.api.asset.EmptyAsset; 33 | import org.jboss.shrinkwrap.api.asset.StringAsset; 34 | import org.jboss.shrinkwrap.api.spec.WebArchive; 35 | import org.testng.annotations.Test; 36 | 37 | import jakarta.enterprise.context.Dependent; 38 | import jakarta.enterprise.inject.spi.CDI; 39 | import jakarta.inject.Inject; 40 | 41 | /** 42 | * Test cases for Config profile 43 | * 44 | * @author Emily Jiang 45 | */ 46 | public class TestCustomConfigProfile extends Arquillian { 47 | @Deployment 48 | public static WebArchive deployment() { 49 | WebArchive war = ShrinkWrap 50 | .create(WebArchive.class, "TestConfigProfileTest.war") 51 | .addClasses(TestCustomConfigProfile.class, ProfilePropertyBean.class, 52 | CustomConfigProfileConfigSource.class) 53 | .addAsServiceProvider(ConfigSource.class, CustomConfigProfileConfigSource.class) 54 | .addAsResource( 55 | new StringAsset( 56 | "mp.config.profile=prod\n" + 57 | "%dev.vehicle.name=bus\n" + 58 | "%prod.vehicle.name=bike\n" + 59 | "%test.vehicle.name=coach\n" + 60 | "vehicle.name=car"), 61 | "META-INF/microprofile-config.properties") 62 | .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); 63 | return war; 64 | } 65 | 66 | @Test 67 | public void testConfigProfileWithDev() { 68 | ProfilePropertyBean bean = CDI.current().select(ProfilePropertyBean.class).get(); 69 | assertThat(bean.getConfigProperty(), is(equalTo("van"))); 70 | assertThat(ConfigProvider.getConfig().getValue("vehicle.name", String.class), is(equalTo("van"))); 71 | } 72 | 73 | @Dependent 74 | public static class ProfilePropertyBean { 75 | @Inject 76 | @ConfigProperty(name = "vehicle.name") 77 | private String vehicleName; 78 | public String getConfigProperty() { 79 | return vehicleName; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/util/AdditionalAssertions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck.util; 21 | 22 | import java.net.MalformedURLException; 23 | import java.net.URISyntaxException; 24 | import java.net.URL; 25 | import java.util.Arrays; 26 | import java.util.Iterator; 27 | import java.util.List; 28 | import java.util.Set; 29 | import java.util.stream.IntStream; 30 | 31 | import org.testng.Assert; 32 | 33 | /** 34 | * @author Emily Jiang 35 | * @author Joseph Cass 36 | */ 37 | public final class AdditionalAssertions { 38 | 39 | private AdditionalAssertions() { 40 | // utility class 41 | } 42 | 43 | /** 44 | * Use URI.equals() since URL.equals() performs DNS resolution which is undesired. See #549 45 | * 46 | * @throws URISyntaxException 47 | * if either URL is not formatted correctly 48 | */ 49 | public static boolean urlEquals(URL expected, URL actual) throws URISyntaxException { 50 | return (expected.toURI().equals(actual.toURI())); 51 | } 52 | 53 | public static void assertURLArrayEquals(URL[] value, URL[] expectedValue) throws MalformedURLException { 54 | assertURLListEquals(Arrays.asList(value), Arrays.asList(expectedValue)); 55 | } 56 | 57 | public static void assertURLListEquals(List value, List expectedValue) throws MalformedURLException { 58 | 59 | Assert.assertTrue(IntStream.range(0, expectedValue.size()).allMatch(i -> { 60 | try { 61 | return urlEquals(expectedValue.get(i), value.get(i)); 62 | } catch (URISyntaxException e) { 63 | e.printStackTrace(); 64 | } 65 | return false; 66 | })); 67 | } 68 | 69 | public static void assertURLSetEquals(Set valueSet, Set expectedURLSet) 70 | throws MalformedURLException, URISyntaxException { 71 | 72 | Assert.assertTrue(valueSet.size() == expectedURLSet.size()); 73 | 74 | Iterator it = valueSet.iterator(); 75 | boolean isEquals = true; 76 | while (it.hasNext()) { 77 | boolean found = false; 78 | URL url = it.next(); 79 | for (URL thisURL : expectedURLSet) { 80 | if (urlEquals(thisURL, url)) { 81 | found = true; 82 | break; 83 | } 84 | } 85 | if (!found) { 86 | isEquals = false; 87 | break; 88 | } 89 | } 90 | Assert.assertTrue(isEquals); 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /tck/src/main/java/org/eclipse/microprofile/config/tck/util/AdditionalMatchers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information regarding copyright ownership. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * You may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.eclipse.microprofile.config.tck.util; 21 | 22 | import static org.hamcrest.Matchers.closeTo; 23 | 24 | import org.hamcrest.BaseMatcher; 25 | import org.hamcrest.Description; 26 | import org.hamcrest.Matcher; 27 | 28 | /** 29 | * 30 | * @author Ondrej Mihalyi 31 | */ 32 | public final class AdditionalMatchers { 33 | 34 | private AdditionalMatchers() { 35 | // utility class 36 | } 37 | 38 | public static Matcher floatCloseTo(float value, float range) { 39 | return new BaseMatcher() { 40 | 41 | private Matcher doubleMatcher = null; 42 | 43 | @Override 44 | public boolean matches(Object item) { 45 | if (item instanceof Float) { 46 | return (doubleMatcher = closeTo(value, range)).matches(((Float) item).doubleValue()); 47 | } else { 48 | return (doubleMatcher = closeTo(value, range)).matches(item); 49 | } 50 | } 51 | 52 | @Override 53 | public void describeTo(Description description) { 54 | doubleMatcher.describeTo(description); 55 | } 56 | 57 | @Override 58 | public void describeMismatch(Object item, Description mismatchDescription) { 59 | doubleMatcher.describeMismatch(item, mismatchDescription); 60 | } 61 | }; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /tck/src/main/resources/META-INF/NOTICE: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to section 4(d) of the Apache License, == 3 | == Version 2.0, in this case for Microprofile Config == 4 | ========================================================================= 5 | 6 | This product includes software developed at 7 | The Apache Software Foundation (http://www.apache.org/). 8 | 9 | SPDXVersion: SPDX-2.1 10 | PackageName: Eclipse Microprofile 11 | PackageHomePage: http://www.eclipse.org/microprofile 12 | PackageLicenseDeclared: Apache-2.0 13 | 14 | PackageCopyrightText: 15 | Mark Struberg struberg@apache.org, 16 | Emily Jiang emijiang@uk.ibm.com, 17 | Ondrej Mihalyi ondrej.mihalyi@gmail.com 18 | 19 | -------------------------------------------------------------------------------- /tck/src/main/resources/META-INF/tck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microprofile/microprofile-config/8e5f457bf1a16ff631f4ced0486e7a50e53247a9/tck/src/main/resources/META-INF/tck -------------------------------------------------------------------------------- /tck/src/main/resources/internal/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | # 4 | # See the NOTICES file(s) distributed with this work for additional 5 | # information regarding copyright ownership. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | org.eclipse.microprofile.config.tck.configsources.CustomDbConfigSource 22 | -------------------------------------------------------------------------------- /tck/src/main/resources/internal/sampleconfig.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016-2017 Contributors to the Eclipse Foundation 3 | # 4 | # See the NOTICES file(s) distributed with this work for additional 5 | # information regarding copyright ownership. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # just needed as a trigger for the ConfigSource pickup. 21 | # Content is hardcoded in SampleYamlConfigSource 22 | --------------------------------------------------------------------------------