Skip to content

Commit 62c5508

Browse files
authored
Merge pull request #423 from ljnelson/tck-additions
Added a test to the TCK to ensure observer method injection points are also validated
2 parents dee6008 + a7eff20 commit 62c5508

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 javax.enterprise.context.ApplicationScoped;
23+
import javax.enterprise.context.Initialized;
24+
import javax.enterprise.event.Observes;
25+
26+
import org.eclipse.microprofile.config.inject.ConfigProperty;
27+
28+
/**
29+
* A bean supporting the {@link
30+
* MissingValueOnObserverMethodInjectionTest} test that injects a
31+
* non-existent configuration property in a container lifecycle event
32+
* observer method.
33+
*
34+
* @author <a href="https://about.me/lairdnelson"
35+
* target="_parent">Laird Nelson</a>
36+
*
37+
* @see MissingValueOnObserverMethodInjectionTest
38+
*/
39+
@ApplicationScoped
40+
final class ConfigObserver {
41+
42+
private ConfigObserver() {
43+
super();
44+
}
45+
46+
private static final void onStartup(@Observes @Initialized(ApplicationScoped.class)
47+
final Object event,
48+
@ConfigProperty(name = "this.property.does.not.exist")
49+
final String nonExistentConfigurationPropertyValue) {
50+
}
51+
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 javax.enterprise.inject.spi.DeploymentException;
23+
24+
import org.jboss.arquillian.container.test.api.Deployment;
25+
import org.jboss.arquillian.container.test.api.ShouldThrowException;
26+
import org.jboss.arquillian.testng.Arquillian;
27+
import org.jboss.shrinkwrap.api.ShrinkWrap;
28+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
29+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
30+
import org.jboss.shrinkwrap.api.spec.WebArchive;
31+
import org.testng.annotations.Test;
32+
33+
/**
34+
* A test to verify that a {@link
35+
* org.eclipse.microprofile.config.inject.ConfigProperty}-annotated
36+
* injection point in an observer method with a payload that is not an
37+
* instance of {@link java.util.Optional} that does not have a
38+
* corresponding configuration property value set will cause a {@link
39+
* DeploymentException} to be thrown.
40+
*
41+
* @author <a href="https://about.me/lairdnelson"
42+
* target="_parent">Laird Nelson</a>
43+
*/
44+
public class MissingValueOnObserverMethodInjectionTest extends Arquillian {
45+
46+
@ShouldThrowException(DeploymentException.class)
47+
@Deployment
48+
public static WebArchive deploy() {
49+
JavaArchive testJar = ShrinkWrap
50+
.create(JavaArchive.class, "missingValueOnObserverMethodInjectionTest.jar")
51+
.addClass(ConfigObserver.class)
52+
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
53+
.as(JavaArchive.class);
54+
55+
WebArchive war = ShrinkWrap
56+
.create(WebArchive.class, "missingValueOnObserverMethodInjectionTest.war")
57+
.addAsLibrary(testJar);
58+
return war;
59+
}
60+
61+
@Test
62+
public void test() {
63+
}
64+
65+
}

0 commit comments

Comments
 (0)