Skip to content

Commit 8cc4258

Browse files
authored
Channel properties must override connector config (helidon-io#1616)
Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
1 parent bc8fb2b commit 8cc4258

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

microprofile/messaging/src/main/java/io/helidon/microprofile/messaging/ConfigurableConnector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ default org.eclipse.microprofile.config.Config getConnectorConfig(String channel
5353
.get(connectorName.get());
5454

5555
return AdHocConfigBuilder
56-
.from(channelConfig)
57-
//It seams useless but its required by the spec
56+
.from(connectorConfig)
5857
.put(ConnectorFactory.CHANNEL_NAME_ATTRIBUTE, channelName)
59-
.putAll(connectorConfig)
58+
.putAll(channelConfig)
6059
.build();
6160
}
6261
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2020 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.helidon.microprofile.messaging;
19+
20+
import java.util.Map;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import io.helidon.config.Config;
25+
import io.helidon.config.ConfigSources;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
29+
public class ConnectorConfigTest {
30+
private static final String TEST_CHANNEL_VALUE = "test-channel-value";
31+
private static final String TEST_CONNECTOR_VALUE = "test-connector-value";
32+
private static final String TEST_KEY = "test-key";
33+
private static final String TEST_CHANNEL_NAME = "test-channel";
34+
private static final String TEST_CONNECTOR_NAME = "test-connector";
35+
36+
Map<String, String> propMap = Map.of(
37+
"mp.messaging.outgoing." + TEST_CHANNEL_NAME + ".connector", TEST_CONNECTOR_NAME,
38+
"mp.messaging.outgoing." + TEST_CHANNEL_NAME + "." + TEST_KEY, TEST_CHANNEL_VALUE,
39+
"mp.messaging.connector." + TEST_CONNECTOR_NAME + "." + TEST_KEY, TEST_CONNECTOR_VALUE
40+
);
41+
42+
@Test
43+
void testChannelPropsPrecedent() {
44+
Config rootConfig = Config.builder()
45+
.sources(ConfigSources.create(propMap))
46+
.build();
47+
48+
ConfigurableConnector connector = new ConfigurableConnector() {
49+
@Override
50+
public String getConnectorName() {
51+
return TEST_CONNECTOR_NAME;
52+
}
53+
54+
@Override
55+
public Config getRootConfig() {
56+
return rootConfig;
57+
}
58+
59+
@Override
60+
public Config getChannelsConfig() {
61+
return rootConfig.get("mp.messaging.outgoing");
62+
}
63+
};
64+
65+
org.eclipse.microprofile.config.Config connectorConfig = connector.getConnectorConfig(TEST_CHANNEL_NAME);
66+
assertEquals(TEST_CHANNEL_VALUE, connectorConfig.getValue(TEST_KEY, String.class));
67+
}
68+
}

0 commit comments

Comments
 (0)