getConfigSources(ClassLoader forClassLoader) {
95 | return configSources;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/configsource/SystemEnvConfigSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.configsource;
20 |
21 |
22 | import java.util.HashMap;
23 | import java.util.Map;
24 |
25 | import javax.enterprise.inject.Typed;
26 | import javax.enterprise.inject.Vetoed;
27 |
28 | import org.eclipse.microprofile.config.spi.ConfigSource;
29 |
30 | /**
31 | * {@link ConfigSource} which uses {@link System#getenv()}
32 | *
33 | * We also allow to write underlines _ instead of dots _ in the
34 | * environment via export (unix) or SET (windows)
35 | *
36 | * @author Mark Struberg
37 | */
38 | @Typed
39 | @Vetoed
40 | public class SystemEnvConfigSource extends BaseConfigSource {
41 | private Map configValues;
42 | private Map uppercasePosixValues;
43 |
44 | public SystemEnvConfigSource() {
45 | uppercasePosixValues = new HashMap<>();
46 | configValues = System.getenv();
47 | initOrdinal(300);
48 |
49 | for (Map.Entry e : configValues.entrySet()) {
50 | String originalKey = e.getKey();
51 | String posixKey = replaceNonPosixEnvChars(originalKey).toUpperCase();
52 | if (!originalKey.equals(posixKey)) {
53 | uppercasePosixValues.put(posixKey, e.getValue());
54 | }
55 | }
56 | }
57 |
58 | @Override
59 | public String getName() {
60 | return "system_env";
61 | }
62 |
63 | @Override
64 | public Map getProperties() {
65 | return configValues;
66 | }
67 |
68 | @Override
69 | public String getValue(String key) {
70 | String val = configValues.get(key);
71 | if (val == null) {
72 | key = replaceNonPosixEnvChars(key);
73 | val = configValues.get(key);
74 | }
75 | if (val == null) {
76 | key = key.toUpperCase();
77 | val = configValues.get(key);
78 | }
79 | if (val == null) {
80 | val = uppercasePosixValues.get(key);
81 | }
82 |
83 | return val;
84 | }
85 |
86 | private String replaceNonPosixEnvChars(String key) {
87 | return key.replaceAll("[^A-Za-z0-9]", "_");
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/configsource/SystemPropertyConfigSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.configsource;
20 |
21 | import org.apache.geronimo.config.cdi.configsource.Reloadable;
22 | import org.eclipse.microprofile.config.spi.ConfigSource;
23 |
24 | import javax.enterprise.inject.Typed;
25 | import javax.enterprise.inject.Vetoed;
26 | import java.util.Map;
27 |
28 | import static java.lang.Boolean.valueOf;
29 | import static java.util.function.Function.identity;
30 | import static java.util.stream.Collectors.toMap;
31 |
32 | /**
33 | * {@link ConfigSource} which uses {@link System#getProperties()}
34 | *
35 | * @author Mark Struberg
36 | */
37 | @Typed
38 | @Vetoed
39 | public class SystemPropertyConfigSource extends BaseConfigSource implements Reloadable {
40 | private static final String COPY_PROPERTY = "org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy";
41 | private final Map instance;
42 | private final boolean shouldReload;
43 |
44 | public SystemPropertyConfigSource() {
45 | this(valueOf(System.getProperty(COPY_PROPERTY, "true")));
46 | }
47 |
48 | public SystemPropertyConfigSource(boolean copy) {
49 | instance = load(copy);
50 | shouldReload = copy;
51 | initOrdinal(400);
52 | }
53 |
54 | @Override
55 | public Map getProperties() {
56 | return instance;
57 | }
58 |
59 | @Override
60 | public String getValue(String key) {
61 | return instance.get(key);
62 | }
63 |
64 | @Override
65 | public String getName() {
66 | return "system-properties";
67 | }
68 |
69 | @Override
70 | public void reload() {
71 | if (!shouldReload) {
72 | return;
73 | }
74 | instance.clear();
75 | instance.putAll(load(true));
76 | }
77 |
78 | private Map load(final boolean copy) {
79 | return copy ?
80 | System.getProperties().stringPropertyNames().stream().collect(toMap(identity(), System::getProperty)) :
81 | Map.class.cast(System.getProperties());
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/BooleanConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Mark Struberg
26 | */
27 | @Priority(1)
28 | @Vetoed
29 | public class BooleanConverter implements Converter {
30 |
31 | public static final BooleanConverter INSTANCE = new BooleanConverter();
32 |
33 | @Override
34 | public Boolean convert(String value) {
35 | if (value != null) {
36 | return "TRUE".equalsIgnoreCase(value)
37 | || "1".equalsIgnoreCase(value)
38 | || "YES".equalsIgnoreCase(value)
39 | || "Y".equalsIgnoreCase(value)
40 | || "ON".equalsIgnoreCase(value)
41 | || "JA".equalsIgnoreCase(value)
42 | || "J".equalsIgnoreCase(value)
43 | || "OUI".equalsIgnoreCase(value);
44 | }
45 |
46 | return null;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/ByteConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Daniel 'soro' Cunha
26 | */
27 |
28 | @Priority(1)
29 | @Vetoed
30 | public class ByteConverter implements Converter {
31 |
32 | public static final ByteConverter INSTANCE = new ByteConverter();
33 |
34 | @Override
35 | public Byte convert(String value) {
36 | return value != null ? Byte.valueOf(value) : null;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/CharacterConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Daniel 'soro' Cunha
26 | */
27 |
28 | @Priority(1)
29 | @Vetoed
30 | public class CharacterConverter implements Converter {
31 |
32 | public static final CharacterConverter INSTANCE = new CharacterConverter();
33 |
34 | @Override
35 | public Character convert(String value) {
36 | if (value == null || value.length() > 1) {
37 | throw new IllegalArgumentException("Error while converting the value " + value +
38 | " to type " + char.class);
39 | }
40 |
41 | return value.charAt(0);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/ClassConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.converters;
20 |
21 | import org.eclipse.microprofile.config.spi.Converter;
22 |
23 | import javax.annotation.Priority;
24 | import javax.enterprise.inject.Vetoed;
25 |
26 | @Priority(1)
27 | @Vetoed
28 | public class ClassConverter implements Converter{
29 | public static final Converter INSTANCE = new ClassConverter();
30 | @Override
31 | public Class convert(String value) {
32 | if(value == null) {
33 | return null;
34 | }
35 | try {
36 | ClassLoader loader = Thread.currentThread().getContextClassLoader();
37 | if (loader == null) {
38 | return Class.forName(value);
39 | }
40 | return Class.forName(value, true, loader);
41 | } catch (ClassNotFoundException e) {
42 | throw new IllegalArgumentException(e);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/DoubleConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Mark Struberg
26 | */
27 | @Priority(1)
28 | @Vetoed
29 | public class DoubleConverter implements Converter {
30 |
31 | public static final DoubleConverter INSTANCE = new DoubleConverter();
32 |
33 | @Override
34 | public Double convert(String value) {
35 | return value != null ? Double.valueOf(value) : null;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/DurationConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import java.time.Duration;
20 | import java.time.format.DateTimeParseException;
21 |
22 | import javax.annotation.Priority;
23 | import javax.enterprise.inject.Vetoed;
24 |
25 | import org.eclipse.microprofile.config.spi.Converter;
26 |
27 | /**
28 | * @author Mark Struberg
29 | */
30 | @Priority(1)
31 | @Vetoed
32 | public class DurationConverter implements Converter {
33 |
34 | public static final DurationConverter INSTANCE = new DurationConverter();
35 |
36 | @Override
37 | public Duration convert(String value) {
38 | if (value != null) {
39 | try {
40 | return Duration.parse(value);
41 | }
42 | catch (DateTimeParseException dtpe) {
43 | throw new IllegalArgumentException(dtpe);
44 | }
45 | }
46 | return null;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/FloatConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import javax.annotation.Priority;
20 | import javax.enterprise.inject.Vetoed;
21 |
22 | import org.eclipse.microprofile.config.spi.Converter;
23 |
24 | /**
25 | * @author Mark Struberg
26 | */
27 | @Priority(1)
28 | @Vetoed
29 | public class FloatConverter implements Converter {
30 |
31 | public static final FloatConverter INSTANCE = new FloatConverter();
32 |
33 | @Override
34 | public Float convert(String value) {
35 | return value != null ? Float.valueOf(value) : null;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/ImplicitConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import java.lang.reflect.Array;
22 | import java.lang.reflect.Constructor;
23 | import java.lang.reflect.Method;
24 | import java.lang.reflect.Modifier;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 |
29 |
30 | /**
31 | * A Converter factory + impl for 'common sense converters'
32 | *
33 | */
34 | public abstract class ImplicitConverter {
35 |
36 | public static Converter getImplicitConverter(Class> clazz) {
37 | // handle ct with String param
38 | Converter converter = null;
39 | if (converter == null) {
40 | converter = hasConverterMethod(clazz, "of", String.class);
41 | }
42 | if (converter == null) {
43 | converter = hasConverterMethod(clazz, "of", CharSequence.class);
44 | }
45 | if (converter == null) {
46 | converter = hasConverterMethod(clazz, "valueOf", String.class);
47 | }
48 | if (converter == null) {
49 | converter = hasConverterMethod(clazz, "valueOf", CharSequence.class);
50 | }
51 | if (converter == null) {
52 | converter = hasConverterMethod(clazz, "parse", String.class);
53 | }
54 | if (converter == null) {
55 | converter = hasConverterMethod(clazz, "parse", CharSequence.class);
56 | }
57 | if (converter == null) {
58 | converter = hasConverterCt(clazz, String.class);
59 | }
60 | if (converter == null) {
61 | converter = hasConverterCt(clazz, CharSequence.class);
62 | }
63 | return converter;
64 | }
65 |
66 | private static Converter hasConverterCt(Class> clazz, Class> paramType) {
67 | try {
68 | final Constructor> declaredConstructor = clazz.getDeclaredConstructor(paramType);
69 | if (!declaredConstructor.isAccessible()) {
70 | declaredConstructor.setAccessible(true);
71 | }
72 | return new Converter() {
73 | @Override
74 | public Object convert(String value) {
75 | try {
76 | return declaredConstructor.newInstance(value);
77 | } catch (Exception e) {
78 | throw new IllegalArgumentException(e);
79 | }
80 | }
81 | };
82 | } catch (NoSuchMethodException e) {
83 | // all fine
84 | }
85 | return null;
86 | }
87 |
88 | private static Converter hasConverterMethod(Class> clazz, String methodName, Class> paramType) {
89 | // handle valueOf with CharSequence param
90 | try {
91 | final Method method = clazz.getDeclaredMethod(methodName, paramType);
92 | if (!method.isAccessible()) {
93 | method.setAccessible(true);
94 | }
95 | if (Modifier.isStatic(method.getModifiers()) && method.getReturnType().equals(clazz)) {
96 | return new Converter() {
97 | @Override
98 | public Object convert(String value) {
99 | try {
100 | return method.invoke(null, value);
101 | } catch (Exception e) {
102 | throw new IllegalArgumentException("Error while converting the value " + value +
103 | " to type " + method.getReturnType());
104 | }
105 | }
106 | };
107 | }
108 | } catch (NoSuchMethodException e) {
109 | // all fine
110 | }
111 | return null;
112 | }
113 |
114 | public static class ImplicitArrayConverter implements Converter {
115 | private final Converter converter;
116 | private final Class> type;
117 |
118 | public ImplicitArrayConverter(Converter converter, Class> type) {
119 | this.converter = converter;
120 | this.type = type;
121 | }
122 |
123 | @Override
124 | public T convert(String valueStr) {
125 | if (valueStr == null)
126 | {
127 | return null;
128 | }
129 |
130 | List list = new ArrayList();
131 | StringBuilder currentValue = new StringBuilder();
132 | int length = valueStr.length();
133 | for (int i = 0; i < length; i++)
134 | {
135 | char c = valueStr.charAt(i);
136 | if (c == '\\')
137 | {
138 | if (i < length - 1)
139 | {
140 | char nextC = valueStr.charAt(i + 1);
141 | currentValue.append(nextC);
142 | i++;
143 | }
144 | }
145 | else if (c == ',')
146 | {
147 | String trimedVal = currentValue.toString().trim();
148 | if (trimedVal.length() > 0)
149 | {
150 | list.add(converter.convert(trimedVal));
151 | }
152 |
153 | currentValue.setLength(0);
154 | }
155 | else
156 | {
157 | currentValue.append(c);
158 | }
159 | }
160 |
161 | String trimedVal = currentValue.toString().trim();
162 | if (trimedVal.length() > 0)
163 | {
164 | list.add(converter.convert(trimedVal));
165 | }
166 |
167 | // everything else is an Object array
168 | Object array = Array.newInstance(type, list.size());
169 | for (int i=0; i < list.size(); i++) {
170 | Array.set(array, i, list.get(i));
171 | }
172 | return (T) array;
173 | }
174 |
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/IntegerConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import javax.annotation.Priority;
20 | import javax.enterprise.inject.Vetoed;
21 |
22 | import org.eclipse.microprofile.config.spi.Converter;
23 |
24 | /**
25 | * @author Mark Struberg
26 | */
27 | @Priority(1)
28 | @Vetoed
29 | public class IntegerConverter implements Converter {
30 |
31 | public static final IntegerConverter INSTANCE = new IntegerConverter();
32 |
33 | @Override
34 | public Integer convert(String value) {
35 | return value != null ? Integer.valueOf(value) : null;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/LongConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Mark Struberg
26 | */
27 | @Priority(1)
28 | @Vetoed
29 | public class LongConverter implements Converter {
30 |
31 | public static final LongConverter INSTANCE = new LongConverter();
32 |
33 | @Override
34 | public Long convert(String value) {
35 | return value != null ? Long.valueOf(value) : null;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/ShortConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 |
24 | /**
25 | * @author Daniel 'soro' Cunha
26 | */
27 |
28 | @Priority(1)
29 | @Vetoed
30 | public class ShortConverter implements Converter {
31 |
32 | public static final ShortConverter INSTANCE = new ShortConverter();
33 |
34 | @Override
35 | public Short convert(String value) {
36 | return value != null ? Short.valueOf(value) : null;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/StringConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import javax.annotation.Priority;
20 | import javax.enterprise.inject.Vetoed;
21 |
22 | import org.eclipse.microprofile.config.spi.Converter;
23 |
24 | /**
25 | * 1:1 string output. Just to make converter logic happy.
26 | *
27 | * @author Mark Struberg
28 | */
29 | @Priority(1)
30 | @Vetoed
31 | public class StringConverter implements Converter {
32 |
33 | public static final StringConverter INSTANCE = new StringConverter();
34 |
35 | @Override
36 | public String convert(String value) {
37 | return value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/impl/src/main/java/org/apache/geronimo/config/converters/URLConverter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.converters;
18 |
19 | import org.eclipse.microprofile.config.spi.Converter;
20 |
21 | import javax.annotation.Priority;
22 | import javax.enterprise.inject.Vetoed;
23 | import java.net.MalformedURLException;
24 | import java.net.URL;
25 |
26 | @Vetoed
27 | @Priority(1)
28 | public class URLConverter implements Converter {
29 | public static final URLConverter INSTANCE = new URLConverter();
30 | @Override
31 | public URL convert(String value) {
32 | try {
33 | return new URL(value);
34 | } catch (MalformedURLException e) {
35 | throw new IllegalArgumentException("Invalid url "+value,e);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/impl/src/main/resources/META-INF/beans.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
--------------------------------------------------------------------------------
/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy current the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | org.apache.geronimo.config.cdi.ConfigExtension
--------------------------------------------------------------------------------
/impl/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigProviderResolver:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy current the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | org.apache.geronimo.config.DefaultConfigProvider
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/GeronimoConfigArchiveProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test;
18 |
19 | import org.apache.geronimo.config.ConfigImpl;
20 | import org.apache.geronimo.config.DefaultConfigProvider;
21 | import org.apache.geronimo.config.cdi.ConfigExtension;
22 | import org.apache.geronimo.config.configsource.BaseConfigSource;
23 | import org.apache.geronimo.config.converters.BooleanConverter;
24 | import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
25 | import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
26 | import org.jboss.arquillian.test.spi.TestClass;
27 | import org.jboss.shrinkwrap.api.Archive;
28 | import org.jboss.shrinkwrap.api.ShrinkWrap;
29 | import org.jboss.shrinkwrap.api.asset.EmptyAsset;
30 | import org.jboss.shrinkwrap.api.spec.JavaArchive;
31 | import org.jboss.shrinkwrap.api.spec.WebArchive;
32 |
33 | /**
34 | * Adds the whole Config implementation classes and resources to the
35 | * Arqillian deployment archive. This is needed to have the container
36 | * pick up the beans from within the impl for the TCK tests.
37 | *
38 | * @author Mark Struberg
39 | */
40 | public class GeronimoConfigArchiveProcessor implements ApplicationArchiveProcessor {
41 |
42 | @Override
43 | public void process(Archive> applicationArchive, TestClass testClass) {
44 | if (applicationArchive instanceof WebArchive) {
45 | JavaArchive configJar = ShrinkWrap
46 | .create(JavaArchive.class, "geronimo-config-impl.jar")
47 | .addPackage(ConfigImpl.class.getPackage())
48 | .addPackage(BooleanConverter.class.getPackage())
49 | .addPackage(BaseConfigSource.class.getPackage())
50 | .addPackage(ConfigExtension.class.getPackage())
51 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
52 | .addAsServiceProvider(ConfigProviderResolver.class, DefaultConfigProvider.class);
53 | ((WebArchive) applicationArchive).addAsLibraries(configJar);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/GeronimoConfigExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test;
18 |
19 | import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor;
20 | import org.jboss.arquillian.core.spi.LoadableExtension;
21 |
22 | /**
23 | * @author Mark Struberg
24 | */
25 | public class GeronimoConfigExtension implements LoadableExtension {
26 | @Override
27 | public void register(ExtensionBuilder extensionBuilder) {
28 | extensionBuilder.service(ApplicationArchiveProcessor.class, GeronimoConfigArchiveProcessor.class);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | package org.apache.geronimo.config.test.internal;
21 |
22 | import org.eclipse.microprofile.config.inject.ConfigProperty;
23 | import org.jboss.arquillian.container.test.api.Deployment;
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.Assert;
31 | import org.testng.annotations.Test;
32 |
33 | import javax.enterprise.context.RequestScoped;
34 | import javax.inject.Inject;
35 |
36 | import java.util.LinkedHashSet;
37 | import java.util.List;
38 | import java.util.Set;
39 |
40 | import static java.util.Arrays.asList;
41 |
42 | public class ArrayTypeTest extends Arquillian {
43 | private static final String SOME_KEY = "org.apache.geronimo.config.test.internal.somekey";
44 | private static final String SOME_OTHER_KEY = "org.apache.geronimo.config.test.internal.someotherkey";
45 |
46 | @Deployment
47 | public static WebArchive deploy() {
48 | JavaArchive testJar = ShrinkWrap
49 | .create(JavaArchive.class, "arrayTest.jar")
50 | .addClasses(ArrayTypeTest.class, SomeBean.class)
51 | .addAsManifestResource(new StringAsset(
52 | SOME_KEY + "=1,2,3\n" +
53 | SOME_OTHER_KEY + "=1,2\\\\,3\n" +
54 | "placeholder=4,5,6\n"
55 | ), "microprofile-config.properties")
56 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
57 |
58 | return ShrinkWrap
59 | .create(WebArchive.class, "arrayTest.war")
60 | .addAsLibrary(testJar);
61 | }
62 |
63 | @Inject
64 | private SomeBean someBean;
65 |
66 | @Test
67 | public void testArraySetListInjection() {
68 | Assert.assertEquals(someBean.getStringValue(), "1,2,3");
69 | Assert.assertEquals(someBean.getMyconfig(), new int[]{1, 2, 3});
70 | Assert.assertEquals(someBean.getIntValues(), asList(1, 2, 3));
71 | Assert.assertEquals(someBean.getIntSet(), new LinkedHashSet<>(asList(1, 2, 3)));
72 | Assert.assertEquals(someBean.getIntSetDefault(), new LinkedHashSet<>(asList(1, 2, 3)));
73 | Assert.assertEquals(someBean.getIntSetPlaceholderDefault(), new LinkedHashSet<>(asList(4, 5, 6)));
74 | }
75 |
76 | @Test
77 | public void testListWithEscaping() {
78 | Assert.assertEquals(someBean.getValues(), asList("1", "2,3"));
79 | }
80 |
81 | @RequestScoped
82 | public static class SomeBean {
83 |
84 | @Inject
85 | @ConfigProperty(name = SOME_KEY)
86 | private int[] myconfig;
87 |
88 | @Inject
89 | @ConfigProperty(name = SOME_KEY)
90 | private List intValues;
91 |
92 | @Inject
93 | @ConfigProperty(name = SOME_KEY)
94 | private Set intSet;
95 |
96 | @Inject
97 | @ConfigProperty(name = SOME_KEY + ".missing", defaultValue = "1,2,3")
98 | private Set intSetDefault;
99 |
100 | @Inject
101 | @ConfigProperty(name = SOME_KEY + ".missing", defaultValue = "${placeholder}")
102 | private Set intSetPlaceholderDefault;
103 |
104 | @Inject
105 | @ConfigProperty(name = SOME_KEY)
106 | private String stringValue;
107 |
108 | @Inject
109 | @ConfigProperty(name = SOME_OTHER_KEY)
110 | private List values;
111 |
112 | public Set getIntSetPlaceholderDefault() {
113 | return intSetPlaceholderDefault;
114 | }
115 |
116 | public Set getIntSetDefault() {
117 | return intSetDefault;
118 | }
119 |
120 | public String getStringValue() {
121 | return stringValue;
122 | }
123 |
124 | public int[] getMyconfig() {
125 | return myconfig;
126 | }
127 |
128 | public List getIntValues() {
129 | return intValues;
130 | }
131 |
132 | public Set getIntSet() {
133 | return intSet;
134 | }
135 |
136 | public List getValues() {
137 | return values;
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/ConfigInjectionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test.internal;
18 |
19 | import javax.inject.Inject;
20 |
21 | import org.eclipse.microprofile.config.Config;
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.spec.JavaArchive;
27 | import org.jboss.shrinkwrap.api.spec.WebArchive;
28 | import org.testng.Assert;
29 | import org.testng.annotations.Test;
30 |
31 | public class ConfigInjectionTest extends Arquillian {
32 | @Deployment
33 | public static WebArchive deploy() {
34 | JavaArchive testJar = ShrinkWrap
35 | .create(JavaArchive.class, "configProviderTest.jar")
36 | .addClasses(ConfigInjectionTest.class)
37 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
38 |
39 | return ShrinkWrap
40 | .create(WebArchive.class, "providerTest.war")
41 | .addAsLibrary(testJar);
42 | }
43 |
44 | @Inject
45 | private Config config;
46 |
47 | @Test
48 | public void testConfigProvider() {
49 | Assert.assertNotNull(config); // is injected
50 | Assert.assertNotNull(config.getValue("java.version", String.class)); // is usable
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/DefaultNullValueTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.test.internal;
20 |
21 | import org.eclipse.microprofile.config.inject.ConfigProperty;
22 | import org.jboss.arquillian.container.test.api.Deployment;
23 | import org.jboss.arquillian.testng.Arquillian;
24 | import org.jboss.shrinkwrap.api.Archive;
25 | import org.jboss.shrinkwrap.api.ShrinkWrap;
26 | import org.jboss.shrinkwrap.api.asset.EmptyAsset;
27 | import org.jboss.shrinkwrap.api.spec.WebArchive;
28 | import org.testng.annotations.Test;
29 |
30 | import javax.enterprise.context.ApplicationScoped;
31 | import javax.inject.Inject;
32 | import java.net.URL;
33 | import java.time.Duration;
34 | import java.util.List;
35 | import java.util.Optional;
36 |
37 | import static org.testng.Assert.assertNull;
38 |
39 | /**
40 | * @author Daniel 'soro' Cunha
41 | */
42 | public class DefaultNullValueTest extends Arquillian {
43 | @Deployment
44 | public static Archive> archive() {
45 | return ShrinkWrap.create(WebArchive.class, DefaultNullValueTest.class.getSimpleName() + ".war")
46 | .addAsWebInfResource(EmptyAsset.INSTANCE, "classes/META-INF/beans.xml")
47 | .addClasses(DefaultNullValueTest.class, DefaultNullValueTest.Injected.class);
48 | }
49 |
50 | @Inject
51 | private Injected injected;
52 |
53 | @Test
54 | public void testDefaultNullValue() {
55 | assertNull(injected.getBooleanNullValue());
56 | assertNull(injected.getStringNullValue());
57 | assertNull(injected.getByteNullValue());
58 | assertNull(injected.getIntegerNullValue());
59 | assertNull(injected.getLongNullValue());
60 | assertNull(injected.getShortNullValue());
61 | assertNull(injected.getListNullValue());
62 | assertNull(injected.getClassNullValue());
63 | assertNull(injected.getDoubleNullValue());
64 | assertNull(injected.getDurationNullValue());
65 | }
66 |
67 | @ApplicationScoped
68 | public static class Injected {
69 |
70 | @Inject
71 | @ConfigProperty(name = "boolean.nullvalue.default")
72 | private Optional booleanNullValue;
73 |
74 | @Inject
75 | @ConfigProperty(name = "string.nullvalue.default")
76 | private Optional stringNullValue;
77 |
78 | @Inject
79 | @ConfigProperty(name = "long.nullvalue.default")
80 | private Optional longNullValue;
81 |
82 | @Inject
83 | @ConfigProperty(name = "integer.nullvalue.default")
84 | private Optional integerNullValue;
85 |
86 | @Inject
87 | @ConfigProperty(name = "float.nullvalue.default")
88 | private Optional floatNullValue;
89 |
90 | @Inject
91 | @ConfigProperty(name = "double.nullvalue.default")
92 | private Optional doubleNullValue;
93 |
94 | @Inject
95 | @ConfigProperty(name = "character.nullvalue.default")
96 | private Optional characterNullValue;
97 |
98 | @Inject
99 | @ConfigProperty(name = "short.nullvalue.default")
100 | private Optional shortNullValue;
101 |
102 | @Inject
103 | @ConfigProperty(name = "byte.nullvalue.default")
104 | private Optional byteNullValue;
105 |
106 | @Inject
107 | @ConfigProperty(name = "list.nullvalue.default")
108 | private Optional> listNullValue;
109 |
110 | @Inject
111 | @ConfigProperty(name = "class.nullvalue.default")
112 | private Optional classNullValue;
113 |
114 | @Inject
115 | @ConfigProperty(name = "url.nullvalue.default")
116 | private Optional urlNullValue;
117 |
118 | @Inject
119 | @ConfigProperty(name = "duration.nullvalue.default")
120 | private Optional durationNullValue;
121 |
122 | public Boolean getBooleanNullValue() {
123 | return booleanNullValue.orElse(null);
124 | }
125 |
126 | public String getStringNullValue() {
127 | return stringNullValue.orElse(null);
128 | }
129 |
130 | public Long getLongNullValue() {
131 | return longNullValue.orElse(null);
132 | }
133 |
134 | public Integer getIntegerNullValue() {
135 | return integerNullValue.orElse(null);
136 | }
137 |
138 | public Float getFloatNullValue() {
139 | return floatNullValue.orElse(null);
140 | }
141 |
142 | public Double getDoubleNullValue() {
143 | return doubleNullValue.orElse(null);
144 | }
145 |
146 | public Character getCharacterNullValue() {
147 | return characterNullValue.orElse(null);
148 | }
149 |
150 | public Short getShortNullValue() {
151 | return shortNullValue.orElse(null);
152 | }
153 |
154 | public Byte getByteNullValue() {
155 | return byteNullValue.orElse(null);
156 | }
157 |
158 | public List getListNullValue() {
159 | return listNullValue.orElse(null);
160 | }
161 |
162 | public Class getClassNullValue() {
163 | return classNullValue.orElse(null);
164 | }
165 |
166 | public URL getUrlNullValue() {
167 | return urlNullValue.orElse(null);
168 | }
169 |
170 | public Duration getDurationNullValue() {
171 | return durationNullValue.orElse(null);
172 | }
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/PropertyFileConfigSourceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test.internal;
18 |
19 | import org.apache.geronimo.config.configsource.PropertyFileConfigSource;
20 | import org.testng.annotations.Test;
21 |
22 | import java.net.URL;
23 | import java.nio.file.Paths;
24 |
25 | import static org.testng.AssertJUnit.assertTrue;
26 |
27 | public class PropertyFileConfigSourceTest {
28 | @Test
29 | public void testLoadMissingFile() throws Exception{
30 | URL url = Paths.get("some/missing/File.txt").toUri().toURL();
31 | PropertyFileConfigSource propertyFileConfigSource = new PropertyFileConfigSource(url);
32 | assertTrue(propertyFileConfigSource.getProperties().isEmpty());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/ProviderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test.internal;
18 |
19 | import java.util.Optional;
20 |
21 | import javax.enterprise.context.RequestScoped;
22 | import javax.inject.Inject;
23 | import javax.inject.Provider;
24 |
25 | import org.apache.geronimo.config.test.testng.SystemPropertiesLeakProtector;
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.JavaArchive;
33 | import org.jboss.shrinkwrap.api.spec.WebArchive;
34 | import org.testng.Assert;
35 | import org.testng.annotations.Test;
36 |
37 | public class ProviderTest extends Arquillian {
38 | private static final String SOME_KEY = "org.apache.geronimo.config.test.internal.somekey";
39 |
40 | @Deployment
41 | public static WebArchive deploy() {
42 | JavaArchive testJar = ShrinkWrap
43 | .create(JavaArchive.class, "configProviderTest.jar")
44 | .addClasses(ProviderTest.class, SomeBean.class)
45 | .addAsManifestResource(
46 | new StringAsset(SOME_KEY + "=someval\n"),
47 | "microprofile-config.properties")
48 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
49 |
50 | return ShrinkWrap
51 | .create(WebArchive.class, "providerTest.war")
52 | .addAsLibrary(testJar);
53 | }
54 |
55 | private @Inject SomeBean someBean;
56 |
57 |
58 | @Test
59 | public void testConfigProvider() {
60 | final SystemPropertiesLeakProtector fixer = new SystemPropertiesLeakProtector(); // lazy way to reset all the system props manipulated by this test
61 | fixer.onStart(null);
62 |
63 | System.setProperty(SOME_KEY, "someval");
64 | String myconfig = someBean.getMyconfig();
65 | Assert.assertEquals(myconfig, "someval");
66 | Assert.assertEquals(someBean.getOptionalProvider().get().get(), "someval");
67 | Assert.assertEquals(someBean.getProviderOptional().get().get(), "someval");
68 |
69 | System.setProperty(SOME_KEY, "otherval");
70 | myconfig = someBean.getMyconfig();
71 | Assert.assertEquals(myconfig, "otherval");
72 |
73 | fixer.onFinish(null);
74 | }
75 |
76 |
77 | @RequestScoped
78 | public static class SomeBean {
79 |
80 | @Inject
81 | @ConfigProperty(name=SOME_KEY)
82 | private Provider myconfig;
83 |
84 | @Inject
85 | @ConfigProperty(name=SOME_KEY)
86 | private Optional> optionalProvider;
87 |
88 | @Inject
89 | @ConfigProperty(name=SOME_KEY)
90 | private Provider> providerOptional;
91 |
92 | public Optional> getOptionalProvider() {
93 | return optionalProvider;
94 | }
95 |
96 | public Provider> getProviderOptional() {
97 | return providerOptional;
98 | }
99 |
100 | public String getMyconfig() {
101 | return myconfig.get();
102 | }
103 |
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/ProxyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test.internal;
18 |
19 | import static java.util.Arrays.asList;
20 | import static org.testng.Assert.assertEquals;
21 | import static org.testng.Assert.assertFalse;
22 | import static org.testng.Assert.assertNotNull;
23 | import static org.testng.Assert.assertNull;
24 |
25 | import java.net.URL;
26 | import java.time.Duration;
27 | import java.util.Collection;
28 | import java.util.List;
29 |
30 | import javax.inject.Inject;
31 |
32 | import org.eclipse.microprofile.config.inject.ConfigProperty;
33 | import org.jboss.arquillian.container.test.api.Deployment;
34 | import org.jboss.arquillian.testng.Arquillian;
35 | import org.jboss.shrinkwrap.api.ShrinkWrap;
36 | import org.jboss.shrinkwrap.api.asset.EmptyAsset;
37 | import org.jboss.shrinkwrap.api.asset.StringAsset;
38 | import org.jboss.shrinkwrap.api.spec.JavaArchive;
39 | import org.jboss.shrinkwrap.api.spec.WebArchive;
40 | import org.testng.annotations.Test;
41 |
42 | public class ProxyTest extends Arquillian {
43 | private static final String LIST_KEY = SomeProxy.class.getName() + ".list";
44 | private static final String SOME_KEY = SomeProxy.class.getName() + ".key";
45 | private static final String SOME_OTHER_KEY = SomeProxy.class.getName() + ".key2";
46 |
47 | @Deployment
48 | public static WebArchive deploy() {
49 | JavaArchive testJar = ShrinkWrap
50 | .create(JavaArchive.class, "PoxyTest.jar")
51 | .addClasses(ProxyTest.class, SomeProxy.class, PrefixedSomeProxy.class)
52 | .addAsManifestResource(
53 | new StringAsset("" +
54 | "interpolated=a,${my_int_property},${MY_STRING_PROPERTY},${my.string.property}\n" +
55 | "list.interpolated=a,${my_int_property},${MY_STRING_PROPERTY},${my.string.property}\n" +
56 | "my.string.property=haha\n" +
57 | "prefix.val=yes\n" +
58 | LIST_KEY + "=a,b,1\n" +
59 | SOME_KEY + "=yeah\n" +
60 | SOME_OTHER_KEY + "=123\n"
61 | ), "microprofile-config.properties")
62 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
63 |
64 | return ShrinkWrap
65 | .create(WebArchive.class, "providerTest.war")
66 | .addAsLibrary(testJar);
67 | }
68 |
69 | @Inject
70 | private PrefixedSomeProxy prefixed;
71 |
72 | @Inject
73 | private SomeProxy proxy;
74 |
75 | @Test
76 | public void test() {
77 | assertEquals(proxy.key(), "yeah");
78 | assertEquals(proxy.renamed(), "yeah");
79 | assertEquals(proxy.key2(), 123);
80 | assertEquals(proxy.key3(), "def");
81 | assertEquals(proxy.list(), asList("a", "b", "1"));
82 | assertEquals(proxy.listDefaults(), asList(1, 2, 1));
83 | assertEquals(proxy.listClasses(), asList(String.class, Integer.class));
84 |
85 | assertNull(proxy.booleanNullValue());
86 | assertNull(proxy.stringNullValue());
87 | assertNull(proxy.byteNullValue());
88 | assertNull(proxy.integerNullValue());
89 | assertNull(proxy.longNullValue());
90 | assertNull(proxy.shortNullValue());
91 | assertNull(proxy.listNullValue());
92 | assertNull(proxy.classNullValue());
93 | assertNull(proxy.doubleNullValue());
94 | assertNull(proxy.durationNullValue());
95 |
96 | assertFalse(proxy.primitiveBooleanNullValue());
97 | assertEquals(0, proxy.primitiveLongNullValue());
98 | assertEquals(0, proxy.primitiveIntegerNullValue());
99 | assertEquals(0, proxy.primitiveShortNullValue());
100 | assertEquals(0, proxy.primitiveByteNullValue());
101 | assertEquals(0.0F, proxy.primitiveFloatNullValue());
102 | assertEquals(0.0D, proxy.primitiveDoubleNullValue());
103 | assertEquals('\u0000', proxy.primitiveCharacterNullValue());
104 |
105 | assertEquals(proxy.interpolated(), "a,45,woohoo,haha");
106 | assertEquals(proxy.listInterpolatedValue(), asList("a", "45", "woohoo", "haha"));
107 | }
108 |
109 | @Test
110 | public void prefix() {
111 | assertEquals(prefixed.val(), "yes");
112 | }
113 |
114 | @ConfigProperty(name = "prefix.")
115 | public interface PrefixedSomeProxy {
116 | @ConfigProperty(name = "val")
117 | String val();
118 | }
119 |
120 | public interface SomeProxy {
121 | @ConfigProperty
122 | int key2();
123 |
124 | @ConfigProperty(defaultValue = "def")
125 | String key3();
126 |
127 | @ConfigProperty
128 | String key();
129 |
130 | @ConfigProperty(name = "org.apache.geronimo.config.test.internal.ProxyTest$SomeProxy.key")
131 | String renamed();
132 |
133 | @ConfigProperty
134 | Collection list();
135 |
136 | @ConfigProperty(defaultValue = "java.lang.String,java.lang.Integer")
137 | Collection> listClasses();
138 |
139 | @ConfigProperty(defaultValue = "1,2,1")
140 | Collection listDefaults();
141 |
142 | @ConfigProperty(name = "boolean.nullvalue.default")
143 | Boolean booleanNullValue();
144 |
145 | @ConfigProperty(name = "boolean.nullvalue.default")
146 | boolean primitiveBooleanNullValue();
147 |
148 | @ConfigProperty(name = "string.nullvalue.default")
149 | String stringNullValue();
150 |
151 | @ConfigProperty(name = "long.nullvalue.default")
152 | Long longNullValue();
153 |
154 | @ConfigProperty(name = "long.nullvalue.default")
155 | long primitiveLongNullValue();
156 |
157 | @ConfigProperty(name = "integer.nullvalue.default")
158 | Integer integerNullValue();
159 |
160 | @ConfigProperty(name = "integer.nullvalue.default")
161 | int primitiveIntegerNullValue();
162 |
163 | @ConfigProperty(name = "float.nullvalue.default")
164 | Float floatNullValue();
165 |
166 | @ConfigProperty(name = "float.nullvalue.default")
167 | float primitiveFloatNullValue();
168 |
169 | @ConfigProperty(name = "double.nullvalue.default")
170 | Double doubleNullValue();
171 |
172 | @ConfigProperty(name = "double.nullvalue.default")
173 | double primitiveDoubleNullValue();
174 |
175 | @ConfigProperty(name = "character.nullvalue.default")
176 | Character characterNullValue();
177 |
178 | @ConfigProperty(name = "character.nullvalue.default")
179 | char primitiveCharacterNullValue();
180 |
181 | @ConfigProperty(name = "short.nullvalue.default")
182 | Short shortNullValue();
183 |
184 | @ConfigProperty(name = "short.nullvalue.default")
185 | short primitiveShortNullValue();
186 |
187 | @ConfigProperty(name = "byte.nullvalue.default")
188 | Byte byteNullValue();
189 |
190 | @ConfigProperty(name = "byte.nullvalue.default")
191 | byte primitiveByteNullValue();
192 |
193 | @ConfigProperty(name = "list.nullvalue.default")
194 | List listNullValue();
195 |
196 | @ConfigProperty(name = "list.interpolated")
197 | List listInterpolatedValue();
198 |
199 | @ConfigProperty(name = "interpolated")
200 | String interpolated();
201 |
202 | @ConfigProperty(name = "class.nullvalue.default")
203 | Class classNullValue();
204 |
205 | @ConfigProperty(name = "url.nullvalue.default")
206 | URL urlNullValue();
207 |
208 | @ConfigProperty(name = "duration.nullvalue.default")
209 | Duration durationNullValue();
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/SupplierTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.test.internal;
20 |
21 | import org.apache.geronimo.config.test.testng.SystemPropertiesLeakProtector;
22 | import org.eclipse.microprofile.config.inject.ConfigProperty;
23 | import org.jboss.arquillian.container.test.api.Deployment;
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.Assert;
31 | import org.testng.annotations.Test;
32 |
33 | import javax.enterprise.context.RequestScoped;
34 | import javax.inject.Inject;
35 | import java.util.function.Supplier;
36 |
37 | public class SupplierTest extends Arquillian{
38 | private static final String SOME_KEY = "org.apache.geronimo.config.test.internal.somekey";
39 | private static final String SUPPLIER_DEFAULT_VALUE = "supplierDefaultValue";
40 | private static final String SOME_INT_KEY = "some.supplier.int.key";
41 |
42 | @Deployment
43 | public static WebArchive deploy() {
44 | JavaArchive testJar = ShrinkWrap
45 | .create(JavaArchive.class, "configSupplierTest.jar")
46 | .addClasses(SupplierTest.class, SomeBean.class)
47 | .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
48 | .addAsManifestResource(
49 | new StringAsset(SOME_KEY + "=someval\n"),
50 | "microprofile-config.properties")
51 | .as(JavaArchive.class);
52 |
53 | return ShrinkWrap
54 | .create(WebArchive.class, "supplierTest.war")
55 | .addAsLibrary(testJar);
56 | }
57 |
58 | private @Inject SomeBean someBean;
59 |
60 |
61 | @Test
62 | public void testConfigProvider() {
63 | final SystemPropertiesLeakProtector fixer = new SystemPropertiesLeakProtector(); // lazy way to reset all the system props manipulated by this test
64 | fixer.onStart(null);
65 |
66 | String someval = "someval";
67 | System.setProperty(SOME_KEY, someval);
68 | String myconfig = someBean.getMyconfig();
69 | Assert.assertEquals(myconfig, someval);
70 |
71 | String otherval = "otherval";
72 | System.setProperty(SOME_KEY, otherval);
73 | myconfig = someBean.getMyconfig();
74 | Assert.assertEquals(myconfig, otherval);
75 |
76 | Assert.assertEquals(someBean.getAnotherconfig().get(), SUPPLIER_DEFAULT_VALUE);
77 |
78 | System.setProperty(SOME_INT_KEY, "42");
79 | Assert.assertEquals(someBean.getSomeInt(), 42);
80 |
81 | Assert.assertNull(someBean.getUndefinedValue().get());
82 | fixer.onFinish(null);
83 | }
84 |
85 | @RequestScoped
86 | public static class SomeBean {
87 |
88 | @Inject
89 | @ConfigProperty(name=SOME_KEY)
90 | private Supplier myconfig;
91 |
92 | @Inject
93 | @ConfigProperty(name = SOME_INT_KEY)
94 | private Supplier someIntValue;
95 |
96 | @Inject
97 | @ConfigProperty(name="missing.key", defaultValue = SUPPLIER_DEFAULT_VALUE)
98 | private Supplier anotherconfig;
99 |
100 | @Inject
101 | @ConfigProperty(name = "UNDEFINED_VALUE")
102 | private Supplier undefinedValue;
103 |
104 | public int getSomeInt() {
105 | return someIntValue.get();
106 | }
107 |
108 | public String getMyconfig() {
109 | return myconfig.get();
110 | }
111 |
112 | public Supplier getAnotherconfig() {
113 | return anotherconfig;
114 | }
115 |
116 | public Supplier getUndefinedValue() {
117 | return undefinedValue;
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/SystemEnvConfigSourceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.test.internal;
20 |
21 | import org.eclipse.microprofile.config.Config;
22 | import org.eclipse.microprofile.config.ConfigProvider;
23 | import org.testng.Assert;
24 | import org.testng.annotations.Test;
25 |
26 | /**
27 | * This needs to have some ENV settings set up.
28 | * This is usually done via maven.
29 | * For running the test yourself you have to set the following environment properties:
30 | *
31 | * A_b_c=1
32 | * A_B_C=2
33 | * A_B_D=3
34 | * A_B_e=4
35 | */
36 | public class SystemEnvConfigSourceTest {
37 | @Test
38 | public void testEnvReplacement() {
39 | Config config = ConfigProvider.getConfig();
40 |
41 | Assert.assertEquals(config.getValue("A.b#c", Integer.class), Integer.valueOf(1));
42 |
43 | Assert.assertEquals(config.getValue("a.b.c", Integer.class), Integer.valueOf(2));
44 |
45 | Assert.assertEquals(config.getValue("a.b.d", Integer.class), Integer.valueOf(3));
46 |
47 | Assert.assertEquals(config.getValue("a.b.e", Integer.class), Integer.valueOf(4));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/internal/SystemPropertyConfigSourceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.geronimo.config.test.internal;
20 |
21 | import static org.testng.Assert.assertTrue;
22 |
23 | import javax.enterprise.context.ApplicationScoped;
24 | import javax.enterprise.event.Observes;
25 | import javax.enterprise.inject.spi.AfterBeanDiscovery;
26 | import javax.enterprise.inject.spi.BeforeBeanDiscovery;
27 | import javax.enterprise.inject.spi.BeforeShutdown;
28 | import javax.enterprise.inject.spi.Extension;
29 | import javax.inject.Inject;
30 |
31 | import org.eclipse.microprofile.config.Config;
32 | import org.eclipse.microprofile.config.ConfigProvider;
33 | import org.eclipse.microprofile.config.inject.ConfigProperty;
34 | import org.jboss.arquillian.container.test.api.Deployment;
35 | import org.jboss.arquillian.testng.Arquillian;
36 | import org.jboss.shrinkwrap.api.Archive;
37 | import org.jboss.shrinkwrap.api.ShrinkWrap;
38 | import org.jboss.shrinkwrap.api.asset.EmptyAsset;
39 | import org.jboss.shrinkwrap.api.spec.WebArchive;
40 | import org.testng.Assert;
41 | import org.testng.annotations.Test;
42 |
43 | /**
44 | * It is important to ensure the config is reloaded before going live in case some
45 | * system properties are set during the starting extension lifecycle.
46 | */
47 | public class SystemPropertyConfigSourceTest extends Arquillian {
48 | @Deployment
49 | public static Archive> archive() {
50 | return ShrinkWrap.create(WebArchive.class, SystemPropertyConfigSourceTest.class.getSimpleName() + ".war")
51 | .addAsWebInfResource(EmptyAsset.INSTANCE, "classes/META-INF/beans.xml")
52 | .addAsServiceProvider(Extension.class, InitInExtension.class)
53 | .addClasses(SystemPropertyConfigSourceTest.class, Injected.class);
54 | }
55 |
56 | @Inject
57 | private Injected injected;
58 |
59 | @Test
60 | public void testSystemPropsLoadedExtensionValue() {
61 | assertTrue(injected.getSet());
62 | }
63 |
64 | @ApplicationScoped
65 | public static class Injected {
66 | @Inject
67 | @ConfigProperty(name = "org.apache.geronimo.config.test.internal.SystemPropertyConfigSourceTest$InitInExtension")
68 | private Boolean set;
69 |
70 | public Boolean getSet() {
71 | return set;
72 | }
73 | }
74 |
75 | public static class InitInExtension implements Extension {
76 | private String originalCopy;
77 |
78 | void eagerInit(@Observes final BeforeBeanDiscovery beforeBeanDiscovery) {
79 | originalCopy = System.getProperty("org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy");
80 | // enfore the default, it is overriden for surefire
81 | System.setProperty("org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy", "true");
82 |
83 | // eager load -> loads system props and copy
84 | ConfigProvider.getConfig();
85 | }
86 |
87 | // before validation to ensure config validation passes
88 | void afterBeanDiscovery(@Observes final AfterBeanDiscovery afterBeanDiscovery) {
89 | // with copy this should get ignored but we will reload it before the validation
90 | System.setProperty(InitInExtension.class.getName(), "true");
91 | }
92 |
93 | void beforeShutdown(@Observes final BeforeShutdown beforeShutdown) {
94 | System.clearProperty(InitInExtension.class.getName());
95 | if (originalCopy != null) {
96 | System.setProperty("org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy", originalCopy);
97 | } else {
98 | System.clearProperty("org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy");
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/impl/src/test/java/org/apache/geronimo/config/test/testng/SystemPropertiesLeakProtector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. 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 | package org.apache.geronimo.config.test.testng;
18 |
19 | import org.testng.ITestContext;
20 | import org.testng.TestListenerAdapter;
21 |
22 | import java.util.Properties;
23 |
24 | public class SystemPropertiesLeakProtector extends TestListenerAdapter {
25 | private Properties props;
26 |
27 | @Override
28 | public void onStart(final ITestContext context) {
29 | props = new Properties();
30 | props.putAll(System.getProperties());
31 | props.put("org.apache.geronimo.config.configsource.SystemPropertyConfigSource.copy", "false");
32 | }
33 |
34 | @Override
35 | public void onFinish(final ITestContext testContext) {
36 | System.getProperties().clear(); // keep the same ref
37 | System.getProperties().putAll(props);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/impl/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy current the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 |
21 | org.apache.geronimo.config.test.GeronimoConfigExtension
--------------------------------------------------------------------------------
/impl/tck-suite.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 | 4.0.0
22 |
23 |
24 | org.apache
25 | apache
26 | 18
27 |
28 |
29 | org.apache.geronimo.config
30 | geronimo-config
31 | 1.2.4-SNAPSHOT
32 | pom
33 | Geronimo Microprofile Configuration
34 |
35 |
36 |
37 | Apache License, Version 2.0
38 | https://www.apache.org/licenses/LICENSE-2.0.txt
39 | repo
40 |
41 |
42 |
43 |
44 | scm:git:https://gitbox.apache.org/repos/asf/geronimo-config.git
45 | scm:git:https://gitbox.apache.org/repos/asf/geronimo-config.git
46 | https://gitbox.apache.org/repos/asf/geronimo-config.git
47 | HEAD
48 |
49 |
50 |
51 |
52 | 1.8
53 | 1.8
54 | 1.4
55 | 1.1.14.Final
56 | 2.0.0.Final
57 | 5.0.1
58 |
59 |
60 | 1.7.5
61 | 2.0.20
62 |
63 |
64 | 2.0
65 | 3.0.1.Final
66 |
67 |
68 |
69 |
70 | impl
71 |
72 |
73 |
74 |
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-release-plugin
79 |
80 | false
81 | true
82 | true
83 | clean install
84 |
85 |
86 |
87 |
88 | org.apache.rat
89 | apache-rat-plugin
90 | 0.12
91 |
92 |
93 | rat-check
94 | check
95 |
96 |
97 |
98 |
99 | .travis.yml.*
100 | *.log
101 |
102 |
103 |
104 |
105 | org.apache.maven.plugins
106 | maven-enforcer-plugin
107 | 1.4.1
108 |
109 |
110 | enforce-versions
111 |
112 | enforce
113 |
114 |
115 |
116 |
117 | 3.1.0
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | org.apache.maven.plugins
126 | maven-shade-plugin
127 | 3.2.4
128 |
129 |
130 | package
131 |
132 | shade
133 |
134 |
135 | true
136 | jakarta
137 | false
138 |
139 |
140 |
141 |
142 |
143 | ${project.groupId}:${project.artifactId}
144 |
145 |
146 |
147 |
148 | javax.annotation
149 | jakarta.annotation
150 |
151 | javax.annotation.processing.**
152 |
153 |
154 |
155 | javax.enterprise
156 | jakarta.enterprise
157 |
158 | javax.enterprise.deploy.**
159 |
160 |
161 |
162 | javax.inject
163 | jakarta.inject
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------