forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Ability to use HelidonTest in a meta-annotation helidon-io#4918
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
- Loading branch information
Showing
4 changed files
with
288 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestMetaAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.microprofile.tests.testing.junit5; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import io.helidon.microprofile.testing.junit5.AddBean; | ||
import io.helidon.microprofile.testing.junit5.AddConfig; | ||
import io.helidon.microprofile.testing.junit5.AddConfigBlock; | ||
import io.helidon.microprofile.testing.junit5.Configuration; | ||
import io.helidon.microprofile.testing.junit5.HelidonTest; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@TestMetaAnnotation.MetaAnnotation | ||
// @HelidonTest is still mandatory in the test and it has no effect in the MetaAnnotation | ||
@HelidonTest | ||
class TestMetaAnnotation { | ||
|
||
@Inject | ||
MyBean bean; | ||
|
||
@Inject | ||
@ConfigProperty(name = "some.key1") | ||
private String value1; | ||
|
||
@Inject | ||
@ConfigProperty(name = "some.key2") | ||
private String value2; | ||
|
||
@Inject | ||
@ConfigProperty(name = "some.key") | ||
private String someKey; | ||
|
||
@Inject | ||
@ConfigProperty(name = "another.key") | ||
private String anotherKey; | ||
|
||
@Inject | ||
@ConfigProperty(name = "second-key") | ||
private String anotherValue; | ||
|
||
@Test | ||
void testIt() { | ||
assertThat(bean.hello(), is("hello")); | ||
assertThat(value1, is("some.value1")); | ||
assertThat(value2, is("some.value2")); | ||
assertThat(someKey, is("some.value")); | ||
assertThat(anotherKey, is("another.value")); | ||
assertThat(anotherValue, is("test-custom-config-second-value")); | ||
} | ||
|
||
@AddBean(MyBean.class) | ||
@AddConfigBlock(""" | ||
some.key1=some.value1 | ||
some.key2=some.value2 | ||
""") | ||
@AddConfig(key = "second-key", value = "test-custom-config-second-value") | ||
@Configuration(configSources = {"testConfigSources.properties", "testConfigSources.yaml"}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
static @interface MetaAnnotation { | ||
} | ||
|
||
static class MyBean { | ||
|
||
String hello() { | ||
return "hello"; | ||
} | ||
} | ||
} |
Oops, something went wrong.