|
| 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